<p>There is k8s pod yaml file that has 3 containers, here is the part of the yaml file:</p>
<pre><code>Containers:
  apple:
    Container ID:  
    Image:         busybox
    Image ID:      
    Port:          &lt;none&gt;
    Host Port:     &lt;none&gt;
    Command:
      sleep
      4500
    State:          Waiting
      Reason:       ContainerCreating
    Ready:          False
    Restart Count:  0
    Environment:    &lt;none&gt;
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-2ccr2 (ro)
  wine:
    Container ID:  
    Image:         busybox
    Image ID:      
    Port:          &lt;none&gt;
    Host Port:     &lt;none&gt;
    Command:
      sleep
      4500
    State:          Waiting
      Reason:       ContainerCreating
    Ready:          False
    Restart Count:  0
    Environment:    &lt;none&gt;
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-2ccr2 (ro)
  scarlet:
    Container ID:  
    Image:         busybox
    Image ID:      
    Port:          &lt;none&gt;
    Host Port:     &lt;none&gt;
    Command:
      sleep
      4500
    State:          Waiting
      Reason:       ContainerCreating
    Ready:          False
    Restart Count:  0
    Environment:    &lt;none&gt;
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-2ccr2 (ro)
</code></pre>
<p>I did &quot;kubectl describe pod mypod&quot;</p>
<p>I still had to count the num of containers.
What should i add to get the num of containers out of the file? Like this:</p>
<pre><code>kubectl describe pod mypod | grep -i containers
</code></pre>
<p>But this only finds the keyword.</p>
<pre><code>kubectl describe pod mypod | grep -i containers | wc -l
</code></pre>
<p>I just want it a nice eloquent 1 liner cmd to show me num of containers.</p>

ERJAN
<p>You can use <code>grep</code> for counting the occurrences of a key that every container is bound to have once and that cannot be mistaken with an other key; for example <code>Container ID:</code>:</p>
<pre class="lang-sh prettyprint-override"><code>kubectl describe pod mypod | grep -c 'Container ID:'
</code></pre>
