安装kubernetes之后,使用
kubectl get pod --all namespaces
查看所有pod,发现coredns的pod一直处于create的状态
使用命令查看
kubectl describe pod coredns-5c98db65d4-xxb6z -n kube-system
发现此pod报错为:
Warning FailedCreatePodSandBox 74s kubelet, node1 Failed create pod sandbox: rpc error: code = Unknown desc = [failed to set up sandbox container "79be600e4f1711672f9c42d6b1b03202d4a0682fb3175a0be99d976d0b01a4af" network for pod "coredns-5c98db65d4-xxb6z": NetworkPlugin cni failed to set up pod "coredns-5c98db65d4-xxb6z_kube-system" network: failed to find plugin "loopback" in path [/opt/cni/bin], failed to clean up sandbox container "79be600e4f1711672f9c42d6b1b03202d4a0682fb3175a0be99d976d0b01a4af" network for pod "coredns-5c98db65d4-xxb6z": NetworkPlugin cni failed to teardown pod "coredns-5c98db65d4-xxb6z_kube-system" network: failed to find plugin "portmap" in path [/opt/cni/bin]]
检查/opt/cni/bin目录下,发现没有文件,
于是执行
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
yum clean all
yum install kubernetes-cni -y
之后,检查/opt/cni/bin目录下,已经有文件,并且coredns能够正常执行,于是问题解决。