Question
A pod named example-pod is running on the cluster. Insert a sidecar container in it with following information:
image: busybox
name: sidec-container
command inside sidec-container would be:
/bin/sh -c while true; do echo $(date -u) 'Hi I am from sidec-container' >> /var/log/index.log; sleep 5; done
Also, mounts below volume as well:
name: var-log
mountPath: /var/log
Answer
Add the following to the pod manifest:
- image: busybox
command: ["/bin/sh"]
args: ["-c", "while true; do echo $(date -u) 'Hi I am from sidec-container' >> /var/log/index.log; sleep 5; done"]
name: sidec-container
volumeMounts:
- name: var-log
mountPath: /var/log
You can do this by editing the pod:
kubectl edit po example-pod
And replace the configuration when it is done:
kubectl replace --force -f /tmp/kubectl-edit-123456789.yaml