Kubernetes Application Container Usage
Kubernetes Application Container Usage manages containers in Kubernetes for scalable, reliable, and efficient application deployment.
Kubernetes Application Container Usage is the design consideration around how many containers to place in a Pod's main containers list and what role each should play, covering the single-container norm most workloads follow, the established multi-container patterns that justify departing from it, and the behavioral differences between how main containers and init containers are started and supervised.
The Single-Container Default
Why Most Pods Contain One Container
The overwhelming majority of Pods declare exactly one container, reflecting that a Pod's shared lifecycle, shared networking, and shared scheduling are usually meant to scope a single logical application process, and introducing additional containers without a clear justification adds operational complexity — more images to build and version, more resource accounting to reason about — without a corresponding benefit.
When One Container Is the Wrong Default
Multi-container Pods become justified specifically when a genuinely separate process needs to share the Pod's network namespace, storage, or lifecycle with the main application closely enough that running it as an independent Pod (communicating over the network instead) would lose something essential — typically tight coupling to the exact lifecycle or localhost-level access the shared Pod boundary provides.
Established Multi-Container Patterns
The Sidecar Pattern
A sidecar container runs alongside the main application container for the Pod's entire life, extending or supporting it — a log-shipping agent tailing the application's log files, a metrics exporter translating application-specific metrics into a standard format, or a service mesh proxy intercepting network traffic — without the main application needing to implement that supporting functionality itself.
The Ambassador Pattern
An ambassador container acts as a local proxy the main application communicates with over localhost, which then handles the complexity of connecting to an external or more complex backend service, letting the main application remain unaware of service discovery, retries, or connection pooling logic the ambassador handles on its behalf.
The Adapter Pattern
An adapter container transforms the main application's output into a standardized format some external system expects — normalizing a legacy application's non-standard log format into a structure a cluster-wide logging pipeline can consume — without requiring changes to the main application itself.
Startup and Supervision Differences From Init Containers
No Guaranteed Ordering Among Main Containers
Unlike init containers, which start strictly in sequence, containers within the main containers list have no guaranteed startup ordering relative to each other; the container runtime may start them concurrently, meaning a sidecar cannot assume the main application container has already started (or vice versa) purely based on list position, and any genuine ordering dependency between main containers must be handled through application-level readiness checks rather than relied upon implicitly.
Independent Restart Behavior
Each main container is restarted independently according to the Pod's restart policy when it exits, meaning one container crashing and restarting does not, by itself, restart its sibling containers in the same Pod — a design that allows a sidecar's transient failure to be recovered without disrupting the main application container's own continuous operation, and vice versa.
Resource and Failure Accounting Across Multiple Containers
Aggregate Resource Requests
A Pod's overall resource requests and limits are computed as the sum across every container it contains (main and init containers, with init container resource needs handled according to their own sequential, non-overlapping consumption pattern), meaning adding a sidecar directly increases the Pod's total scheduling footprint, a cost that should be weighed against the sidecar's benefit when deciding whether a multi-container design is warranted.
Readiness as an Aggregate Judgment
A Pod's overall Ready condition depends on every main container passing its own readiness probe, meaning a struggling sidecar can hold an otherwise healthy main application container out of Service traffic if the Pod's readiness is computed strictly across all containers, a consideration that shapes how carefully sidecar health-check behavior needs to be designed relative to the main application's own.