解决k8s pod报错: Failed to create pod sandbox: rpc error networkPlugin cni failed
前言
k8s
在部署 pod
时报错:
Warning FailedCreatePodSandBox 9m35s kubelet Failed to create pod sandbox: rpc error: code = Unknown desc = [failed to set up sandbox container "5f8aec7f5368eb8c5b023519739cc75c199d76457c262bc636df7a7741abe5d7" network for pod "ingress-nginx-controller-hldh6": networkPlugin cni failed to set up pod "ingress-nginx-controller-hldh6_ingress-nginx" network: failed to find plugin "loopback" in path [/opt/cni/bin], failed to clean up sandbox container "5f8aec7f5368eb8c5b023519739cc75c199d76457c262bc636df7a7741abe5d7" network for pod "ingress-nginx-controller-hldh6": networkPlugin cni failed to teardown pod "ingress-nginx-controller-hldh6_ingress-nginx" network: failed to find plugin "bandwidth" in path [/opt/cni/bin]]
这个错误表明 Kubernetes
在创建 pod
时遇到了网络问题,具体是 Container Network Interface
(CNI) 插件配置异常。
错误信息中提到在 /opt/cni/bin
路径下找不到 "loopback" 和 "bandwidth" 插件,导致 pod
的网络无法正确设置。
检查 CNI 插件是否安装
在出问题的节点上,运行以下命令检查 /opt/cni/bin
目录内容
ls /opt/cni/bin
如果目录为空,或者缺少 loopback
和 bandwidth
等插件,则需要安装它们。
安装缺失的 CNI 插件
# 下载与 Kubernetes v1.26.5 兼容的 CNI 版本(更新下载链接)
wget https://github.com/containernetworking/plugins/releases/download/v1.2.0/cni-plugins-linux-amd64-v1.2.0.tgz
# 解压并覆盖所有插件(确保其他依赖插件也存在)
sudo tar -xzvf cni-plugins-linux-amd64-v1.2.0.tgz -C /opt/cni/bin/ --overwrite
# 检查 kubelet 和 CNI 的版本关联性
kubelet --version # Kubernetes v1.26.5
ls /opt/cni/bin/loopback /opt/cni/bin/bandwidth # 确认文件存在且版本为 v1.2.0
重启 kubelet,应用配置
检查 kubelet
参数,确定启动参数包含 --network-plugin=cni
和 --cni-bin-dir=/opt/cni/bin
有些配置可能是写在了 /etc/kubernetes/kubelet-config.yaml
文件中,最后执行重启命令
sudo systemctl restart kubelet
验证kubelet
状态
systemctl status kubelet
并强制删除故障 Pod
kubectl delete pod -n ingress-nginx ingress-nginx-controller-hldh6 --force
完美解决!