Question
Create a Pod named multi-container-playground in Namespace default with three containers named c1, c2 and c3. There should be a volume attached to that Pod and mounted into every container, but the volume shoudn't be persisted or shared with other Pods.
Container c1 should be of image nginx:1.17.6-alpine and have the name where its Pod is running available as environment variable MY_NODE_NAME.
Container c2 should be of image busybox:1.31.1 and write the output of the date command every second on the shared volume into the file date.log. You can use:
while true; do date >> /log/date.log; sleep 1; done
for this.tail -f /log/date.log
for this.kubectl run multi-container-playground --image=nginx:1.17.6-alpine --dry-run=client -o yaml
Adjust the manufest:
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: multi-container-playground
name: multi-container-playground
spec:
containers:
- image: nginx:1.17.6-alpine
name: c1
env:
- name: MY_NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
volumeMounts:
- mountPath: /log
name: log-volume
- image: busybox:1.31.1
name: c2
command: ["/bin/sh", "-c", "while true; do date >> /log/date.log; sleep 1; done"]
volumeMounts:
- mountPath: /log
name: log-volume
- image: busybox:1.31.1
name: c3
command: ["/bin/sh", "-c", "tail -f /log/date.log"]
volumeMounts:
- mountPath: /log
name: log-volume
volumes:
- name: log-volume
emptyDir: {}
Apply:
kubectl apply -f pod.yaml
Verify:
kubectl exec -it multi-container-playground -c c1 -- env
kubectl logs -f multi-container-playground -c c3