1. 程式人生 > >解決k8s出現pod服務一直處於ContainerCreating狀態的問題

解決k8s出現pod服務一直處於ContainerCreating狀態的問題

在建立Dashborad時,檢視狀態總是ContainerCreating

kubectl get pods -n kube-system 
NAME                                           READY     STATUS              RESTARTS   AGE
kubernetes-dashboard-latest-4167338039-cjh13   0/1       ContainerCreating   0          47s

檢視日誌/var/log/message,發現有如下日誌資訊:

May 31 17:29:19 apm-slave03 kubelet: E0531 17:29:19.526941   24919 docker_manager.go:2159] Failed to create pod infra container: ImagePullBackOff; Skipping pod "kubernetes-dashboard-latest-4167338039-cjh13_kube-system(0ba4a71f-64ae-11e8-9a31-005056bc2ad1)": Back-off pulling image "registry.access.redhat.com/rhel7/pod-infrastructure:latest"

發現此時會pull一個映象registry.access.redhat.com/rhel7/pod-infrastructure:latest,當我手動pull時,提示如下錯誤:

docker pull registry.access.redhat.com/rhel7/pod-infrastructure:latest
Trying to pull repository registry.access.redhat.com/rhel7/pod-infrastructure ... 
open /etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt: no such file or directory

通過搜尋得知,需要安裝rhsm,於是安裝之:

yum install *rhsm*
已載入外掛:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror.lzu.edu.cn
 * extras: mirror.lzu.edu.cn
 * updates: ftp.sjtu.edu.cn
base                                                                                                                                                                                  | 3.6 kB  00:00:00     
extras                                                                                                                                                                                | 3.4 kB  00:00:00     
updates                                                                                                                                                                               | 3.4 kB  00:00:00     
軟體包 python-rhsm-1.19.10-1.el7_4.x86_64 被已安裝的 subscription-manager-rhsm-1.20.11-1.el7.centos.x86_64 取代
軟體包 subscription-manager-rhsm-1.20.11-1.el7.centos.x86_64 已安裝並且是最新版本
軟體包 python-rhsm-certificates-1.19.10-1.el7_4.x86_64 被已安裝的 subscription-manager-rhsm-certificates-1.20.11-1.el7.centos.x86_64 取代
軟體包 subscription-manager-rhsm-certificates-1.20.11-1.el7.centos.x86_64 已安裝並且是最新版本

但是在/etc/rhsm/ca/目錄下依舊沒有證書檔案,於是反覆解除安裝與安裝都不靠譜,後來發現大家所謂yum install *rhsm*其實安裝的的是python-rhsm-1.19.10-1.el7_4.x86_64python-rhsm-certificates-1.19.10-1.el7_4.x86_64,但是在實際安裝過程中會有如下提示:

軟體包 python-rhsm-1.19.10-1.el7_4.x86_64 被已安裝的 subscription-manager-rhsm-1.20.11-1.el7.centos.x86_64 取代
軟體包 subscription-manager-rhsm-1.20.11-1.el7.centos.x86_64 已安裝並且是最新版本
軟體包 python-rhsm-certificates-1.19.10-1.el7_4.x86_64 被已安裝的 subscription-manager-rhsm-certificates-1.20.11-1.el7.centos.x86_64 取代
軟體包 subscription-manager-rhsm-certificates-1.20.11-1.el7.centos.x86_64 已安裝並且是最新版本

罪魁禍首在這裡。原來我們想要安裝的rpm包被取代了。而取代後的rpm包在安裝完成後之建立了目錄,並沒有證書檔案redhat-uep.pem。於是乎,手動下載以上兩個包

wget ftp://ftp.icm.edu.pl/vol/rzm6/linux-scientificlinux/7.4/x86_64/os/Packages/python-rhsm-certificates-1.19.9-1.el7.x86_64.rpm
wget ftp://ftp.icm.edu.pl/vol/rzm6/linux-scientificlinux/7.4/x86_64/os/Packages/python-rhsm-1.19.9-1.el7.x86_64.rpm

注意版本要匹配,解除安裝安裝錯的包

yum remove *rhsm*

然後執行安裝命令

rpm -ivh *.rpm
rpm -ivh *.rpm
警告:python-rhsm-1.19.9-1.el7.x86_64.rpm: 頭V4 DSA/SHA1 Signature, 金鑰 ID 192a7d7d: NOKEY
準備中...                          ################################# [100%]
正在升級/安裝...
   1:python-rhsm-certificates-1.19.9-1################################# [ 50%]
   2:python-rhsm-1.19.9-1.el7         ################################# [100%]

接著驗證手動pull映象

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

此時才算是解決這個問題。
當然同樣的問題同樣的解法為啥有人可以有人不可以呢,我目測是因為系統發行版的緣故吧。我是用的是CentOS Linux release 7.5.1804 (Core) 他們的版本稍微低一點吧。