title: Steps of Kubernetes CNI when using Flannel
body: <p>I have been setting up Kubernets with kubeadm and I have used Flannel to setup the pod network. The setup basically worked but I have been running into all kinds of problems (and bugs) and now I am trying to gain a better understanding of the different steps involved in network setup process (e.g. CNI and flannel).</p>
  
  <p>From an end-user/admin perspective I simply pass <code>--pod-network-cidr</code> with some network argument to <code>kubeadm</code> and then later I apply a pod configuration for flannel using <code>kubectl</code>. Kubernetes will then start a flannel pod on each of my nodes. Assuming everything worked, flannel should then use the container network interfaces (CNI) of Kubernetes to setup the pod network.</p>
  
  <p>As a result of this process I should get a pod network which includes the following:</p>
  
  <ol>
  <li>A <code>cni0</code> bridge.</li>
  <li>A <code>flannel.x</code> interface.</li>
  <li>iptables entries to route between the host and the pod network.</li>
  </ol>
  
  <p>The following files and binaries seem to be involved in the setup:</p>
  
  <ol>
  <li><code>kubectl</code> reads a CNI configuration such as <code>/etc/cni/net.d/10-flannel.conflist</code> and invokes the CNI plugin described in the config file.</li>
  <li>Somehow a folder <code>/var/lib/cni</code> is being created which seems to contain configuration files for the network setup.</li>
  <li>A CNI plugin such as <code>/opt/cni/bin/flannel</code> is run, I don't yet understand what it does.</li>
  </ol>
  
  <p>What am I missing on this list and how does (2.) fit into these steps. How does <code>/var/lib/cni</code> get created and which program is responsible for this?</p>