Skip to content
Cloudintermediate

What is a Pod in Kubernetes?

Updated Nov 30, 20263 min readBased on official documentation
What is a Pod in Kubernetes?

In short

A Pod is the smallest unit you can create and manage in Kubernetes. It is a group of one or more containers that share network and storage resources and run together on the same node. Most Pods hold a single container.

What a Pod is

Kubernetes does not run containers directly. It wraps them in a Pod, which is the smallest object you can create and manage. Think of a Pod as a small logical host for your application. The name is borrowed from a pod of whales or a pea pod, which hold a group of things together.

A Pod holds one or more application containers. Those containers are always placed on the same machine, start together and share a context. They share network resources, so they can reach each other on localhost, and they can share storage volumes. The shared context is built from the same Linux features that isolate a single container, such as namespaces and cgroups.

A Pod can also include init containers, which run during startup before the main containers begin. You can also add ephemeral containers to a running Pod to debug it.

How Pods are used

There are two common patterns. The first is one container per Pod. This is by far the most common case. You can think of the Pod as a wrapper around a single container, and Kubernetes manages the Pod rather than the container itself.

The second pattern is a Pod with several containers that work closely together and need to share resources. Examples include a main application with a helper that ships logs. This pattern is more advanced. Use it only when the containers are tightly coupled. If you only need more copies for resilience or capacity, you do not need extra containers. You need more Pods.

Here is a minimal Pod that runs one nginx container:

apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  containers:
  - name: nginx
    image: nginx:1.14.2
    ports:
    - containerPort: 80

You can create it with kubectl apply using the example file from the documentation. Note that in practice you rarely create Pods this way.

Pods are disposable

Pods are designed to be ephemeral. When a Pod is created, the scheduler places it on a node in the cluster. It stays there until it finishes, is deleted, is evicted for lack of resources, or the node fails. A Pod does not heal itself. If it dies, something else must replace it.

That is why you usually use a workload resource instead of a bare Pod. A Deployment, StatefulSet or DaemonSet creates Pods from a template and a controller keeps the right number running. If a node fails, the controller notices the lost Pods and creates replacements, which the scheduler places on healthy nodes. To scale an app, you run several Pods, one per instance, and the controller manages them as a group.

Pod templates and updates

Workload resources hold a pod template. It is a specification the controller uses to build each Pod. Changing the template does not change Pods that already exist. The controller creates new Pods from the updated template and then replaces the old ones.

Direct edits to a running Pod are limited. Most metadata, such as name, namespace and uid, cannot change. Only a few fields can be updated in place, such as container images and some timing settings. For most changes, the right move is to let the controller replace the Pod.

Common mistakes

A common mistake is treating a Pod as a long-lived server. Pods can be removed at any time, so store important data outside the Pod. Another mistake is putting several unrelated containers in one Pod to save effort. This couples their lifecycles and makes them harder to scale and update separately. A third mistake is confusing a container restart with a Pod restart. A container inside a Pod can restart, but the Pod stays the same until it is deleted.

If you are new to containers, it helps to first learn what a container is and how an image runs. Then the Pod becomes the next layer up.

FAQ

Is a Pod the same as a container?

No. A Pod is a wrapper that holds one or more containers. It adds shared networking, shared storage and a specification for how the containers run. Most Pods contain just one container.

Why does Kubernetes use Pods instead of containers directly?

Pods give Kubernetes a single unit to schedule, network and manage. Containers that must run together can share an IP address and volumes inside one Pod.

Should I create Pods by hand?

Usually not. A workload resource such as a Deployment or Job creates and manages Pods for you. It replaces them if they fail, which a bare Pod does not do.

Can I change a running Pod?

Only a few fields can be changed in place, such as some container images and timing settings. For other changes, update the pod template in the workload resource so new Pods are created.

Sources

This page is based on the official documentation below. Read it for full detail.

Kubernetes Pod — official documentation ↗

Kubernetes Pod in the news

blozhikDeveloper news from across the web, explained. Every story links to its original sources.