What a Pod really is
Chapter 3 gave you the picture. Now we go deeper: why Kubernetes invented Pods at all, when a Pod holds more than one container, and how a Pod differs from a container.
The definition
Most of the time that is one container. For your micro-posts app:
Docker
ContainerKubernetes
Pod
└── micro-posts containerBut do not think of a Pod as "another name for a container". A Pod is a shared environment around its containers. That difference is what this chapter is about.
Why Pods exist
If almost every Pod has one container, why not just schedule containers? Because sometimes a main application needs a helper that must stay extremely close to it. A log agent that reads the app's log files, for example:
These two containers have to:
- run together
- share the same network
- be able to share storage
- be scheduled together, on the same machine
- have the same lifecycle: start together, stop together
A container on its own cannot express "these belong together". A Pod can. So Kubernetes schedules and manages Pods, and the containers inside a Pod always land on the same machine.
Several containers in one Pod
Click the parts of this Pod to see what is shared:
posts container
The main application: Node.js running your posts service on port 4000. It writes its logs to /var/log/app.
log-agent container
A helper, often called a sidecar. It reads the log files from the shared volume and ships them to a logging system. It has no reason to exist without posts, so it lives in the same Pod.
Shared network
Both containers use the same IP address and the same ports. The agent can call posts at localhost:4000. Chapter 6 is all about this.
Shared volume
A folder mounted into both containers. posts writes files, log-agent reads them. Chapter 7 covers storage.
The rule: no unrelated apps
Pod
└── posts
Pod
└── users
Pod
└── paymentsOne app per Pod. Each can be scaled on its own (10 posts Pods, 2 payments Pods), updated on its own, and can crash without taking the others down.
Pod
├── posts
├── users
├── payments
└── commentsUnrelated apps in one Pod. Want more posts? You must copy users, payments and comments too. Update payments? The whole Pod restarts. They also fight over ports and must all fit on one machine.
Pod vs container
Container
Your application process, packaged with its runtime and filesystem.
Docker container
└── Node.js
└── posts applicationPod
A Kubernetes object that provides an environment for one or more containers.
Pod
├── Network
├── Storage
└── Container
└── Node.js applicationRecap
- A Pod is the smallest deployable unit: one or more containers meant to run together.
- Pods exist so tightly coupled containers can share network, storage, scheduling and lifecycle.
- A helper container in the same Pod is called a sidecar.
- Unrelated applications go in separate Pods.
Quick check
Show answer
Separate. Redis is a service in its own right: other apps may use it, it scales differently, and you do not want a new posts version to restart your cache. A sidecar is something like a log shipper or proxy that only exists for its main container.
Kubernetes Pods in depth: common questions
When should a Pod have more than one container?
Only when the containers are tightly coupled, like an app and a log-shipping sidecar that must share network, storage and lifecycle. Unrelated apps belong in separate Pods.