kubectl 使用过程中的错误记录及解决方法

分类:Docker |

1. kubectl 无法删除 Unknown 的pods

场景, 由于网络环境变化, 对应的pods 关系出现错误, 导致无法删除, 使用 kubectl delete pods --all --force 也无法删除, 重启服务也无法删除:

image.png


解决方法, 删除命令: 

kubectl get pods -o wide|grep nginx|awk '{print $1}'|xargs kubectl delete pod --force --grace-period=0


2. 无法创建 nodes 使用 kubectl get nodes 命令, 节点一直无法创建一例:

在master 上 使用  tail -f /var/log/messages 查看:

错误信息:

Oct 18 20:31:42 localhost kube-scheduler: I1018 20:31:42.661925    2516 event.go:217] Event(api.ObjectReference{Kind:"Pod", Namespace:"kube-system", Name:"kubernetes-dashboard-latest-240878077-t39z6", UID:"c5800350-1130-11eb-817d-000c299d0b62", APIVersion:"v1", ResourceVersion:"103772", FieldPath:""}): type: 'Warning' reason: 'FailedScheduling' no nodes available to schedule pods

Connection to 192.168.1.105 closed by remote host.


在worker 上 使用  tail -f /var/log/messages 查看: 

Oct 18 20:45:45 localhost kubelet: E1018 20:45:45.663361    9126 kubelet_node_status.go:98] Unable to register node "192.168.1.104#" with API server: Node "192.168.1.104#" is invalid: [metadata.name: Invalid value: "192.168.1.104#": must match the regex [a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)* (e.g. 'example.com'), metadata.labels: Invalid value: "192.168.1.104#": must match the regex (([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])? (e.g. 'MyValue' or 'my_value' or '12345')]


问题原因:

因为自己注册: 在此配置文件  /etc/kubernetes/kubelet 中IP后添加了注释  # worker 的地址, 不然可能导致service 无法访问

如: 

KUBELET_HOSTNAME="--hostname-override=192.168.1.104" # worker 的地址, 不然可能导致service 无法访问

解决方法: 

将注释新起一行, 不要写在 KUBELET_HOSTNAME 的后面即可

即: 

# worker 的地址, 不然可能导致service 无法访问

KUBELET_HOSTNAME="--hostname-override=192.168.1.104"


3. k8s 中使用 nodePort 时 外部机器无法访问端口: 

问题现象:

a. 使用netstat -tunlp 查看, nodePort端口开启正常

b. 在worker机器上使用 curl 进行访问, 正常

c. 在同网段其它机器可以正常访问worker中的其它端口

d. 在同网段其它机器无法访问nodePort 端口

e. getenforce 查看selinux状态, 已禁用

f.  firewall-cmd --state  结果是 not running 


解决方法:

在worker机器上执行, 

iptables -P FORWARD ACCEPT