2021-08-23

<nav id="nav_main" class="navbar-main" style="display: flex; font-size: 14px; color: rgb(102, 102, 102); flex-flow: row nowrap; align-items: center; justify-content: space-between; width: 1823px;">

  • [登录](javascript:void(0);)

</nav>

chalon

K8S使用---故障处理

问题1:K8S集群服务访问失败?

image
image

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:K8S集群服务访问失败?

image

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

原因分析:端口映射错误,服务正常工作,但不能提供服务。

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

kubectl delete svc nginx-deployment

image
image

问题3:K8S集群服务暴露失败?

image

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

原因分析:该容器已暴露服务了。

image
image

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

问题4:外网无法访问K8S集群提供的服务?

image

原因分析:K8S集群的type为ClusterIP,未将服务暴露至外网。

解决方法:修改K8S集群的type为NodePort即可,于是可通过所有K8S集群节点访问服务。

kubectl edit svc nginx-deployment

image

问题5:pod状态为ErrImagePull?

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

image

原因分析:image无法拉取;

image
image

Warning Failed 59m (x4 over 61m) kubelet, k8s-node01 Error: ErrImagePull

解决方法:更换镜像即可。

问题6:创建init C容器后,其状态不正常?

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

原因分析:查看日志发现,pod一直出于初始化中;然后查看pod详细信息,定位pod创建失败的原因为:初始化容器未执行完毕。

image

Error from server (BadRequest): container "myapp-container" in pod "myapp-pod" is waiting to start: PodInitializing

image
image
image

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

image
image
image

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

image

问题7:探测存活pod状态为CrashLoopBackOff?

readiness-httpget-pod 0/1 CrashLoopBackOff 1 13s
readiness-httpget-pod 0/1 Completed 2 20s
readiness-httpget-pod 0/1 CrashLoopBackOff 2 31s
readiness-httpget-pod 0/1 Completed 3 42s
readiness-httpget-pod 0/1 CrashLoopBackOff 3 53s

image

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

Events:
Type Reason Age From Message


Normal Pulling 56m kubelet, k8s-node01 Pulling image "hub.atguigu.com/library/mylandmarktech/myapp:v1"
Normal Pulled 56m kubelet, k8s-node01 Successfully pulled image "hub.atguigu.com/library/mylandmarktech/myapp:v1"
Normal Created 56m (x3 over 56m) kubelet, k8s-node01 Created container readiness-httpget-container
Normal Started 56m (x3 over 56m) kubelet, k8s-node01 Started container readiness-httpget-container
Normal Pulled 56m (x2 over 56m) kubelet, k8s-node01 Container image "hub.atguigu.com/library/mylandmarktech/myapp:v1" already present on machine
Warning Unhealthy 56m kubelet, k8s-node01 Readiness probe failed: Get http://10.244.2.22:80/index1.html: dial tcp 10.244.2.22:80: connect: connection refused
Warning BackOff 56m (x4 over 56m) kubelet, k8s-node01 Back-off restarting failed container
Normal Scheduled 50s default-scheduler Successfully assigned default/readiness-httpget-pod to k8s-node01

image

解决方法:更换镜像即可。

image
image

问题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

原因分析:镜像问题导致容器无法启动。

[root@k8s-master01 ~]# kubectl logs readiness-httpget-pod
url.js:106
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'url', 'string', url);
^

TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string. Received type undefined
at Url.parse (url.js:106:11)
at Object.urlParse [as parse] (url.js:100:13)
at module.exports (/myapp/node_modules/mongodb/lib/url_parser.js:17:23)
at connect (/myapp/node_modules/mongodb/lib/mongo_client.js:159:16)
at Function.MongoClient.connect (/myapp/node_modules/mongodb/lib/mongo_client.js:110:3)
at Object.<anonymous> (/myapp/app.js:12:13)
at Module._compile (module.js:641:30)
at Object.Module._extensions..js (module.js:652:10)
at Module.load (module.js:560:32)
at tryModuleLoad (module.js:503:12)
at Function.Module._load (module.js:495:3)
at Function.Module.runMain (module.js:682:10)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:613:3

