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.
More on Write-a-Kubernetes-manifest tasks
Write a Deployment and Service for an Nginx app with 3 replicas, resources and probes.BeginnerAdd an HPA that scales the Deployment between 3 and 15 pods at 70% CPU.BeginnerFix this broken Deployment YAML.BeginnerWrite a ConfigMap and Secret and inject them as environment variables and as a mounted file.IntermediateWrite an Ingress that routes `/api` to the api service and `/` to the web service with TLS.IntermediateWrite a pod spec with a hardened securityContext.Intermediate