[kubernetes]Error from server (BadRequest):container install-cni is not valid for pod kube-dns

王一洋發表於2018-11-23

安裝完 Flannel 網路元件之後,發現 pod kube-flannel 的狀態為 CrashLoopBackOff,執行命令檢視日誌,提示如下資訊:

Error from server (BadRequest): container install-cni is not valid for pod kube-dns-6f4fd4bdf-qdhqb

出現這個是因為 pod kube-flannel 啟動了兩個容器 kube-flannel 和 install-cni,檢視日誌時需要指定檢視那個容器,可通過命令 -c <container_name> 指定,例如: kubectl logs -f pods/kube-flannel-ds-vkdzw -c install-cni -n kube-system。通過命令可以看到報錯資訊如下:
 

+ cp -f /etc/kube-flannel/cni-conf.json /etc/cni/net.d/10-flannel.conf
cp: can't create '/etc/cni/net.d/10-flannel.conf': Permission denied

這個是因為容器跟主機檔案系統有互動操作,需要關閉 SELinux,執行如下命令即可:

[apps@mvxl1484 ~]$ sudo su -
[root@mvxl1484 ~]# setenforce 0
setenforce: SELinux is disabled
[root@mvxl1484 ~]# systemctl daemon-reload

檢視pod執行情況:

[apps@mvxl1484 ~]$ kubectl get pod --all-namespaces
NAMESPACE     NAME                               READY     STATUS             RESTARTS   AGE
kube-system   etcd-mvxl1484                      1/1       Running            0          50m
kube-system   kube-apiserver-mvxl1484            1/1       Running            0          50m
kube-system   kube-controller-manager-mvxl1484   1/1       Running            0          50m
kube-system   kube-dns-6f4fd4bdf-qdhqb           2/3       CrashLoopBackOff   21         50m
kube-system   kube-flannel-ds-7248h              1/1       Running            0          38m
kube-system   kube-flannel-ds-bzdg4              1/1       Running            0          38m

刪除有問題的pod,會自動重新安裝

[apps@mvxl1484 ~]$ kubectl delete pod kube-dns-6f4fd4bdf-qdhqb -n kube-system
pod "kube-dns-6f4fd4bdf-qdhqb" deleted

再看,已經正常

NAMESPACE     NAME                               READY     STATUS    RESTARTS   AGE
kube-system   etcd-mvxl1484                      1/1       Running   0          51m
kube-system   kube-apiserver-mvxl1484            1/1       Running   0          51m
kube-system   kube-controller-manager-mvxl1484   1/1       Running   0          51m
kube-system   kube-dns-6f4fd4bdf-4jj56           2/3       Running   0          55s
kube-system   kube-flannel-ds-7248h              1/1       Running   0          39m
kube-system   kube-flannel-ds-bzdg4              1/1       Running   0          39m

 

相關文章