image

Events:

Type Reason Age From Message


Normal Pulled 58m (x5 over 59m) kubelet, k8s-node01 Container image "hub.atguigu.com/library/myapp:v1" already present on machine
Normal Created 58m (x5 over 59m) kubelet, k8s-node01 Created container readiness-httpget-container
Normal Started 58m (x5 over 59m) kubelet, k8s-node01 Started container readiness-httpget-container
Warning BackOff 57m (x10 over 59m) kubelet, k8s-node01 Back-off restarting failed container
Normal Scheduled 3m35s default-scheduler Successfully assigned default/readiness-httpget-pod to k8s-node01

解决方法:更换镜像。

image
image

问题9:POD的ready状态未进入?

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

原因分析:POD的执行命令失败,无法获取资源。

Error from server (NotFound): pods "pod" not found

2021/06/11 07:10:14 [error] 30#30: *1 open() "/usr/share/nginx/html/index1.html" failed (2: No such file or directory), client: 10.244.2.1, server: localhost, request: "GET /index1.html HTTP/1.1", host: "10.244.2.25:80"
10.244.2.1 - - [11/Jun/2021:07:10:14 +0000] "GET /index1.html HTTP/1.1" 404 153 "-" "kube-probe/1.15" "-"
10.244.2.1 - - [11/Jun/2021:07:10:17 +0000] "GET /index1.html HTTP/1.1" 404 153 "-" "kube-probe/1.15" "-"

image

Events:

Type Reason Age From Message


Normal Pulled 64m kubelet, k8s-node01 Container image "hub.atguigu.com/library/nginx" already present on machine
Normal Created 64m kubelet, k8s-node01 Created container readiness-httpget-container
Normal Started 64m kubelet, k8s-node01 Started container readiness-httpget-container
Warning Unhealthy 59m (x101 over 64m) kubelet, k8s-node01 Readiness probe failed: HTTP probe failed with statuscode: 404
Normal Scheduled 8m16s default-scheduler Successfully assigned default/readiness-httpget-pod to k8s-node01

解决方法:进入容器内部,创建yaml定义的资源

image

image

问题10:pod创建失败?

error: error validating "myregistry-secret.yml": error validating data: ValidationError(Pod.spec.imagePullSecrets[0]): invalid type for io.k8s.api.core.v1.LocalObjectReference: got "string", expected "map"; if you choose to ignore these errors, turn validation off with --validate=false

image

原因分析:yml文件内容出错---使用中文字符;

解决方法:修改myregistrykey内容即可。

image

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

image

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

image

原因分析:k8s-slave1节点拉取镜像失败。

解决方法:登录k8s-slave1,重启docker服务,手动拉取镜像。

image

k8s-master节点,重新安装插件即可。

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

image

12、K8S创建服务status为ErrImagePull?

image

排查思路:kubectl describe pod test-nginx

image

原因分析:拉取镜像名称问题。

解决方法:删除错误pod;重新拉取镜像;

kubectl delete pod test-nginx;kubectl run test-nginx --image=10.0.0.81:5000/nginx:alpine

image

13、不能进入指定容器内部?

Error from server (BadRequest): container volume-test-container is not valid for pod volume-test-pod

image

原因分析:yml文件comtainers字段重复,导致该pod没有该容器。

image
image
image

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

image
image

14、创建PV失败?

