Kubernetes 故障修复
初始化报错
error execution phase preflight: [preflight] Some fatal errors occurred:
[ERROR CRI]: container runtime is not running: output: E1115 15:55:45.917967 13996 remote_runtime.go:948] “Status from runtime service failed” err=”rpc error: code = Unimplemented desc = unknown service runtime.v1alpha2.RuntimeService”
time=”2022-11-15T15:55:45+08:00” level=fatal msg=”getting status of runtime: rpc error: code = Unimplemented desc = unknown service runtime.v1alpha2.RuntimeService”
, error: exit status 1
[preflight] If you know what you are doing, you can make a check non-fatal with--ignore-preflight-errors=...
To see the stack trace of this error execute with —v=5 or higher
1 | rm /etc/containerd/config.toml |
CoreDNS 报错
CoreDNS 一直处于创建(ContainerCreating)状态1
2
3
4
5
kubectl describe pod coredns-7f89b7bc75-h225g -n kube-system
kubectl describe pod coredns-7f89b7bc75-rb89w -n kube-system
kubectl logs coredns-7f89b7bc75-h225g -n kube-system
kubectl logs coredns-7f89b7bc75-rb89w -n kube-system
cni0 网桥配置了一个不同网段的 IP 地址所导致的,做法是删除 cni0,让网络插件重新自动创建。
由于 cni0 是作为 Docker 的网桥,因此需要暂停 Docker 和 K8s。1
2
3
4
5
6
7
8
9
10
11
12kubeadm reset
rm -f /etc/cni/net.d/*
rm -rf $HOME/.kube/config
systemctl stop kubelet & systemctl stop docker
rm -rf /var/lib/cni/
rm -rf /var/lib/kubelet/
rm -rf /etc/cni/
ifconfig cni0 down
ifconfig flannel.1 down
ifconfig docker0 down
ip link delete cni0
ip link delete flannel.1
然后重新初始化,添加 Flannel 组件1
2
3
4
5
6
7
8
9
10systemctl start kubelet & systemctl start docker
kubeadm init \
--apiserver-advertise-address=192.168.1.101 \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.25.0 \
--service-cidr=10.96.0.0/12 \
--pod-network-cidr=10.244.0.0/16 \
--ignore-preflight-errors=Swap
kubectl apply -f kube-flannel.yml
重启后查询 node 报错
The connection to the server 192.168.254.101:6443 was refused - did you specify the right host or port?
journalctl -xe fu kubelet
1
failed to run Kubelet: running with swap on is not supported, please disable swap! or set --fail-swap-on flag to false. /proc/swaps contain
看报错是 SWAP 没有永久关闭1
2
3
4swapoff -a
sed -i 's/\/dev\/mapper\/centos-swap/\#\/dev\/mapper\/centos-swap/g' /etc/fstab
#重启服务器
kubectl get node -n kube-system -o wide