*is that pod can patch the sidecar without deleting the main container?* Add a s . . .

Yuvaraj K:
is that pod can patch the sidecar without deleting the main container?
Add a sidecar container named sidecar, using the busybox Image, to the existing Pod legacy-app. The new sidecar container has to run the following command:

/bin/sh -c tail -n+1 -f /var/log/legacy-app.log
Use a Volume, mounted at /var/log, to make the log file legacy-app.log available to the sidecar container.

Mohamed Ayman:
The smallest unit in k8s is a pod not a container. So, if u have more than one container in the pod and add a change like ur command, u should recreate the pod again.

Yuvaraj K:
@Mohamed Ayman but in CKA exam the given same questions like this… Logging and monitor.

Mohamed Ayman:
Can u post this question?

Yuvaraj K:
@Mohamed Ayman Add a sidecar container named sidecar, using the busybox Image, to the existing Pod legacy-app. The new sidecar container has to run the following command:
/bin/sh -c tail -n+1 -f /var/log/legacy-app.log
Use a Volume, mounted at /var/log, to make the log file legacy-app.log available to the sidecar container.

Note: Do not alter the application container and verify the logs are written properly to the file.

Basavraj Nilkanthe:
@Yuvaraj K This is simple right. They are asking you to not modify application container… it means you can get yaml definition of application container and then add side car container in pod.spec.containers as second object after your application container as per above requirement… Then kill application pod and recreate it with new yaml file

Basavraj Nilkanthe:
There is no way in kubernetes you can add another container to running existing pod

Basavraj Nilkanthe:
In fact running pod will not allow you to modify every fiend of it apart of few field like image name

Basavraj Nilkanthe:
Field*

Pradeep:
I agree with it too

Pradeep:
We cannot add a new container to the existing/running container

Arun SD:
I got similar question in the exam, yes we have to delete the running pod and recreate it. But, i had issue with logs not getting generated. I used /var/log volume mounts as specified in the question but didn’t work. Do we need to specify the volume section in the pod spec as emptyDir{}?

Basavraj Nilkanthe:
It doesn’t matters actually. Either you can use hostPath type volume or emptyDir. Ultimate goal of running two containers in same pod is to get benefits of share network space and volume space