persistentvolume/nfspv1 unchanged
persistentvolume/nfspv01 created
Error from server (Invalid): error when applying patch:
{"metadata":{"annotations":{"kubectl.kubernetes.io/last-applied-configuration":"{"apiVersion":"v1","kind":"PersistentVolume","metadata":{"annotations":{},"name":"nfspv01"},"spec":{"accessModes":["ReadWriteOnce"],"capacity":{"storage":"5Gi"},"nfs":{"path":"/nfs2","server":"192.168.66.100"},"persistentVolumeReclaimPolicy":"Retain","storageClassName":"nfs"}}\n"}},"spec":{"nfs":{"path":"/nfs2"}}}
to:
Resource: "/v1, Resource=persistentvolumes", GroupVersionKind: "/v1, Kind=PersistentVolume"
Name: "nfspv01", Namespace: ""
Object: &{map["apiVersion":"v1" "kind":"PersistentVolume" "metadata":map["annotations":map["kubectl.kubernetes.io/last-applied-configuration":"{"apiVersion":"v1","kind":"PersistentVolume","metadata":{"annotations":{},"name":"nfspv01"},"spec":{"accessModes":["ReadWriteOnce"],"capacity":{"storage":"5Gi"},"nfs":{"path":"/nfs1","server":"192.168.66.100"},"persistentVolumeReclaimPolicy":"Retain","storageClassName":"nfs"}}\n"] "creationTimestamp":"2021-06-25T01:54:24Z" "finalizers":["kubernetes.io/pv-protection"] "name":"nfspv01" "resourceVersion":"325674" "selfLink":"/api/v1/persistentvolumes/nfspv01" "uid":"89cb1d15-8012-47f0-aee6-6507bb624387"] "spec":map["accessModes":["ReadWriteOnce"] "capacity":map["storage":"5Gi"] "nfs":map["path":"/nfs1" "server":"192.168.66.100"] "persistentVolumeReclaimPolicy":"Retain" "storageClassName":"nfs" "volumeMode":"Filesystem"] "status":map["phase":"Available"]]}
for: "PV.yml": PersistentVolume "nfspv01" is invalid: spec.persistentvolumesource: Forbidden: is immutable after creation

image

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

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

image

15、pod无法挂载PVC?

image
image

原因分析:pod无法挂载PVC。

Events:
Type Reason Age From Message


Warning FailedScheduling 60s default-scheduler pod has unbound immediate PersistentVolumeClaims (repeated 2 times)

image
image

accessModes与可使用的PV不一致,导致无法挂载PVC,由于只能挂载大于1G且accessModes为RWO的PV,故只能成功创建1个pod,第2个pod一致pending,按序创建时则第3个pod一直未被创建;

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

image

16、问题:pod使用PV后,无法访问其内容?

image

原因分析:nfs卷中没有文件或权限不对。

image
image

解决方法:在nfs卷中创建文件并授予权限。

image
image

17、查看节点状态失败?

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

image

原因分析:没有heapster服务。

解决方法:安装promethus监控组件即可。

image
image

18、pod一直处于pending'状态?

image

原因分析:由于已使用同样镜像发布了pod,导致无节点可调度。

image

Events:

Type Reason Age From Message


Warning FailedScheduling 9s (x13 over 14m) default-scheduler 0/3 nodes are available: 3 node(s) didn't match node selector.

解决方法:删除所有pod后部署pod即可。

image

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"

image

原因分析:文件名格式不对。

解决方法:mv chart.yaml Chart.yaml

image

20、helm更新release失败?

[root@k8s-master01 hello-world]#

[root@k8s-master01 hello-world]# helm upgrade joyous-wasp ./
UPGRADE FAILED
ROLLING BACK
Error: render error in "hello-world/templates/deployment.yaml": template: hello-world/templates/deployment.yaml:14:35: executing "hello-world/templates/deployment.yaml" at <.values.image.reposi...>: can't evaluate field image in type interface {}
Error: UPGRADE FAILED: render error in "hello-world/templates/deployment.yaml": template: hello-world/templates/deployment.yaml:14:35: executing "hello-world/templates/deployment.yaml" at <.values.image.reposi...>: can't evaluate field image in type interface {}

原因分析:yaml文件语法错误。

image

解决方法:修改yaml文件即可。

image

21、etcd启动失败?

[root@k8s-master01 ~]# systemctl enable --now etcd
Created symlink from /etc/systemd/system/etcd3.service to /usr/lib/systemd/system/etcd.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/etcd.service to /usr/lib/systemd/system/etcd.service.
Job for etcd.service failed because a timeout was exceeded. See "systemctl status etcd.service" and "journalctl -xe" for details.

