kind: Pod
apiVersion: v1
metadata:
  name: pod-with-sidecar 
spec:
  # Create a volume called 'shared-logs' that the 
  # app and sidecar share.
  volumes:
    - name: shared-logs
      emptyDir: {}
  # In the sidecar pattern, there is a main application
  # container and a sidecar container. 
  containers:
  # Main application container
  - name: app-container
    # Simple application: write the current date every 5s. 
    image: alpine
    command: ["/bin/sh"]
    args: ["-c", "while true; do date >> /var/log/app.txt; sleep 5;done"]
    # Mount the pod's shared log file into the app container.
    volumeMounts:
    - name: shared-logs
      mountPath: /var/log

  # Sidecar container
  - name: sidecar-container
    # Simple sidecar: display log files using nginx. 
    image: nginx:alpine
    ports:
    - containerPort: 80
    # Mount the pod's shared log file into the sidecar
    # container. In this case, nginx will serve the files
    # in this directory. 
    volumeMounts:
    - name: shared-logs
      mountPath: /usr/share/nginx/html

