一、执行kubeadm init后报错[ERROR Swap]:running with swap on is not supported。
处理方法:
swapoff -a
# 防止开机自动挂载 swap 分区
sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
二、执行kubectl apply -f flannel.yaml后,coredns一直pending,所有节点仍然NotReady。
#排错
kubectl get pods -n kube-system
kubectl describe pod -n kube-system coredns-7ff-c5k
vim /var/log/messages
systemctl status kubelet -l
journalctl -u kubelet -f
desc日志:0/3 nodes are available: 3 node(s) had taint {node.kubernetes.io/not-ready: }, that the pod didn’t tolerate.
message日志: failed to find plugin “flannel” in path [/opt/cni/bin]
#最终处理方法:
下载flannel,所有节点 复制 flannel 到 /opt/cni/bin/ 。 此时全部节点变成ready状态,
参考:https://blog.csdn.net/qq_29385297/article/details/127682552 《failed to find plugin “flannel” in path [/opt/cni/bin]》
2.1 其他类似情况
处理手法类似。
failed to find plugin "portmap" in path [/opt/cni/bin]
0/3 nodes are available: 3 node(s) had taint {node.kubernetes.io/not-ready: }, that the pod didn't tolerate.
三、expects " or n,but found t, error found in
apply yaml文件时,报错,根据下图中的报错提示, v1.LabelSelector.MatchLabels 和 #10 byte of "access":true
定位是matchLabels:下面的access: true 有语法错误。
需要加双引号变成 access: "true"
四、error unknown flag: --label
通过--help和错误提示, 正确写法是 --labels
五、yaml中annotation的值写纯数字报错。
error: unable to decode annotation readString: expects " or n,but found 2,error found in #10 byte of
#模拟报错
[root@master01 c5] kubectl apply -f nginx-pod.yaml
error: unable to decode "nginx-pod.yaml": resource.metadataOnlyObject.ObjectMeta: v1.ObjectMeta.Annotations: ReadString: expects " or n, but found 1, error found in #10 byte of ...|version":1.1},"creat|..., bigger context ...|ta":{"annotations":{"app":"nginx-pod1","version":1.1},"creationTimestamp":null,"labels":{"run":"ngin|...
发现在annotation的value值写 纯数字,小数会报错。
version: 123 (会报错)
version: 1.2 (会报错)
version: 123v ( ok )
version: v123 ( ok )
version: v1.2 ( ok )
version: "123" ( ok )
处理方法: value加上双引号,或者写成数字+英文。
yaml语法检查网站: json2yaml.com/convert-yaml-to-json
本文的第五项与第三项可相互看。
六、排错执行的操作
kubectl logs -f kube-flannel-xxx
kubectl describe pod kube-flannel-xxx
cat /var/log/message
journalctl -u kubelet -f
七、pod的name不能含有大写,大写会报错。
这里的name的值需要符合RFC 1035规范。可以写 小写, -号 ,数字。比如 v-test-01
[root@master01 test_file]# kubectl apply -f nginx-pod.yaml
The Pod "nginxTEst" is invalid: metadata.name: Invalid value: "nginxTEst": a DNS-1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*')
[root@master01 test_file]#
八、DaemonSet的yaml文件,编写的报错。(报错文字的分析+排查)
from : “演示Daemonset部署fluentd组件-”
8.1、
写漏字母,比较好排查。DaemonSet.spec.template.spec.volumes[0]:unknow field “hotPath” in io.k8s.api.core.v1.volume
改成hostPath即可。
8.2、
最后一行的hostpath,写错了。应该写成hostPath (排错手法与8.1相同)
DaemonSet.spec.template.spec.volumes[1]:unknown field “hostpath” in io.k8s.api.core.v1.volume
8.3、(重要)
DaemonSet.spec.template.spec.volumes[1].hostPath:
invalid type for io.k8s.api.core.v1.HostPathVolumeSource: (重点是invalid type)
got “string”,expected “map” (得到了string类型,但需要的是map类型)
原错误文本:
hotstPath: /var/log 这样写是String类型 。
hostPath为object对象,他下面有两个字段path和type 。文中写成了string类型了。正确的写成下图:符合他说的map。
=分割线=
参考其他参数来看他所谓的String类型和object类型 (Map)。
String类型后面直接 接“字符串”。 object类型说明他有自己的fields,需要再看其下一层的内容。
小结:根据报错英文提示,参考kubectl explain进行排查
九、已在node1节点docker load镜像,但一直ErrImagePull
来源:安装k8s的dashboard组件-
背景:安装dashboard插件,已docker load -i dashboard_2_0_0.tar.gz
docker load -i dashboard_2_0_0.tar.gz
kubectl apply -f kubernetes-dashboard.yaml
kubectl get pods -n kubernetes-dashboard
kubectl describe pods kubernetes-dashboard-977xx -n kubernetes-dashboard
describe信息:
处理方法:
1、delete删除该pod,让其重新尝试拉取。(但错误依旧)
2、vim kubernetes-dashboard.yaml的 imagePullPolicy策略。 将Always(总是拉取镜像)换成 IfNotPresent
(如果有提子,那估计没这种报错)
十、cni网络插件有问题, apply yaml文件后,pod的状态一直是containerCreating。
之前虚拟机宕机,再次启动服务器后,calico出问题。
尝试新创建另一个pod (如nginx 、 busybox), 看新建的busybox是否有错 。
通过describe pod报错信息为:networkPlugin cni failed to teardown pod xxx 。 projectcalico.org
处理方法:
重置calico。重新安装calico.yaml (生产环境慎重操作)
十一、yaml格式,字段缩进错误,导致报错。
来源:statefulset通过存储类动态生成pv 15.30
原错误yaml文本:
11.1 在statefulSet.spec下 缺少必须字段selector
validationError(StatefulSet.spec) missing required filed “selector”
上图中有两个报错,先处理缺required field报错。 加上下图中selector内容即可。
11.2 由于缩进格式问题,出现unknown field spec
定位在validationError(statefulSet.spec.volumeClaimTemplates[0].metadata)下,unknown field ‘spec’。 通过kubectl explain查看是要写这个spec字段的。
报错时的格式:
metadata和spec是同级的field。 上图中spec缩进了一个空格,
那这样写就会被认为: metadata下有name 、annotations 、spec字段。所以报了unknown field ‘spec’ 。
11.3 同样的再举个错误的写法,他也会报错 unknown field
报错信息变成:validationError(statefulSet.spec.volumeClaimTemplates[0])下,unknown field ‘annotation’。报错的逻辑跟上面红字类似。volumeClaimTemplates下本身就不存在annotation字段。 (kubectl explain很有参考价值)
正确的:
小结:遇过几次unknown field的报错了。总的来说,写错单词,写错位置,缩进格式错误导致根本不存在该field。他都报这个unknown field
十二、node1节点状态notReady处理
问题描述:node1节点已经正常运行一段时间,虚拟机内存6GB。在master节点执行apply yaml文件后,容器状态是pending / containerCreating. 通过describe pod节点。 发现这pod竟然调度到了master节点,由于master本身有污点,报错了。(yaml文件写特别的容忍字段)
平常应该调度到node1节点上部署。 (node1 状态notReady后,不在集群里,调度跑到了 ready状态的master1上了。)
master节点查看
kubectl describe nodes node1
#不建议这样操作,应该取调整node1节点的硬件参数。
kubectl taint node master1 node-role.kubernetes.io/master-
文章来源:https://www.toymoban.com/news/detail-580079.html
free Unused memory (MemFree and SwapFree in /proc/meminfo)
===
available
Estimation of how much memory is available for starting new applications, without swapping. Unlike the data provided by the cache or free
fields, this field takes into account page cache and also that not all reclaimable memory slabs will be reclaimed due to items being in use
生产环境慎用!文章来源地址https://www.toymoban.com/news/detail-580079.html
#node1节点操作. 重启完后node1节点恢复回ready状态
systemctl restart kubelet
systemctl restart kubelet
到了这里,关于k8s排错随记(一)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!