原因分析:认证失败原因可能为证书、配置、端口等。检查配置符合etcd版本要求,证书生成过程有效。最后确认端口被占用导致认证失败。

|

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

|

[root@k8s-master01 ~]``# systemctl status etcd

● etcd.service - Etcd.service

Loaded: loaded (``/usr/lib/systemd/system/etcd``.service; enabled; vendor preset: disabled)

Active: activating (start) since Wed 2021-07-14 09:53:03 CST; 1min 6s ago

Docs: https:``//coreos``.com``/etcd/docs/latest/

Main PID: 39692 (etcd)

CGroup: ``/system``.slice``/etcd``.service

└─39692 ``/usr/local/bin/etcd --config-``file``=``/etc/etcd/etcd``.config.yml

Jul 14 09:54:09 k8s-master01 etcd[39692]: rejected connection from ``"192.168.0.108:46168" (error ``"remote error: tls: bad certificate"``, ServerName ``""``)

Jul 14 09:54:09 k8s-master01 etcd[39692]: rejected connection from ``"192.168.0.108:46166" (error ``"remote error: tls: bad certificate"``, ServerName ``""``)

Jul 14 09:54:09 k8s-master01 etcd[39692]: rejected connection from ``"192.168.0.108:46170" (error ``"remote error: tls: bad certificate"``, ServerName ``""``)

Jul 14 09:54:09 k8s-master01 etcd[39692]: rejected connection from ``"192.168.0.108:46172" (error ``"remote error: tls: bad certificate"``, ServerName ``""``)

Jul 14 09:54:09 k8s-master01 etcd[39692]: rejected connection from ``"192.168.0.108:46176" (error ``"remote error: tls: bad certificate"``, ServerName ``""``)

Jul 14 09:54:09 k8s-master01 etcd[39692]: rejected connection from ``"192.168.0.108:46174" (error ``"remote error: tls: bad certificate"``, ServerName ``""``)

Jul 14 09:54:09 k8s-master01 etcd[39692]: rejected connection from ``"192.168.0.108:46178" (error ``"remote error: tls: bad certificate"``, ServerName ``""``)

Jul 14 09:54:09 k8s-master01 etcd[39692]: rejected connection from ``"192.168.0.108:46180" (error ``"remote error: tls: bad certificate"``, ServerName ``""``)

Jul 14 09:54:10 k8s-master01 etcd[39692]: rejected connection from ``"192.168.0.108:46182" (error ``"remote error: tls: bad certificate"``, ServerName ``""``)

Jul 14 09:54:10 k8s-master01 etcd[39692]: rejected connection from ``"192.168.0.108:46186" (error ``"remote error: tls: bad certificate"``, ServerName ``""``)

|

image

解决方法:kill占用2379端口的进程,重启etcd即可。

image
image
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 213,992评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,212评论 3 388
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 159,535评论 0 349
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,197评论 1 287
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,310评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,383评论 1 292
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,409评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,191评论 0 269
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,621评论 1 306
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,910评论 2 328
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,084评论 1 342
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,763评论 4 337
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,403评论 3 322
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,083评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,318评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,946评论 2 365
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,967评论 2 351

推荐阅读更多精彩内容

  • 一、COREDNS 1.1yml文件 root@master1:~/maniftest/coredns# cat ...
    55ff35e076f3阅读 1,233评论 1 0
  • 污点、容忍度 给了节点选则的主动权,我们给节点打一个污点,不容忍的 pod就运行不上来,污点就是定义在 节点上的键...
    菜头_355f阅读 713评论 0 2
  • K8S一、二进制搭建1.安装要求(1)CentOS 7(2)禁止swap(3)集群间互通 2.操作系统初始化(1)...
    Saka_2859阅读 386评论 0 0
  • Kubernetes部属说明 环境准备 资料准备 开始部属 编写yaml文件,用于部属Kubenetes基础容器e...
    俊逸之光阅读 2,609评论 2 0
  • 安装k8s Master高可用集群 主机 角色 组件 172.18.6.101 K8S Master Kubele...
    jony456123阅读 8,046评论 0 9