重启之后k8s集群居然起不起来了
解决方法:重装
重装前清除环境方法:
kubeadm reset
systemctl stop kubelet
systemctl stop docker
rm -rf /var/lib/cni/ /var/lib/kubelet/* /etc/cni/
ifconfig cni0 down
ifconfig flannel.1 down
ifconfig docker0 down
ip link delete cni0
ip link delete flannel.1
systemctl start docker
# kubeadm join xxx
重装后pod-coredns一直处于ContainerCreating状态:
看是否重装了Pod Network
$ curl -O https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
如果node有多个网卡,需编辑kube-flannel.yml,用--iface指定网卡
containers:
- name: kube-flannel
image: quay.io/coreos/flannel:v0.11.0-amd64
command:
- /opt/bin/flanneld
args:
- --ip-masq
- --kube-subnet-mgr
- --iface=eth1
apply kube-flannel
$ kubectl apply -f kube-flannel.yml
clusterrole.rbac.authorization.k8s.io/flannel created
clusterrolebinding.rbac.authorization.k8s.io/flannel created
serviceaccount/flannel created
configmap/kube-flannel-cfg created
daemonset.extensions/kube-flannel-ds-amd64 created
daemonset.extensions/kube-flannel-ds-arm64 created
daemonset.extensions/kube-flannel-ds-arm created
daemonset.extensions/kube-flannel-ds-ppc64le created
daemonset.extensions/kube-flannel-ds-s390x created
但是仍然pod-coredns一直处于ContainerCreating状态
kubectl describe pod一下,发现是/var/lib/cni找不到
mkdir -p /etc/cni/net.d
cat > /etc/cni/net.d/10-flannel.conflist << EOF
{
"name": "cbr0",
"plugins": [
{
"type": "flannel",
"delegate": {
"hairpinMode": true,
"isDefaultGateway": true
}
},
{
"type": "portmap",
"capabilities": {
"portMappings": true
}
}
]
}
EOF
然后重启kubectl,发现还是不行。
再修改/run/flannel/subnet.env
$ vim /run/flannel/subnet.env
FLANNEL_NETWORK=10.244.0.0/16
FLANNEL_SUBNET=10.244.0.1/24
FLANNEL_MTU=1450
FLANNEL_IPMASQ=true
保存再重启kubectl,终于可以了。
也许本来就只需要改/run/flannel/subnet.env文件。不过现在已经无法验证了。
只能等下次出问题再验证。
参考网址:
https://blog.csdn.net/ANXIN997483092/article/details/86711006
https://blog.csdn.net/qq_26545503/article/details/123183184
https://www.cnblogs.com/aresxin/p/K8S-issue1.html
转载请注明来源:https://www.cnblogs.com/bugutian/