# systemctl disable firewalld # systemctl stop firewalld
2. 安装etcd以及kubernetes软件
yum install -y etcd kubernetes
3.
vim /etc/sysconfig/docker OPTIONS='--selinux-enabled=false --insecure-registry grc.io --log-driver=journald --signature-verification=false'
4.
systemctl start etcd systemctl start docker systemctl start kube-apiserver systemctl start kube-controller-manager systemctl start kube-scheduler systemctl start kubelet systemctl start kubelet systemctl start kube-proxy
5. 检查是否启动成功
apiVersion: v1 #副本控制器 kind: ReplicationController metadata: name: mysql spec: # 实例的数量 replicas: 1 selector: # Pod名称 app: mysql template: metadata: # Pod副本名称对应selector labels: app: mysql spec: containers: # Pod内容定义部分 - name: mysql # 容器的名称 image: mysql # 容器的镜像 ports: - containerPort: 3306 ## 暴露端口 env: ##注入到容器内的环境变量 - name: MYSQL_ROOT_PASSWORD value: "123456"
2. 启动
kubectl create -f mysql-rc.yaml
3.
# kubectl get rc NAME DESIRED CURRENT READY AGE mysql 1 1 1 14m
Pod状态
# kubectl get pods NAME READY STATUS RESTARTS AGE mysql-w3t8z 1/1 Running 0 14m
4.
-
启动后发现 Pod状态一直都是ContainerCreating
-
使用kubectl describe po mysql查看状态
-
如果出现如下错误
kubectl describe po mysql-bwnlk Name: mysql-bwnlk Namespace: default Node: 127.0.0.1/127.0.0.1 Start Time: Thu, 04 Jan 2018 10:20:45 +0800 Labels: app=mysql Status: Pending IP: Controllers: ReplicationController/mysql Containers: mysql: Container ID: Image: daocloud.io/library/mysql Image ID: Port: 3306/TCP State: Waiting Reason: ContainerCreating Ready: False Restart Count: 0 Volume Mounts: <none> Environment Variables: MYSQL_ROOT_PASSWORD: 123456 Conditions: Type Status Initialized True Ready False PodScheduled True No volumes. QoS Class: BestEffort Tolerations: <none> Events: FirstSeen LastSeen Count From SubObjectPath Type Reason Message --------- -------- ----- ---- ------------- -------- ------ ------- 3m 3m 1 {default-scheduler } Normal Scheduled Successfully assigned mysql-bwnlk to 127.0.0.1 3m 20s 5 {kubelet 127.0.0.1} Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "POD" with ErrImagePull: "image pull failed for registry.access.redhat.com/rhel7/pod-infrastructure:latest, this may be because there are no credentials on this request. details: (open /etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt: no such file or directory)" 2m 8s 10 {kubelet 127.0.0.1} Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "POD" with ImagePullBackOff: "Back-off pulling image "registry.access.redhat.com/rhel7/pod-infrastructure:latest""
解决:
yum install *rhsm*
#wget http://mirror.centos.org/centos/7/os/x86_64/Packages/python-rhsm-certificates-1.19.10-1.el7_4.x86_64.rpm #rpm2cpio python-rhsm-certificates-1.19.10-1.el7_4.x86_64.rpm | cpio -iv --to-stdout ./etc/rhsm/ca/redhat-uep.pem | tee /etc/rhsm/ca/redhat-uep.pem
kubectl delete -f mysql-rc.yaml kubectl create -f mysql-rc.yaml
-
安装阿里镜像加速即可解决https://cr.console.aliyun.com/cn-hangzhou/mirrors