When creating 'multi-pod' containers, just use the imperative command kubectl ru . . .

Jesse Adelman:
Also, a tip I’ve not seen elsewhere:

When creating ‘multi-pod’ containers, just use the imperative command kubectl run multi-pod --image <1st container image>... -o yaml --dry-run=client >> multi-pod.ymland then kubectl run <2nd container name> --image <2nd container image> -o yaml --dry-run=client >> multi-pod.yml. Then, just remove the extra lines between the first pod stanza and the second, until you have two container definitions for one pod. :slightly_smiling_face:

Joe:
Hey Jesse, Ive been wondering about this for a while, but what do you mean when you say pod stanza? Can you paste the resultant yaml file?

I keep trying this and getting a pod status of "CrashLoopBackOff' with error of

2021/04/23 01:55:01 [emerg] 1#1: bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)

unnivkn:
nice one @Jesse Adelman

unnivkn:
@Joe…pls try this.
kubectl run multipod --image=nginx --dry-run=client -oyaml>multipod.yaml
kubectl run beta --image=busybox --command sleep 4800 --dry-run=client -oyaml>>multipod.yaml

vi multipod.yaml

–> Podname: multipod (containers; alpha & beta)
–> update first conytainer name:line 11 --> name: alpha
–> delete below 13-lines (from line-12 onwords)
—> you are good now to apply the yaml file.
–> kubectl describe po multipod

Tej_Singh_Rana:
Hello, @Joe
Can you please share your rYAML file? It looks like you’re using nginx image in both containers.

Tej_Singh_Rana:
so conflicting default port (80).

Joe:
@Tej_Singh_Rana, you are correct, I WAS trying to use 2x nginx pods. However, I finally got the below yaml file to work using 2x different images.

Is it not possible to use the same image(nginx) for different containers in a pod?

Working yaml below - thx @unnivkn

apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: multipod
  name: multipod
spec:
  containers:
  - image: nginx
    name: alpha
    resources: {}
  - command:
    - sleep
    - "4800"
    image: busybox
    name: beta
  dnsPolicy: ClusterFirst
  restartPolicy: Always
status: {}

Tej_Singh_Rana:
Yeah, It’s possible but make sure use different containerPort for 2nd nginx container.

Joe:
Oh, OK, so if its the same image, then their default port values conflict. Makes sense.

Thank you

unnivkn:
you may end up with this error: root@controlplane:~# kubectl logs multipod1 -c beta1 | grep -i failed
2021/04/23 04:10:11 [emerg] 1#1: bind() to 0.0.0.0:80 failed (98: Address already in use)