---
apiVersion: v1
kind: Pod
metadata:
  name: sidecar
  labels:
    run: sidecar
spec:
  volumes:
  - name: sharedvolume
    emptyDir: {}
  containers:
  # Main container to read data from shared volume
  - name: mainapp
    image: nginx:latest
    ports:
    - name: nginx-webport
      containerPort: 80
    volumeMounts:
    - name: sharedvolume
      mountPath: /usr/share/nginx/html
  # Sidecar container to write data to shared volume
  - name: sidecar
    image: busybox:latest
    volumeMounts:
    - name: sharedvolume
      mountPath: /tmp
    command:
    - /bin/sh
    - -c
    - 'while true; do date >> /tmp/index.html; sleep 10; done'

# kubectl exec -it sidecar -c sidecar -- /bin/sh -c 'cat /tmp/index.html'
# kubectl exec -it sidecar -c mainapp -- /bin/sh -c 'tail -n 10 /usr/share/nginx/html/index.html'
