Bansi:
If I was asked to add a sidecar container with an echo command to an existing container. I tried adding it like a mutli container but it crashes rite away. Any advice.
Tej_Singh_Rana:
Hello, @Bansi
Can you please share your YAML file?
Bansi:
spec:
containers:
- image: nginx
imagePullPolicy: Always
name: nginx-pod
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: default-token-zg9tf
readOnly: true
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
- image: busybox
name: sidecar
command: [“sh”,“-c”,“echo Hi I am sidecar container”]
dnsPolicy: ClusterFirst
enableServiceLinks: true
nodeName: node2
Bansi:
Hi…Anyone able to help with this question. Am kinda stuck. Thank you in Advance.
Sanjay Kumar:
@Bansi - I tested the yaml you provided and it’s working fine for me.
nginx container is in running state and sidecar container is terminated state with reason as completed.
If you run exec command on sidecar container it is showing the result as “Hi I am sidecar container”
Kubectl exec -it nginx -c sidecar — sh
Not sure if I am missing anything.
Bansi:
Issue am having is my sidecar container crashes rite away. (Yes logs does show the echo command)
Sanjay Kumar:
@Bansi - that is what happens when you use the busybox image for the side car container. That is what the purpose of that busybox, it will perform the action (echo command) and exits.
Try running the sleep command 4800 rather than echo command in the same sidecar container with busybox image or Try adding sidecar container with nginx image and run the same echo command and you will see both containers are running fine.
Bansi:
I did try nginx and had same issue