Chapter 5 of 47 · Pods in depth, part 1

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

A Pod is the smallest deployable unit in Kubernetes. It contains one or more containers that are meant to run together.

Most of the time that is one container. For your micro-posts app:

Docker

Container

Kubernetes

Pod
└── micro-posts container

But 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:

A Pod with posts and a log agentA Pod holds the posts container and a log-agent container. They share the Pod network and a shared volume.PODpostscontainerlog-agentcontainerShared network: one IP, localhostShared volumes

These two containers have to:

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:

Parts of a two-container Pod POD posts-pod postscontainer · :4000 log-agentcontainer Shared network · IP 10.244.1.15 Shared volume · /var/log/app

posts container

The main application: Node.js running your posts service on port 4000. It writes its logs to /var/log/app.

The rule: no unrelated apps

Pod
└── posts

Pod
└── users

Pod
└── payments

One 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.

Test: would these containers still make sense on different machines? If yes, they belong in separate Pods. Only put containers together when one exists to serve the other.

Pod vs container

Container

Your application process, packaged with its runtime and filesystem.

Docker container
└── Node.js
    └── posts application

Pod

A Kubernetes object that provides an environment for one or more containers.

Pod
├── Network
├── Storage
└── Container
     └── Node.js application
The container runs the application. The Pod provides the environment the container runs in.

Recap

Quick check

Your posts app needs a Redis cache. Same Pod or separate Pod?
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.