<p>I am new to Kubernetes. Just set up the stack one master and another slave ( two Ec2 Instances ) when trying to deploy my first pod on the slave I got below error. Could you hlep me out. Error file is attached.</p>
<p><strong>Error:</strong></p>
<blockquote>
<p>Warning  FailedCreatePodSandBox  34m                     kubelet, slave-node  Failed to create pod sandbox: rpc error: code = Unknown desc = failed to set up sandbox container &quot;26cdaf3170806455a4731218d20c482bb2a41ded6ef85c90b560058e332df684&quot; network for pod &quot;label-demo&quot;: networkPlugin cni failed to set up pod &quot;label-demo_default&quot; network: open /run/flannel/subnet.env: no such file or directory</p>
</blockquote>

<p>As the state of this cluster, how exactly it was deployed as well as the output messages of <code>kubectl</code>, <code>kubelet</code> are unknown, I will try to give some troubleshooting steps and circumstances that can lead to resolving some of the problems that are encountered here. </p>

<ul>
<li>Kubeadm</li>
<li>Flannel </li>
<li>Kubelet </li>
<li>Reproduction </li>
<li>Additional links</li>
</ul>

<h3>Kubeadm</h3>

<p>The first thing is provisioning process of the Kubernetes cluster with <code>kubeadm</code>: </p>

<p>Check all the requirements and steps with official documentation: </p>

<ul>
<li><a href="https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/" rel="nofollow noreferrer">Kubernetes.io: Install kubeadm</a>.</li>
<li><a href="https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/" rel="nofollow noreferrer">Kubernetes.io: Create cluster kubeadm</a></li>
</ul>

<p>When invoking <code>$ kubeadm init</code> command please make sure to add parameters like:</p>

<ul>
<li><code>--apiserver-advertise-address=IP_ADDRESS_OF_MASTER_NODE</code></li>
<li><code>--pod-network-cidr=POD_NETWORK_CIDR_WITH_ACCORDANCE_TO_CNI</code></li>
</ul>

<p><strong>Provisioning cluster without <code>--pod-network-cidr</code> parameter could lead to CNI related issues.</strong></p>

<p>For Flannel default pod network cidr is <code>10.244.0.0/16</code>. </p>

<p>After <code>kubeadm init</code> you need to apply one of many CNI's (like Flannel or Calico) as the <code>kubeadm</code> tool does not do it automatically. </p>

<p>Please check if all of the nodes are in <code>Ready</code> status with command:</p>

<p><code>$ kubectl get nodes -o wide</code></p>

<p>Output of this command should look like that:</p>

<pre class="lang-sh prettyprint-override"><code>NAME   STATUS   ROLES    AGE   VERSION   INTERNAL-IP   EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION   CONTAINER-RUNTIME
k1     Ready    master   69m   v1.17.3   10.156.0.29   &lt;none&gt;        Ubuntu 18.04.4 LTS   5.0.0-1031-gcp   docker://19.3.7
k2     Ready    &lt;none&gt;   65m   v1.17.3   10.156.0.30   &lt;none&gt;        Ubuntu 18.04.4 LTS   5.0.0-1031-gcp   docker://19.3.7
k3     Ready    &lt;none&gt;   63m   v1.17.3   10.156.0.35   &lt;none&gt;        Ubuntu 18.04.4 LTS   5.0.0-1031-gcp   docker://19.3.7
</code></pre>

<p>Additionally you can <code>$ kubectl describe node NAME_OF_THE_NODE</code> to get more detailed information about each of the nodes. </p>

<h3>Flannel</h3>

<p>There is official documentation about troubleshooting Flannel related issues: <a href="https://github.com/coreos/flannel/blob/master/Documentation/troubleshooting.md" rel="nofollow noreferrer">Github.com: flannel troubleshooting</a> </p>

<p>The message that you received from <code>kubelet</code>:</p>

<blockquote>
  <p>Warning FailedCreatePodSandBox 34m kubelet, slave-node Failed to create pod sandbox: rpc error: code = Unknown desc = failed to set up sandbox container "26cdaf3170806455a4731218d20c482bb2a41ded6ef85c90b560058e332df684" network for pod "label-demo": networkPlugin cni failed to set up pod "label-demo_default" network: open /run/flannel/subnet.env: no such file or directory</p>
</blockquote>

<p>Is telling that there is <code>subnet.env</code> file missing on a node that was supposed to schedule a <code>sandbox</code> pod.</p>

<p>Furthermore please check if Flannel pods are running correctly. You can check it with either: </p>

<ul>
<li><code>$ kubectl get pods -A</code></li>
<li><code>$ kubectl get pods -n kube-system</code></li>
</ul>

<p>Additionally you can check logs of this pods by running command: 
<code>$ kubectl logs NAME_OF_FLANNEL_CONTAINER</code></p>

<h3>Kubelet</h3>

<p>You can check <code>kubelet</code> logs by (on systemd os) with:</p>

<ul>
<li><code>$ systemctl status kubelet</code></li>
<li><code>$ journalctl -u kubelet</code></li>
</ul>

<h3>Reproduction</h3>

<p>I've managed to reproduce error that you encountered and it was happening when: </p>

<ul>
<li><code>--pod-network-cidr=CIDR</code> was not used with <code>$ kubeadm init</code> </li>
<li>Flannel CNI was applied after <code>$ kubeadm init</code> without <code>--pod-network-cidr</code></li>
</ul>

<h3>Additional links:</h3>

<p>There is an article talking about troubleshooting networking: <a href="https://kubernetes.feisky.xyz/v/en/index/network" rel="nofollow noreferrer">Kubernetes.feisky.xyz: Network</a>.</p>

<p>Please let me know if you have any other questions </p>
