Kubernetes新建RC成功时但Pods没有自动生成的解决方法

创建好yaml文件以后,为了将它发布到kubernetes集群中,在Master节点执行以下命令时,显示我们想要创建的RC已经创建成功

#kubectl create -f filename.yam
replicationcontroller "rcname" created 

但是当查看Pods时,却显示不存在

#kubectl get pods
No resources found. 

解决办法是编辑/etc/kubernetes/apiserver 去除 KUBE_ADMISSION_CONTROL 中的 SecurityContextDeny,ServiceAccount ,并重启kube-apiserver.service服务

#vim /etc/kubernetes/apiserver 
KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,ResourceQuota"
#systemctl restart kube-apiserver.service

删除RC,重新执行前面的步骤就可以看到Pods的生成了

#kubectl delete -f filename.yam
replicationcontroller "rcname" deleted
#kubectl create -f filename.yam
replicationcontroller "rcname" created
#kubectl get pods
NAME          READY     STATUS              RESTARTS   AGE
mysql-sgvzt   0/1       ContainerCreating   0          3s

若是Pod一直卡在ContainerCreating状态,可以用以下命令查看具体原因

#kubectl describe pod mysql-sgvzt
Name:       mysql-sgvzt
Namespace:  default
Node:       127.0.0.1/127.0.0.1
Start Time: Thu, 26 Apr 2018 13:45:25 +0800
Labels:     app=mysql
Status:     Pending
IP:     
Controllers:    ReplicationController/mysql
Containers:
  mysql:
    Container ID:   
    Image:      docker.io/mysql
    Image ID:       
    Port:       3306/TCP
    State:      Waiting
      Reason:       ContainerCreating
    Ready:      False
    Restart Count:  0
    Volume Mounts:  
    Environment Variables:
      MYSQL_ROOT_PASSWORD:  123456
Conditions:
  Type      Status
  Initialized   True 
  Ready     False 
  PodScheduled  True 
No volumes.
QoS Class:  BestEffort
Tolerations:    
Events:
  FirstSeen LastSeen    Count   From            SubObjectPath   Type        Reason      Message
  --------- --------    -----   ----            -------------   --------    ------      -------
  30m       30m     1   {default-scheduler }            Normal      Scheduled   Successfully assigned mysql-sgvzt to 127.0.0.1
  30m       4m      10  {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)"
 
  29m   1s  132 {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\""

根据结果,可以明显看到失败原因,缺少了/etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt

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

而这个缺失的文件是由python-rhsm-certificates提供的,所以我们只需要用yum安装他就行了

 yum install -y *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

这两个命令会生成/etc/rhsm/ca/redhat-uep.pem文件.

顺得的话会得到下面的结果。

[root@localhost]# docker pull registry.access.redhat.com/rhel7/pod-infrastructure:latest

Trying to pull repository registry.access.redhat.com/rhel7/pod-infrastructure ...

latest: Pulling from registry.access.redhat.com/rhel7/pod-infrastructure

26e5ed6899db: Pull complete

66dbe984a319: Pull complete

9138e7863e08: Pull complete

Digest: sha256:92d43c37297da3ab187fc2b9e9ebfb243c1110d446c783ae1b989088495db931

Status: Downloaded newer image for registry.access.redhat.com/rhel7/pod-infrastructure:latest

删除原来创建的rc

[root@localhost /]# kubectl delete -f mysql-rc.yaml

重新创建

[root@localhost /]# kubectl create -f mysql-rc.yaml

replicationcontroller "mysql" created

再次查看状态

[root@localhost /]# kubectl get pod

NAME READY STATUS RESTARTS AGE

mysql-b8m2q 1/1 Running 0 27m

作者:JensenWong
链接:https://www.jianshu.com/p/e601d79357c6
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

你可能感兴趣的:(docker开发之旅)