CKAD field manual
k8s sidecar YAML example
Same Pod, extra container. Init must finish. A sidecar stays up and shares volumes.
apiVersion: v1
kind: Pod
metadata:
name: web
spec:
initContainers:
- name: fetch
image: busybox:1.36
command: ["sh", "-c", "echo hi > /data/index.html"]
volumeMounts:
- name: html
mountPath: /data
containers:
- name: web
image: nginx:1.27
volumeMounts:
- name: html
mountPath: /usr/share/nginx/html
volumes:
- name: html
emptyDir: {}
spec:
containers:
- name: app
image: nginx:1.27
volumeMounts:
- name: logs
mountPath: /var/log/nginx
- name: shipper
image: busybox:1.36
command: ["sh", "-c", "tail -F /var/log/nginx/access.log"]
volumeMounts:
- name: logs
mountPath: /var/log/nginx
volumes:
- name: logs
emptyDir: {}
spec:
initContainers:
- name: shipper
image: busybox:1.36
restartPolicy: Always
command: ["sh", "-c", "tail -F /var/log/app.log"]
volumeMounts:
- name: logs
mountPath: /var/log
containers:
- name: app
image: nginx:1.27
volumeMounts:
- name: logs
mountPath: /var/log
volumes:
- name: logs
emptyDir: {}
Fields
- initContainers
- Run to completion, in order, before app containers. A failing init blocks the Pod.
- restartPolicy
- Always on an initContainer = native sidecar. It stays up with the app.
- emptyDir
- How the containers share files. Same volume name on every mount.
Watch
- Init containers run to completion, in order, before app containers start. A failing init blocks the Pod.
- Classic sidecar = second item in containers[]. Native sidecar = initContainers[] + restartPolicy: Always.
- Share files with emptyDir. Same volume name in every volumeMounts.
Official docs Init containers Sidecar containers