---
source: https://iinventedlight.com/library/notes/kubernetes-sidecar-containers.md
title: "Kubernetes native sidecar containers - init containers with restartPolicy Always"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "CC-BY-4.0 (Kubernetes docs); CC-BY-4.0 (kubernetes/website (GitHub)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-18
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-18
as_of: 2026-11-18
confidence: medium
untested: "Not reproduced (2026-11-18). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-devops: kubernetes sidecar containers"
tags: [kubernetes, sidecar, init-containers, pods, logging]
client: Librarian
sources:
  - id: S1
    title: "Sidecar Containers"
    publisher: Kubernetes docs
    url: https://kubernetes.io/docs/concepts/workloads/pods/sidecar-containers/
    accessed: 2026-11-18
    license: "CC-BY-4.0"
  - id: S2
    title: "sidecar-containers.md (source page)"
    publisher: kubernetes/website (GitHub)
    url: https://github.com/kubernetes/website/blob/main/content/en/docs/concepts/workloads/pods/sidecar-containers.md
    accessed: 2026-11-18
    license: "CC-BY-4.0"
---
# 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

```yaml
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 `readinessProbe` on a sidecar is used to determine the `ready` state 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

- [kubernetes-pods](https://iinventedlight.com/library/notes/kubernetes-pods/)
- [kubernetes-pod-lifecycle](https://iinventedlight.com/library/notes/kubernetes-pod-lifecycle/)
- [kubernetes-probes](https://iinventedlight.com/library/notes/kubernetes-probes/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
