Interview Prep/Real-World Interview/Write-a-Kubernetes-manifest tasks

Write a sidecar pattern: an app container plus a log-shipper reading a shared volume.

AdvancedHands-onWrite-a-Kubernetes-manifest tasks
Answer
spec:
  volumes:
    - name: logs
      emptyDir: {}
  initContainers:
    - name: log-shipper
      image: fluent/fluent-bit:3.1
      restartPolicy: Always          # native sidecar
      volumeMounts: [{ name: logs, mountPath: /var/log/app, readOnly: true }]
  containers:
    - name: app
      image: legacy-app:2.3
      volumeMounts: [{ name: logs, mountPath: /var/log/app }]

Key trick → An init container with restartPolicy: Always is a native sidecar (on by default since Kubernetes 1.29). It starts before the app and is stopped after it, which also fixes Jobs that never complete because the sidecar keeps running.

All Real-World Interview questions Roadmap: Interview readiness

More on Write-a-Kubernetes-manifest tasks