19 個 K8S 日常故障處理集錦!
問題1:K8S集群服務(wù)訪問失敗?


原因分析:證書不能被識別,其原因?yàn)椋鹤远x證書,過期等。
解決方法:更新證書即可。
問題2:K8S集群服務(wù)訪問失敗?
curl: (7) Failed connect to 10.103.22.158:3000; Connection refused
原因分析:端口映射錯誤,服務(wù)正常工作,但不能提供服務(wù)。
解決方法:刪除svc,重新映射端口即可。
kubectl delete svc nginx-deployment
問題3:K8S集群服務(wù)暴露失???
Error from server (AlreadyExists): services "nginx-deployment" already exists
原因分析:該容器已暴露服務(wù)了。
解決方法:刪除svc,重新映射端口即可。
問題4:外網(wǎng)無法訪問K8S集群提供的服務(wù)?
原因分析:K8S集群的type為ClusterIP,未將服務(wù)暴露至外網(wǎng)。
解決方法:修改K8S集群的type為NodePort即可,于是可通過所有K8S集群節(jié)點(diǎn)訪問服務(wù)。
kubectl edit svc nginx-deployment
問題5:pod狀態(tài)為ErrImagePull?
readiness-httpget-pod 0/1 ErrImagePull 0 10s

原因分析:image無法拉??;


解決方法:更換鏡像即可。
問題6:創(chuàng)建init C容器后,其狀態(tài)不正常?
NAME READY STATUS RESTARTS AGE
myapp-pod 0/1 Init:0/2 0 20s
原因分析:查看日志發(fā)現(xiàn),pod一直出于初始化中;然后查看pod詳細(xì)信息,定位pod創(chuàng)建失敗的原因?yàn)椋撼跏蓟萜魑磮?zhí)行完畢。
Error from server (BadRequest): container "myapp-container" in pod "myapp-pod" is waiting to start: PodInitializing



waiting for myservice
Server: 10.96.0.10
Address: 10.96.0.10:53
** server can't find myservice.default.svc.cluster.local: NXDOMAIN
*** Can't find myservice.svc.cluster.local: No answer
*** Can't find myservice.cluster.local: No answer
*** Can't find myservice.default.svc.cluster.local: No answer
*** Can't find myservice.svc.cluster.local: No answer
*** Can't find myservice.cluster.local: No answer
解決方法:創(chuàng)建相關(guān)service,將SVC的name寫入K8S集群的coreDNS服務(wù)器中,于是coreDNS就能對POD的initC容器執(zhí)行過程中的域名解析了。
kubectl apply -f myservice.yaml



NAME READY STATUS RESTARTS AGE
myapp-pod 0/1 Init:1/2 0 27m
myapp-pod 0/1 PodInitializing 0 28m
myapp-pod 1/1 Running 0 28m

問題7:探測存活pod狀態(tài)為CrashLoopBackOff?
原因分析:鏡像問題,導(dǎo)致容器重啟失敗。
解決方法:更換鏡像即可。


問題8:POD創(chuàng)建失?。?/span>
readiness-httpget-pod 0/1 Pending 0 0s
readiness-httpget-pod 0/1 Pending 0 0s
readiness-httpget-pod 0/1 ContainerCreating 0 0s
readiness-httpget-pod 0/1 Error 0 2s
readiness-httpget-pod 0/1 Error 1 3s
readiness-httpget-pod 0/1 CrashLoopBackOff 1 4s
readiness-httpget-pod 0/1 Error 2 15s
readiness-httpget-pod 0/1 CrashLoopBackOff 2 26s
readiness-httpget-pod 0/1 Error 3 37s
readiness-httpget-pod 0/1 CrashLoopBackOff 3 52s
readiness-httpget-pod 0/1 Error 4 82s
原因分析:鏡像問題導(dǎo)致容器無法啟動。

解決方法:更換鏡像。


問題9:POD的ready狀態(tài)未進(jìn)入?
readiness-httpget-pod 0/1 Running 0 116s
原因分析:POD的執(zhí)行命令失敗,無法獲取資源。

解決方法:進(jìn)入容器內(nèi)部,創(chuàng)建yaml定義的資源


問題10:pod創(chuàng)建失敗?

原因分析:yml文件內(nèi)容出錯—-使用中文字符;
解決方法:修改myregistrykey內(nèi)容即可。

11、kube-flannel-ds-amd64-ndsf7插件pod的status為Init:0/1?

排查思路:kubectl -n kube-system describe pod kube-flannel-ds-amd64-ndsf7 #查詢pod描述信息;

原因分析:k8s-slave1節(jié)點(diǎn)拉取鏡像失敗。
解決方法:登錄k8s-slave1,重啟docker服務(wù),手動拉取鏡像。

k8s-master節(jié)點(diǎn),重新安裝插件即可。
kubectl create -f kube-flannel.yml;kubectl get nodes

12、K8S創(chuàng)建服務(wù)status為ErrImagePull?

排查思路:
kubectl describe pod test-nginx
原因分析:拉取鏡像名稱問題。
解決方法:刪除錯誤pod;重新拉取鏡像;
kubectl delete pod test-nginx;kubectl run test-nginx --image=10.0.0.81:5000/nginx:alpine
13、不能進(jìn)入指定容器內(nèi)部?

原因分析:yml文件comtainers字段重復(fù),導(dǎo)致該pod沒有該容器。
解決方法:去掉yml文件中多余的containers字段,重新生成pod。


14、創(chuàng)建PV失?。?/span>

原因分析:pv的name字段重復(fù)。
解決方法:修改pv的name字段即可。

15、pod無法掛載PVC?


原因分析:pod無法掛載PVC。


accessModes與可使用的PV不一致,導(dǎo)致無法掛載PVC,由于只能掛載大于1G且accessModes為RWO的PV,故只能成功創(chuàng)建1個pod,第2個pod一致pending,按序創(chuàng)建時則第3個pod一直未被創(chuàng)建;
解決方法:修改yml文件中accessModes或PV的accessModes即可。

16、問題:pod使用PV后,無法訪問其內(nèi)容?

原因分析:nfs卷中沒有文件或權(quán)限不對。


解決方法:在nfs卷中創(chuàng)建文件并授予權(quán)限。


17、查看節(jié)點(diǎn)狀態(tài)失?。?/span>
Error from server (NotFound): the server could not find the requested resource (get services http:heapster:)
原因分析:沒有heapster服務(wù)。
解決方法:安裝promethus監(jiān)控組件即可。


18、pod一直處于pending’狀態(tài)?

原因分析:由于已使用同樣鏡像發(fā)布了pod,導(dǎo)致無節(jié)點(diǎn)可調(diào)度。

解決方法:刪除所有pod后部署pod即可。

19、helm安裝組件失敗?
[root@k8s-master01 hello-world]# helm install
Error: This command needs 1 argument: chart nam
[root@k8s-master01 hello-world]# helm install ./
Error: no Chart.yaml exists in directory "/root/hello-world"
原因分析:文件名格式不對。
解決方法:mv chart.yaml Chart.yaml

來源:https://www.cnblogs.com/chalon/p/14415252.html
