liveBook · Manning

Native sidecar

As explained in Kubernetes in Action, Second Edition

A native sidecar is a Kubernetes container configured as an init container with restartPolicy set to Always, giving it sidecar lifecycle ordering and restart behavior.

A native sidecar is an init container whose restartPolicy is set to Always. Kubernetes starts it during pod initialization, but does not wait for it to terminate; instead, later init containers and regular containers start while the sidecar keeps running. This lets the sidecar provide a service throughout the pod’s lifetime, including to later init containers. section 5.5.4

Traffic meter alongside an application

A pod can place a traffic-meter container in initContainers with restartPolicy: Always, between ordinary init containers. The traffic meter starts before the application, remains available while the pod runs, and can be inspected with kubectl logs -f <pod> -c traffic-meter. A running pod reports the native sidecar among its ready containers. section 5.5.4

Native sidecars differ from ordinary init and regular containers in three practical ways:

  • Kubernetes restarts the sidecar whenever it terminates, matching its role as a continuously available service. section 5.5.4
  • The pod starts later init containers after the native sidecar has fully started, rather than waiting for it to finish. section 6.4.4
  • During shutdown, Kubernetes terminates regular containers first and native sidecars afterward, in reverse order of their initContainers entries. section 6.4.4
  • Jobs that need a sidecar that never completes should use this pattern so the sidecar does not prevent the task from finishing. section 18.3

How Kubernetes in Action, Second Edition covers it

How deep it goes
Defines configuration, startup, restart, and shutdown ordering, but stops short of implementation internals.
Examples
Uses a traffic meter, network proxy, connectivity checker, application pod, manifest, readiness output, and streamed logs.
What it assumes
Assumes basic pods and containers while teaching how init-container ordering differs from long-running sidecar behavior.
What you can do after
Build it from scratch by placing an init container with restartPolicy Always before the containers it supports.
How it connects
Connects init containers, sidecar containers, pod lifecycle, Jobs, and CronJobs.

Also explained in

Compare how 2 books explain native sidecar →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes in Action, Second Edition. The section links point to the parts of the book it draws on.