[บันทึกกันลืม] K8S เอา node เดิม join กลับเข้ามาไม่ได้ เป็นปัญหาเพราะ CNI

ปัญหา: ในบางกรณี เราต้อง delete node ออกไป แต่บางที join กลับได้ แต่ ไม่สามารถ allocate pod ไปได้

sudo kubectl describe pod/thepod -n thenamespace

แล้วพบว่า

Error syncing pod, skipping: failed to "SetupNetwork" for "thepod" with SetupNetworkError: "Failed to setup network for pod \"...(...)\" using network plugins \"cni\": no IP addresses available in network: podnet; Skipping pod"

ให้ทำดังต่อไปนี้ กับ nodeX ที่มีปัญหา (ดูจาก subnet ที่ปรากฏ) ด้วยคำสั่งต่อไปนี้

เริ่มจากไปที่ control plane แล้ว delete nodeX ออกไป

sudo kubectl delete node nodeX
sudo kubeadm token create --print-join-command

แล้ว copy คำสั่งที่ได้มา หน้าตาประมาณนี้

kubeadm join ip.of.control.plane:6443 --token xxxxxxxxxx --discovery-token-ca-cert-hash sha256:yyyyyyyyyyyyyyyyyyyyyy

จากนั้นไปที่ nodeX

sudo systemctl stop containerd
sudo systemctl stop kubelet
sudo ip link set cni0 down
sudo brctl delbr cni0
rm -rf /run/flannel/subnet.env
rm -rf /etc/kubernetes/kubelet.conf
rm -rf /etc/kubernetes/pki/ca.crt
sudo systemctl start containerd
kubeadm join ip.of.control.plane:6443 --token xxxxxxxxxx --discovery-token-ca-cert-hash sha256:yyyyyyyyyyyyyyyyyyyyyy

ก็จะใช้งานได้แล้ว

Note: ถ้าพบปัญหา CNI อีก ให้ลองที่ node นั้น ด้วยคำสั่ง

 systemctl restart containerd 

คาดหวังว่าจะได้ cni interface เกิดขึ้น จากการดูคำสั่ง

ip addr | grep cni

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.