← All notes

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

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

Sources

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

Permanent ID: iil:note:xekw6t7v

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.},
}

Markdown

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.