kubernetes flannel 网卡绑定错误,故障排查

kubernetes 新加了个node,状态Ready,但调度过去的任务,都执行异常

查看异常节点日志

`Error adding net work: open run/flannel/subnet.env no such file or directory`

flannel 有问题

环境里flannel也是在容器里启动的,查看flannel,果然新节点的flannel服务没有起来

kbs get pods
kube-flannel-ds-28rh8 0/1 CrashLoopBackOff 7 1h

追查flannel启动日志

kbs logs --tail 10 -f kube-flannel-ds-28rh8
I1213 07:44:58.471264 1 main.go:201] Could not find valid interface matching en1: failed to find IPv4 address for interface en1
E1213 07:44:58.471366 1 main.go:225] Failed to find interface to use that matches the interfaces and/or regexes provided

interface en1 网卡问题

ifcofing 查看

原来这个节点的ip绑在en2上

再看其他节点运行正常的flannel,也是指向的en1

/opt/bin/flanneld --ip-masq --kube-subnet-mgr --iface=en1

问题已经定位到

k8s集群原来机器的ip都在en1上,flannel节点启动设置的网卡都在en1,新加的这台节点ip却在en2上,以en1启动则失败

查看flannel的配置
kubectl -n kube-system get ds kube-flannel-ds -o yaml
...
containers:
- args:
- --ip-masq
- --kube-subnet-mgr
- --iface=en1
...
果然这里也是en1

运维比较给力,10分就换好了网卡,服务正常恢复

如果无法更换网卡则需改个iface=en1这个参数

flannel如果在宿主机上,改宿主机的设置即可,但这里的flannel都是在容器内启动的

为了通用把
--iface=en1
改为(192.168.1.255是子网绑定的ip)
--iface=$(ip add |grep 192.168.1.255 |awk '{print $7}')

需要改的地方就是如何把有效的网卡拿出来

但这个方式通用性还是不太好

更复杂的通用办法就是写个复杂的sh,加入sh打成镜象或把sh映射到容器里,用sh替换启动容器的命令

原文地址:https://www.cnblogs.com/zihunqingxin/p/10461020.html