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
metadata:
  creationTimestamp: null
  labels:
    run: busybox
  name: busybox
spec:
  containers:
  - 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
    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: {}


Read more here: https://stackoverflow.com/questions/66336414/how-to-create-mult-container-pods-using-dry-run-client

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: