Pod storage, lifecycle, and why Pods are disposable
Where data lives in a Pod, the phases a Pod goes through, where Pods actually run, and the mindset that makes Kubernetes work: a Pod is not your server.
Storage
Containers are ephemeral. Anything written to a container's own filesystem can vanish when that container is replaced. To keep or share data, a Pod mounts volumes.
Later chapters go into Volumes, PersistentVolumes and PersistentVolumeClaims, which keep data even after the Pod is gone. For now: container filesystem = temporary, volume = shared, and can be made lasting.
Lifecycle
A Pod moves through a few phases. kubectl get pods shows them in the STATUS column, sometimes with a more specific reason. Pick a story and step through it:
- Kubernetes accepted the Pod. It is waiting for the scheduler to pick a node.
- A node was chosen. The image is being pulled and the container created. Still Pending.
- The container started. At least one container in the Pod is running, so the phase is Running.
- A one-off task, such as a database migration, is waiting to be scheduled.
- The migration script runs.
- The script exits with code 0. All containers finished successfully: Succeeded. This is typical for Jobs.
- A one-off task runs, with
restartPolicy: Never. - The script exits with code 1. A container finished and failed, and nothing restarts it: Failed.
- The node tries to pull
micro-postz, a typo. - The pull fails. The Pod stays Pending.
- Kubernetes keeps retrying, waiting longer each time. Still Pending; it will never run until you fix the image name.
- The Pod is running on node-2.
- node-2 stops reporting (power cut, network split). Kubernetes cannot tell what the Pod is doing: Unknown.
| Phase | Means |
|---|---|
Pending | Accepted, not running yet: waiting for a node, resources or the image |
Running | Bound to a node, at least one container running (or starting/restarting) |
Succeeded | All containers exited successfully and will not restart |
Failed | All containers exited, and at least one failed |
Unknown | The Pod's state cannot be read, usually because its node is unreachable |
Container crash vs Pod gone
These are different events, and it matters which one happened.
The kubelet on that node restarts the container inside the same Pod, following the Pod's restartPolicy (default Always). Same Pod name, same IP; the RESTARTS count goes up.
NAME READY STATUS RESTARTS AGE
posts-pod 1/1 Running 1 5m
A standalone Pod is gone for good. Nothing remembers it should exist, so nothing creates a new one. This is the case the simulator in chapter 3 showed.
$ kubectl get pods
No resources found in default namespace.
Pods are disposable
Don't think
"My Pod is my server." Something you name, log into, fix by hand and keep alive.
Think
"My Pod is disposable." posts-pod-abc can disappear and posts-pod-xyz takes over. The app keeps working.
So: keep no important data only in the container, never depend on a Pod's name or IP, and make your app start cleanly every time.
Pod vs Node
Do not confuse them. A Node is a machine. Pods run on Nodes. Click each level:
Cluster
All the machines Kubernetes manages, treated as one big computer.
Node
One machine, a VM or physical server, with CPU and memory. Many Pods run on each Node. If a Node dies, every Pod on it dies with it.
Pod
The unit Kubernetes places onto a Node. All containers of one Pod always run on the same Node.
Container
Your application, for example Node.js running the posts app, inside a Pod.
Cluster → Node → Pod → Container → Application
Why a Deployment manages Pods
A Pod by itself cannot say "always keep 3 of these running". A Deployment can:
spec:
replicas: 3
In fact a Deployment does this through a ReplicaSet, an object whose only job is keeping N identical Pods alive:
Deployment
└── ReplicaSet
├── Pod
├── Pod
└── Pod
This is why in real applications you will rarely create Pods by hand. Deployments are coming up next.
The seven Pod ideas
- A Pod is the smallest deployable Kubernetes unit.
- A Pod can contain several containers: an app plus sidecars.
- Containers in a Pod share networking and reach each other on
localhost. - A Pod gets an IP, but that IP is temporary.
- Containers in a Pod can share volumes.
- Pods are disposable. Do not depend on their identity or IP.
- A Deployment (through a ReplicaSet) normally manages Pods.
Pod lifecycle: common questions
What does Pending mean for a Kubernetes Pod?
The Pod was accepted but is not running yet: it is waiting for a node, for resources, or for its image to be pulled.