k8s “Unable to update cni config: No networks found in /etc/cni/net.d“解决方案

现象

执行kubeadm reset --force 命令重置之后再执行kubeadm init --config ~/kubeadm-config.yaml 后执行systemctl status kubelet查看kubelet 服务状态发现报错,Unable to update cni config: No networks found in /etc/cni/net.d

解决办法

  • 这个错误和cni网络插件有关,先确定已经按照官方文档下载好cni插件
    https://kubernetes.io/zh/docs/setup/production-environment/tools/kubeadm/install-kubeadm
    无包管理器的情况这一栏下面
    CNI_VERSION="v0.8.2"
    ARCH="amd64"
    sudo mkdir -p /opt/cni/bin
    curl -L "https://github.com/containernetworking/plugins/releases/download/${CNI_VERSION}/cni-plugins-linux-${ARCH}-${CNI_VERSION}.tgz" | sudo tar -C /opt/cni/bin -xz
    
  • 创建配置文件
    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
    
  • 执行systemctl restart kubelet 重启服务然后初始化集群节点即可

其他

  • cniVersion问题 : https://www.cnblogs.com/winstom/p/11836844.html
  • flannel 和路由问题等: https://stackoverflow.com/questions/43713509/kubernetes-v1-6-2-unable-to-update-cni-config-no-networks-found-in-etc-cni-net
  • 修改10-kubeadm.conf网络插件配置参数: https://blog.csdn.net/peishucai/article/details/101172708
    修改时需要注意注意配置路径和插件路径等, 比如说我的路径是/etc/systemd/system/kubelet.service.d/10-kubeadm.conf 新增了Environment="KUBELET_NETWORK_ARGS=--network-plugin=cni --cni-conf-dir=/etc/cni/ --cni-bin-dir=/opt/cni/bin"这一行, 完整配置如下:
    # Note: This dropin only works with kubeadm and kubelet v1.11+
    [Service]
    Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf"
    Environment="KUBELET_CONFIG_ARGS=--config=/var/lib/kubelet/config.yaml"
    Environment="KUBELET_NETWORK_ARGS=--network-plugin=cni --cni-conf-dir=/etc/cni/ --cni-bin-dir=/opt/cni/bin"
    # This is a file that "kubeadm init" and "kubeadm join" generates at runtime, populating the KUBELET_KUBEADM_ARGS variable dynamically
    EnvironmentFile=-/var/lib/kubelet/kubeadm-flags.env
    # This is a file that the user can use for overrides of the kubelet args as a last resort. Preferably, the user should use
    # the .NodeRegistration.KubeletExtraArgs object in the configuration files instead. KUBELET_EXTRA_ARGS should be sourced from this file.
    EnvironmentFile=-/etc/default/kubelet
    ExecStart=
    ExecStart=/usr/local/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS $KUBELET_KUBEADM_ARGS $KUBELET_EXTRA_ARGS
    

参考

https://fantashit.com/unable-to-update-cni-config-no-networks-found-in-etc-cni-net-d/

你可能感兴趣的:(Kubernetes,linux,docker,k8s,kubernetes,cni)