Pods: the most important word
If you remember only one Kubernetes word for now, make it Pod. Kubernetes does not manage containers directly. It manages Pods, and Pods hold your containers.
What a Pod is
A Pod is the smallest thing Kubernetes can run. Usually it holds exactly one application container.
| What you run | |
|---|---|
| Docker | Container |
| Kubernetes | Pod → Container |
Inside a Pod
Why the extra wrapper? Because the Pod is where Kubernetes attaches the things a container needs to live in a cluster. Click each part.
Container
Your application: the same container you ran with Docker, started from the same image. The Pod wraps it; it does not change it.
Network
Every Pod gets its own IP address inside the cluster. All containers in the Pod share it, so they talk to each other on localhost. When the Pod is replaced, the new one gets a different IP.
Storage
A Pod can mount volumes, folders that its containers can read and write. Containers in the same Pod can share a volume, for example one writes logs and another ships them.
Lifecycle
A Pod moves through phases: Pending (being scheduled, image downloading), Running, then Succeeded or Failed. Kubernetes can restart a crashed container inside a Pod, but a Pod that is deleted is gone for good.
So a Pod gives your container networking, storage, a lifecycle, and a way to group containers that must run side by side.
One container or several?
This is what you will write 95% of the time: 1 Pod, 1 container. Need more copies? Make more Pods, not more containers in one Pod.
A Pod can hold several containers when they are tightly coupled: a helper that ships logs or refreshes certificates for the main app. They start together, share the IP and can share files.
Your micro-posts as a Pod
Earlier you ran the posts service with Docker:
$ docker run -d \
--name posts-container \
-p 4000:4000 \
micro-posts
Docker gives you
Container
└── micro-postsKubernetes gives you
Pod
└── micro-posts containerSame image, same app. Kubernetes simply manages the Pod around it. (You will write the YAML for this in a later chapter; for now the picture is enough.)
Why not create Pods yourself?
Suppose you want 3 copies of posts, so you create 3 Pods by hand. Now crash one:
It stays dead. A Pod on its own has no manager: nobody remembers that you wanted 3. You would have to notice and create another one yourself. Not good.
Recap
- A Pod is the smallest unit Kubernetes runs. It wraps one (usually) or more containers.
- The Pod gives its containers one IP address, shared storage and a lifecycle.
- Containers in one Pod share
localhost. - Pods are temporary: a replacement Pod has a new name and a new IP.
- A bare Pod is not recreated when it dies, so we let a Deployment manage Pods.
Quick check
Show answer
4 Pods with 1 container each. Copies of an app go in separate Pods so they can run on different machines and fail independently. Multiple containers in one Pod are for a main app plus helpers.
Kubernetes Pods: common questions
What is the difference between a Pod and a container?
A container is your running application. A Pod is the Kubernetes wrapper around one or more containers that gives them a shared IP address, storage and a lifecycle.