K8S 常見故障及解決方法

問題 1:K8S 集羣服務訪問失敗?

原因分析:證書不能被識別,其原因爲:自定義證書,過期等。

解決方法:更新證書即可。

問題 2:K8S 集羣服務訪問失敗?

curl: (7) Failed connect to 10.103.22.158:3000; Connection refused

原因分析:端口映射錯誤,服務正常工作,但不能提供服務。

解決方法:刪除 svc,重新映射端口即可。

kubectl delete svc nginx-deployment

問題 3:K8S 集羣服務暴露失敗?

Error from server (AlreadyExists): services "nginx-deployment" already exists

原因分析:該容器已暴露服務了。

解決方法:刪除 svc,重新映射端口即可。

問題 4:外網無法訪問 K8S 集羣提供的服務?

原因分析:K8S 集羣的 type 爲 ClusterIP,未將服務暴露至外網。

解決方法:修改 K8S 集羣的 type 爲 NodePort 即可,於是可通過所有 K8S 集羣節點訪問服務。

kubectl edit svc nginx-deployment

問題 5:pod 狀態爲 ErrImagePull?

readiness-httpget-pod   0/1     ErrImagePull   0          10s

原因分析:image 無法拉取;

解決方法:更換鏡像即可。

問題 6:創建 init C 容器後,其狀態不正常?

NAME READY STATUS RESTARTS AGE
myapp-pod 0/1 Init:0/2 0 20s

原因分析:查看日誌發現,pod 一直出於初始化中;然後查看 pod 詳細信息,定位 pod 創建失敗的原因爲:初始化容器未執行完畢。

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

解決方法:創建相關 service,將 SVC 的 name 寫入 K8S 集羣的 coreDNS 服務器中,於是 coreDNS 就能對 POD 的 initC 容器執行過程中的域名解析了。

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 狀態爲 CrashLoopBackOff?

原因分析:鏡像問題,導致容器重啓失敗。

解決方法:更換鏡像即可。

問題 8:POD 創建失敗?

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

原因分析:鏡像問題導致容器無法啓動。

解決方法:更換鏡像。

問題 9:POD 的 ready 狀態未進入?

readiness-httpget-pod   0/1     Running   0          116s

原因分析:POD 的執行命令失敗,無法獲取資源。

解決方法:進入容器內部,創建 yaml 定義的資源

問題 10:pod 創建失敗?

原因分析:yml 文件內容出錯—- 使用中文字符;

解決方法:修改 myregistrykey 內容即可。

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 節點拉取鏡像失敗。

解決方法:登錄 k8s-slave1,重啓 docker 服務,手動拉取鏡像。

k8s-master 節點,重新安裝插件即可。

kubectl create -f kube-flannel.yml;kubectl get nodes

12、K8S 創建服務 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、不能進入指定容器內部?

原因分析:yml 文件 comtainers 字段重複,導致該 pod 沒有該容器。

解決方法:去掉 yml 文件中多餘的 containers 字段,重新生成 pod。

14、創建 PV 失敗?

原因分析:pv 的 name 字段重複。

解決方法:修改 pv 的 name 字段即可。

15、pod 無法掛載 PVC?

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

accessModes 與可使用的 PV 不一致,導致無法掛載 PVC,由於只能掛載大於 1G 且 accessModes 爲 RWO 的 PV,故只能成功創建 1 個 pod,第 2 個 pod 一致 pending,按序創建時則第 3 個 pod 一直未被創建;

解決方法:修改 yml 文件中 accessModes 或 PV 的 accessModes 即可。

16、問題:pod 使用 PV 後,無法訪問其內容?

原因分析:nfs 卷中沒有文件或權限不對。

解決方法:在 nfs 卷中創建文件並授予權限。

17、查看節點狀態失敗?

Error from server (NotFound): the server could not find the requested resource (get services http:heapster:)

原因分析:沒有 heapster 服務。

解決方法:安裝 promethus 監控組件即可。

18、pod 一直處於 pending’狀態?

原因分析:由於已使用同樣鏡像發佈了 pod,導致無節點可調度。

解決方法:刪除所有 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


本文由 Readfog 進行 AMP 轉碼,版權歸原作者所有。
來源https://mp.weixin.qq.com/s/Vgjy0q9g1W77-B1LXRqKyg