<p>While installing Kubernetes with, I'm stuck at CNI plugin installation and configuration part. I have installed Flannel but I see error in kubelet logs due to which coredns pods are in pending state.</p>

<p>OS: Centos7
k8s version: 1.16
Kubeadm is being used to setup the cluster.</p>

<p>I had installed the plugin using: kubectl apply -f <a href="https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml" rel="noreferrer">https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml</a></p>

<p>This is error I can see in Kubelet logs:</p>

<pre><code>Sep 21 04:47:29 peteelizalde2c kubelet: W0921 04:47:29.897759   17817 cni.go:202] Error validating CNI config &amp;{cbr0  false [0xc000fb3ee0 0xc000fb3f60] [123 10 32 32 34 110 97 109 101 34 58 32 34 99 98 114 48 34 44 10 32 32 34 112 108 117 103 105 110 115 34 58 32 91 10 32 32 32 32 123 10 32 32 32 32 32 32 34 116 121 112 101 34 58 32 34 102 108 97 110 110 101 108 34 44 10 32 32 32 32 32 32 34 100 101 108 101 103 97 116 101 34 58 32 123 10 32 32 32 32 32 32 32 32 34 104 97 105 114 112 105 110 77 111 100 101 34 58 32 116 114 117 101 44 10 32 32 32 32 32 32 32 32 34 105 115 68 101 102 97 117 108 116 71 97 116 101 119 97 121 34 58 32 116 114 117 101 10 32 32 32 32 32 32 125 10 32 32 32 32 125 44 10 32 32 32 32 123 10 32 32 32 32 32 32 34 116 121 112 101 34 58 32 34 112 111 114 116 109 97 112 34 44 10 32 32 32 32 32 32 34 99 97 112 97 98 105 108 105 116 105 101 115 34 58 32 123 10 32 32 32 32 32 32 32 32 34 112 111 114 116 77 97 112 112 105 110 103 115 34 58 32 116 114 117 101 10 32 32 32 32 32 32 125 10 32 32 32 32 125 10 32 32 93 10 125 10]}: [plugin flannel does not support config version ""]
Sep 21 04:47:29 peteelizalde2c kubelet: W0921 04:47:29.897824   17817 cni.go:237] Unable to update cni config: no valid networks found in /etc/cni/net.d
Sep 21 04:47:32 peteelizalde2c kubelet: E0921 04:47:32.007379   17817 kubelet.go:2187] Container runtime network not ready: NetworkReady=false reason:NetworkPluginNotReady message:docker: network plugin is not ready: cni config uninitialized
</code></pre>

<p>Here is the pods:</p>

<pre><code>kubectl get pods --all-namespaces
NAMESPACE     NAME                                                                        READY   STATUS    RESTARTS   AGE
kube-system   coredns-5644d7b6d9-n4h5x                                                    0/1     Pending   0          114m
kube-system   coredns-5644d7b6d9-t2q54                                                    0/1     Pending   0          114m
kube-system   etcd-ip-10-29-89-124                      1/1     Running   0          113m
kube-system   kube-apiserver-ip-10-29-89-124            1/1     Running   0          113m
kube-system   kube-controller-manager-ip-10-29-89-124   1/1     Running   0          113m
kube-system   kube-flannel-ds-amd64-dqpzj                                                 1/1     Running   0          110m
kube-system   kube-proxy-vzlqb                                                            1/1     Running   0          114m
kube-system   kube-scheduler-ip-10-29-89-124            1/1     Running   0          113m
</code></pre>

<p>There is a file in <code>/etc/cni/net.d</code> named <code>10-flannel.conflist</code>.
Its contents are:</p>

<pre><code>{
  "name": "cbr0",
  "plugins": [
    {
      "type": "flannel",
      "delegate": {
        "hairpinMode": true,
        "isDefaultGateway": true
      }
    },
    {
      "type": "portmap",
      "capabilities": {
        "portMappings": true
      }
    }
  ]
}
</code></pre>

<p>The accepted solution is incomplete and will cause headache down the line.</p>

<p>The proper solution to make this change permanent is to edit the ConfigMap created by flannel in your Kubernetes cluster. Otherwise, the file  will be recreated the next time the flannel pod volumes are populated with the ConfigMap (e.g. on node reboot).</p>

<p>Use <code>kubectl edit cm -n kube-system kube-flannel-cfg</code> to edit the ConfigMap provided by flannel, and add the missing line:</p>

<pre><code>  5 apiVersion: v1
  6 data:
  7   cni-conf.json: |
  8     {
  9       "name": "cbr0",
 10       "cniVersion": "0.2.0",
 11       "plugins": [
</code></pre>

<p>Reboot the node, or alternatively make the change manually in <code>/etc/cni/net.d/10-flannel.conflist</code> and do <code>systemctl restart kubelet</code> afterwards to skip the reboot.</p>
