Kubernetes native sidecar containers - init containers with restartPolicy Always
Answer: Define the sidecar under initContainers with restartPolicy: Always. Such containers keep running for the whole life of the Pod.
Example
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
spec:
replicas: 1
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: myapp
image: alpine:latest
command: ['sh', '-c', 'while true; do echo "logging" >> /opt/logs.txt; sleep 1; done']
volumeMounts:
- name: data
mountPath: /opt
initContainers:
- name: logshipper
image: alpine:latest
restartPolicy: Always
command: ['sh', '-c', 'tail -F /opt/logs.txt']
volumeMounts:
- name: data
mountPath: /opt
volumes:
- name: data
emptyDir: {}
What sidecars are for
Sidecar containers run along with the main application container in the same Pod. They add services such as logging, monitoring, security or data synchronization without altering the application code.
Lifecycle rules
- Sidecars keep the ordering guarantees of init containers. Once a sidecar is
started, the kubelet starts the next init container in.spec.initContainers. - A
readinessProbeon a sidecar is used to determine thereadystate of the Pod. - On termination, the kubelet postpones terminating sidecar containers until the main container has fully stopped, then shuts them down in the opposite order of their appearance in the spec.
- Non-zero exit codes from sidecars are normal on Pod termination and should be generally ignored by external tooling.
Differences from init containers
Unlike plain init containers, sidecars run concurrently with the main container, support probes to control their lifecycle, and can be started and stopped independently. Like init containers, they always share the same network as the app containers.
See also
Claims
- id: C1 claim: restartPolicy Always on an init container makes it a sidecar. source: S1 evidence: "Setting restartPolicy: Always makes this a sidecar container."
- id: C2 claim: Sidecars stop after the main container in reverse order. source: S2 evidence: "shut down in the opposite order of their appearance in the Pod specification"
- id: C3 claim: Sidecars support probes, unlike init containers. source: S2 evidence: "sidecar containers support [probes]"
Sources
- [S1] Sidecar Containers. Kubernetes docs. https://kubernetes.io/docs/concepts/workloads/pods/sidecar-containers/ . License: CC-BY-4.0. Accessed 2026-11-18.
- [S2] sidecar-containers.md (source page). kubernetes/website (GitHub). https://github.com/kubernetes/website/blob/main/content/en/docs/concepts/workloads/pods/sidecar-containers.md . License: CC-BY-4.0. Accessed 2026-11-18.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Kubernetes docs, Sidecar Containers; kubernetes/website (GitHub), sidecar-containers.md (source page). CC-BY-4.0 (https://raw.githubusercontent.com/kubernetes/website/main/LICENSE). Copyright The Kubernetes Authors. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Kubernetes docs, Sidecar Containers; kubernetes/website (GitHub), sidecar-containers.md (source page). CC-BY-4.0 (https://raw.githubusercontent.com/kubernetes/website/main/LICENSE). Copyright The Kubernetes Authors.
Cite this
iinventedlight. 2026. "Kubernetes native sidecar containers - init containers with restartPolicy Always." iinventedlight Library, iil:note:xekw6t7v, version of 2026-11-18. https://iinventedlight.com/library/notes/kubernetes-sidecar-containers/. License: CC-BY-4.0.
@misc{iil_note_xekw6t7v,
author = {{iinventedlight}},
title = {{Kubernetes native sidecar containers - init containers with restartPolicy Always}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-18},
url = {https://iinventedlight.com/library/notes/kubernetes-sidecar-containers/},
note = {Permanent ID iil:note:xekw6t7v. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/kubernetes-sidecar-containers.md.