How to create mult-container pods using –dry-run=client?

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:

kubectl run busybox --image=busybox --dry-run=client -o yaml -- /bin/sh -c 'some commands' > pod.yaml

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

kubectl create -f pod.yaml
kubectl get pods

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 --dry-run=client and/or running the command combined with dry run but I can't seem to find a good answer to that. Thanks in advance.

EDIT: pod.yaml

apiVersion: v1
kind: Pod
  creationTimestamp: null
    run: busybox
  name: busybox
  - args:
    - /bin/sh
    - -c
    - while true; do echo ‘Hi I am from Main container’ >> /var/log/index.html; sleep
      5; done
    image: busybox
    name: busybox
    - mountPath: /var/log
      name: log-vol
    image: nginx
    name: nginx
    - mountPath: /usr/share/nginx/html
      name: log-vol
    - containerPort: 80
  - name: log-vol
    emptyDir: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Always
status: {}

Read more here:

Content Attribution

This content was originally published by humiliatedpenguin at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: