Text Box
apiVersion: v1kind: Podmetadata: name: two-containersspec: volumes: - name: shared-data emptyDir: {} containers: - name: first image: nginx volumeMounts: - name: shared-data mountPath: /usr/share/nginx/html - name: second image: debian volumeMounts: - name: shared-data mountPath: /pod-data command: ["/bin/sh"] args: - "-c" - > while true; do date >> /pod-data/index.html; echo Hello from the second container >> /pod-data/index.html; sleep 1; done
Test that first container is able to get file content change from second container
root@ubuntu-232:~/deepak/logging-app# kubectl exec -it two-containers -c first bash
root@two-containers:/# tail -f /usr/share/nginx/html/index.html
Sun Mar 3 05:14:44 UTC 2019
Hello from the second container
Sun Mar 3 05:14:45 UTC 2019
Hello from the second container
Sun Mar 3 05:14:46 UTC 2019
Hello from the second container
Sun Mar 3 05:14:47 UTC 2019
Hello from the second container
Sun Mar 3 05:14:48 UTC 2019
Hello from the second container
Sun Mar 3 05:14:49 UTC 2019
Hello from the second container
^C
root@two-containers:/# tail -f /usr/share/nginx/html/index.html
Sun Mar 3 05:14:52 UTC 2019
Hello from the second container
Sun Mar 3 05:14:53 UTC 2019
Hello from the second container
Sun Mar 3 05:14:54 UTC 2019
Hello from the second container
Sun Mar 3 05:14:55 UTC 2019
Hello from the second container
Sun Mar 3 05:14:56 UTC 2019
Hello from the second container
Sun Mar 3 05:14:57 UTC 2019
Hello from the second container
https://www.stratoscale.com/blog/kubernetes/kubernetes-how-to-share-disk-storage-between-containers-in-a-pod/