DevOpsLesson
DevOpsLesson

Free, comprehensive DevOps tutorials and learning roadmaps. Master Docker, Kubernetes, CI/CD, and more.

Stay Updated

Get notified about new tutorials and features.

Tutorials

  • What is DevOps?
  • Docker Tutorial
  • Terraform Tutorial
  • CI/CD Pipeline
  • All Tutorials

Roadmaps

  • DevOps Engineer
  • Cloud Engineer
  • SRE Path
  • All Roadmaps

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service

© 2026 DevOpsLesson. All rights reserved.

DOCKERKUBERNETESTERRAFORMAWSCI/CDLINUXGITDEVOPS ROADMAPCLOUD ROADMAPSRE ROADMAPGIT CHEATSHEETDOCKER CHEATSHEETK8S CHEATSHEETTF CHEATSHEETLINUX CHEATSHEETDOCKERFILE LINTERYAML VALIDATORCRON PARSERREGEX TESTER

Kubernetes Tutorial

Introduction to Kubernetes
Kubernetes Architecture
Installing Kubernetes
kubectl Basics
Kubernetes Pods
Kubernetes Deployments
Kubernetes Services
ConfigMaps and Secrets
Kubernetes Storage
Kubernetes Namespaces
Kubernetes Resource Management
Helm for Kubernetes
Kubernetes Monitoring

Multi-container Pods

PreviousPrev
Next

Learn when multiple containers should share a pod, including sidecar, ambassador, adapter, and init container patterns.

Why Multiple Containers in One Pod?

Most pods run a single main container. But sometimes two or more containers need to share storage, localhost networking, or lifecycle closely enough that putting them in one pod makes sense.

Common Patterns

Sidecar Pattern

A sidecar supports the main app, such as shipping logs, proxying traffic, or refreshing configuration.

Ambassador Pattern

An ambassador acts like a local proxy for external services. The main app talks to localhost, and the ambassador forwards requests outward.

Adapter Pattern

An adapter transforms output from the main app into a format expected by another system.

Init Containers

Init containers run before main containers start. They are perfect for setup steps such as waiting for dependencies or preparing files.

Shared Volumes

Containers in a pod can mount the same volume. That is a common way for an init container or sidecar to hand off data to the main app.

Full Example: App + Sidecar + Init Container

apiVersion: v1
kind: Pod
metadata:
  name: app-with-sidecar
  labels:
    app: demo
spec:
  volumes:
    - name: shared-data
      emptyDir: {}
  initContainers:
    - name: init-content
      image: busybox:1.36
      command: ['sh', '-c', 'echo Ready > /work/status.txt']
      volumeMounts:
        - name: shared-data
          mountPath: /work
  containers:
    - name: app
      image: nginx:1.27
      volumeMounts:
        - name: shared-data
          mountPath: /usr/share/nginx/html
    - name: sidecar
      image: busybox:1.36
      command: ['sh', '-c', 'while true; do date >> /work/sidecar.log; sleep 30; done']
      volumeMounts:
        - name: shared-data
          mountPath: /work

Why This Example Works

  • The init container writes a file before the app starts.
  • The app serves data from the shared volume.
  • The sidecar keeps writing log-like information into the same volume.

When Not to Use Multi-container Pods

Do not put unrelated services into one pod just to save YAML. If the containers scale differently or should be managed independently, they probably belong in separate pods.

A pod should represent one tightly coupled unit, not an entire application stack crammed together.

Exercise

Init Container Timing

When do init containers run?

Exercise

Sidecar Purpose

What is a common reason to add a sidecar container?

PreviousPrev
Next

Continue Learning

Kubernetes Pods

Understand what a Pod is, why Kubernetes schedules pods instead of raw containers, and how containers share networking and storage inside a pod.

16 min·Easy

Kubernetes Pod Manifest

Learn the anatomy of Pod YAML and understand the purpose of apiVersion, kind, metadata, labels, annotations, and the spec section.

20 min·Easy

Kubernetes Pod Lifecycle

Understand pod phases, container states, restart policies, and what Kubernetes does when pods or nodes fail.

20 min·Easy

Explore Related Topics

Do

Docker Tutorials

Build the containers Kubernetes orchestrates

Te

Terraform Tutorials

Provision Kubernetes clusters as code

Try the Tool

YAML Validator

Validate Kubernetes manifests and any YAML files instantly.

On This Page

Why Multiple Containers in One Pod?Common PatternsSidecar PatternAmbassador PatternAdapter PatternInit ContainersShared VolumesFull Example: App + Sidecar + Init ContainerWhy This Example WorksWhen Not to Use Multi-container Pods