Skip to main content
In this lesson we examine the common multi-container Pod design patterns in Kubernetes, when to use each, and how they behave. Understanding these patterns helps you design resilient, observable, and maintainable workloads. Key patterns covered:
  • Co-located containers (multiple concurrent containers in a Pod)
  • initContainers (sequential startup tasks)
  • Sidecar containers (long-running helpers that share a Pod)
Each pattern addresses a distinct operational need. Below you’ll find concise explanations, example Pod manifests, and a comparison table to help you choose the right pattern.

Co-located containers

Co-located containers are multiple containers defined together in the Pod’s containers array. They run concurrently for the lifetime of the Pod. Kubernetes does not guarantee a strict startup ordering between containers listed under containers; they are created and started, but ordering is non-deterministic. If a container terminates, Pod-level restartPolicy determines whether the container (and therefore the Pod) is restarted. When to use:
  • Two or more processes must run together in the same Pod and ordering is not important.
  • Processes communicate via localhost or share volumes for fast IPC.
Example Pod manifest (two co-located containers):

initContainers

initContainers are defined in the Pod spec under a separate initContainers field. Init containers run sequentially and each must exit successfully before Kubernetes starts any of the regular containers in containers. They are restarted on failure according to the Pod’s restartPolicy. Use init containers for deterministic initialization work such as database readiness checks, schema migrations, or provisioning files. When to use:
  • You need a guaranteed startup order for setup tasks.
  • Tasks must complete before the main application begins.
Example with two init containers that run in order before the main app:

Sidecar containers

A sidecar is an auxiliary container that runs alongside one or more main application containers in the same Pod. Sidecars are regular entries under the containers array, so they run concurrently with the app and typically remain active for the Pod’s lifetime. Typical sidecar use cases are logging, metrics/telemetry, proxying, and caching. Important characteristics:
  • Sidecars run concurrently with application containers (no guaranteed ordering).
  • Use coordination techniques (readiness probes, shared volumes, or explicit init containers) if you need deterministic sequencing between sidecare and app.
  • Sidecars share the same network namespace and can access the app via localhost.
A simple sidecar example (Filebeat forwarding container logs). Note that restartPolicy is a Pod-level field (default Always for Pods created by controllers):
Init containers provide deterministic startup order: they run in the order listed and must finish successfully before containers start. Containers under containers (including sidecars) run concurrently and do not have guaranteed startup ordering.
An infographic titled "Design Patterns" showing three container layouts. From left to right it shows "Co-located Containers", "Regular Init Containers", and "Sidecar Containers" represented by colored circles with gear icons to illustrate their relationships.

Real-world logging example

A common production use of sidecars is a log collector such as Filebeat running as a sidecar. The sidecar can:
  • Start alongside your app to capture initialization logs,
  • Forward logs to a backend such as Elasticsearch,
  • Continue running to capture termination logs if the application crashes.
This helps ensure diagnostics are captured for debugging and observability workflows.
A simple logging pipeline diagram: an app running in a pod uses a sidecar Filebeat to forward logs into Elasticsearch. Kibana then reads those logs from Elasticsearch and displays them to the user.

Comparison at a glance

Examples and best practices
  • If ordering matters for startup, prefer initContainers or implement coordination (readiness probes, shared files, in-Pod health checks).
  • Keep sidecars lightweight and focused (single responsibility).
  • Use shared volumes for log or config exchange between containers.
  • Prefer higher-level controllers (Deployments, StatefulSets) to manage Pod lifecycle in production.
Links and references

Summary

  • Use co-located containers when processes must run together but ordering is unimportant.
  • Use initContainers for deterministic, sequential setup tasks that must finish before the main app starts.
  • Use sidecars for long-lived helpers (logging, proxies, telemetry). Because sidecars run concurrently, coordinate startup and shutdown explicitly when ordering matters.

Watch Video

Practice Lab