kubernetes-training

Example

Application with a Logging Sidecar

 apiVersion: v1
 kind: Pod
 metadata:
 name: app-with-logging-sidecar
 spec:
   volumes:
     name: shared-logs
     emptyDir: {}
   initContainers:
   - name: log-shipper
     image: alpine:latest
     command: ['sh', '-c', 'tail -F /opt/logs.txt']
     volumeMounts:
     - name: shared-logs
       mountPath: /opt
     restartPolicy: Always
   containers:
  - name: main-app
    image: alpine:latest
    command: ['sh', '-c', 'while true; do echo "logging" >> /opt/logs.txt; sleep 1; done']
   volumeMounts:
   - name: shared-logs
   mountPath: /opt

Co-located Containers