<p>I am working on practicing for the CKAD exam and ran into an interesting problem with a multi-container pod that I can't seem to find an answer to. Lets say I run this imperative command to create a pod.yaml:</p>
<pre><code>kubectl run busybox --image=busybox --dry-run=client -o yaml -- /bin/sh -c 'some commands' &gt; pod.yaml
</code></pre>
<p>I then edit that yaml definition to add a sidecar nginx container with just a name and image. When I go to create this pod with</p>
<pre><code>kubectl create -f pod.yaml
kubectl get pods
</code></pre>
<p>I get a pod with a single nginx container even though the busybox container is still defined in the pod spec yaml. I suspect this is due to something with <code>--dry-run=client</code> and/or running the command combined with dry run but I can't seem to find a good answer to that. Thanks in advance.</p>
<p>EDIT:
pod.yaml</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: busybox
  name: busybox
spec:
  containers:
  - args:
    - /bin/sh
    - -c
    - while true; do echo ‘Hi I am from Main container’ &gt;&gt; /var/log/index.html; sleep
      5; done
    image: busybox
    name: busybox
    volumeMounts:
    - mountPath: /var/log
      name: log-vol
    image: nginx
    name: nginx
    volumeMounts:
    - mountPath: /usr/share/nginx/html
      name: log-vol
    ports:
    - containerPort: 80
  volumes:
  - name: log-vol
    emptyDir: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Always
status: {}
</code></pre>

<p>Expanding on my comment:</p>
<p>A list in YAML is a series of items marked with a leading <code>-</code>, like
this list of strings:</p>
<pre><code>- one
- two
- three
</code></pre>
<p>Or this list of dictionaries:</p>
<pre><code>containers:
  - image: busybox
    name: busybox
  - image: nginx
    name: nginx
</code></pre>
<p>Or even this list of lists:</p>
<pre><code>outerlist:
  -
    - item 1.1
    - item 1.2
    - item 1.3
  -
    - item 2.1
    - item 2.2
    - item 2.3
</code></pre>
<p>Your <code>pod.yaml</code> as written has only a single item in your <code>containers</code>
list. You need to mark the second item:</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: busybox
  name: busybox
spec:
  containers:

  - args:
    - /bin/sh
    - -c
    - while true; do echo ‘Hi I am from Main container’ &gt;&gt; /var/log/index.html; sleep
      5; done
    image: busybox
    name: busybox
    volumeMounts:
    - mountPath: /var/log
      name: log-vol

  - image: nginx
    name: nginx
    volumeMounts:
    - mountPath: /usr/share/nginx/html
      name: log-vol
    ports:
    - containerPort: 80
  volumes:
  - name: log-vol
    emptyDir: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Always
</code></pre>
