请启用 Javascript 以查看内容

kubernetes 常见故障以及解决方法

 ·   ·  ☕ 4 分钟  ·  ✍ CNSRE · 👀... 阅读

作者:SRE运维博客
博客地址:https://www.cnsre.cn
文章地址:https://www.cnsre.cn/posts/210819955387/
相关话题:https://www.cnsre.cn/tags/kubernetes/


查看节点状态失败

1
Error from server (NotFound): the server could not find the requested resource (get services http:heapster:)
  • 原因分析:没有heapster服务。
  • 解决方法:安装promethus监控组件即可。
    cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控
    cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控

K8S 集群服务访问失败

案例 1

cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控
cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
curl: (60) Peer's Certificate issuer is not recognized.

More details here: http://curl.haxx.se/docs/sslcerts.html

curl performs SSL certificate verification by default, using a "bundle"
of Certificate Authority (CA) public keys (CA certs). If the default
bundle file isn't adequate, you can specify an alternate file
using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
the bundle, the certificate verification probably failed due to a
problem with the certificate (it might be expired, or the name might
not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
the -k (or --insecure) option.
  • 原因分析:证书不能被识别,其原因为:自定义证书,过期等。
  • 解决方法:更新证书即可。

案例 2

1
curl: (7) Failed connect to 10.103.22.158:3000; Connection refused
  • 原因分析:端口映射错误,服务正常工作,但不能提供服务。
  • 解决方法:删除svc,重新映射端口即可。
1
kubectl delete svc nginx-deployment

K8S 集群服务暴露失败

1
Error from server (AlreadyExists): services "nginx-deployment" already exists
  • 原因分析:该容器已暴露服务了。
  • 解决方法:删除svc,重新映射端口即可。

外网无法访问 K8S 集群提供的服务

原因分析:K8S集群的type为ClusterIP,未将服务暴露至外网。
解决方法:修改K8S集群的type为NodePort即可,于是可通过所有K8S集群节点访问服务。

pod 创建失败

案例 1

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
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
  • 原因分析:镜像问题导致容器无法启动。
    cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控
  • 解决方法:更换镜像。
    cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控

案例 2

cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控

  • 原因分析:yml文件内容出错—-使用中文字符;
  • 解决方法:修改myregistrykey内容即可。
    cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控

pod 的 ready 状态未进入

1
readiness-httpget-pod   0/1     Running   0          116s
  • 原因分析:POD的执行命令失败,无法获取资源。
    cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控
  • 解决方法:进入容器内部,创建yaml定义的资源
    cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控
    cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控

pod 状态为 ErrImagePull

1
rnginx-deployment  0/1     ErrImagePull   0          10s
  • 原因分析:image无法拉取
  • 解决方法:更换镜像即可。

pod 一直处于 pending 状态

cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控

  • 原因分析:由于已使用同样镜像发布了pod,导致无节点可调度。
    cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控
  • 解决方法:删除所有pod后部署pod即可。
    cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控

探测存活 pod 状态为 CrashLoopBackOff

  • 原因分析:镜像问题,导致容器重启失败。

  • 解决方法:更换镜像即可。
    cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控
    cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控

创建服务 status 为 ErrImagePull

cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控
排查思路:

1
kubectl describe pod test-nginx

cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控

  • 原因分析:拉取镜像名称问题。
  • 解决方法:删除错误pod;重新拉取镜像;
1
kubectl delete pod test-nginx;kubectl run test-nginx --image=10.0.0.81:5000/nginx:alpine

创建 init C容器后,其状态不正常

1
2
NAME READY STATUS RESTARTS AGE
myapp-pod 0/1 Init:0/2 0 20s
  • 原因分析:查看日志发现,pod一直出于初始化中;然后查看pod详细信息,定位pod创建失败的原因为:初始化容器未执行完毕。
1
Error from server (BadRequest): container "myapp-container" in pod "myapp-pod" is waiting to start: PodInitializing

cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控
cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控
cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
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容器执行过程中的域名解析了。
1
kubectl apply -f myservice.yaml

cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控
cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控
cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控

1
2
3
4
5
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

cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控

创建 PV 失败

cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控

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

  • 解决方法:修改pv的name字段即可。
    cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控

pod 无法挂载 PVC

cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控
cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控

  • 原因分析:pod无法挂载PVC。accessModes与可使用的PV不一致,导致无法挂载PVC,由于只能挂载大于1G且accessModes为RWO的PV,故只能成功创建1个pod,第2个pod一致pending,按序创建时则第3个pod一直未被创建;
    cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控
    cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控
  • 解决方法:修改yml文件中accessModes或PV的accessModes即可。

pod 使用 PV 后,无法访问其内容

cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控

  • 原因分析:nfs卷中没有文件或权限不对。
    cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控
    cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控
  • 解决方法:在nfs卷中创建文件并授予权限。
    cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控
    cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控

kube-flannel-ds-amd64-ndsf7 插件 pod 的 status 为 Init:0/1

cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控
排查思路:kubectl -n kube-system describe pod kube-flannel-ds-amd64-ndsf7 #查询pod描述信息;
cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控

  • 原因分析:k8s-slave1节点拉取镜像失败。
  • 解决方法:登录k8s-slave1,重启docker服务,手动拉取镜像。
    cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控
    k8s-master节点,重新安装插件即可。
1
kubectl create -f kube-flannel.yml;kubectl get nodes

cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控

不能进入指定容器内部

cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控

  • 原因分析:yml文件comtainers字段重复,导致该pod没有该容器。
  • 解决方法:去掉yml文件中多余的containers字段,重新生成pod。
    cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控
    cnsre运维博客|Linux系统运维|自动化运维|云计算|运维监控

作者:SRE运维博客
博客地址:https://www.cnsre.cn
文章地址:https://www.cnsre.cn/posts/210819955387/
相关话题:https://www.cnsre.cn/tags/kubernetes/


您的鼓励是我最大的动力
alipay QR Code
wechat QR Code

Avatar
作者
CNSRE
一位只会重启的运维






目录