Pod Overview

What is a Pod? The word “Pod” refers to a seed pod — a very fitting name. Inside a pod, there are usually one or more seeds, just like the containers running inside a Kubernetes Pod.

What is a Pod?

A Pod is the basic execution unit in Kubernetes — the smallest and simplest unit that can be created and deployed.

What is inside a Pod?

  • One or more application containers.
  • Storage resources.
  • Network resources.
  • Runtime policy configuration for the application containers.

Manifest Example

Here is a simple Pod manifest that runs an nginx container inside the Pod.

1
2
3
4
5
6
7
8
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: nginx
image: nginx

Relationships Between Containers in a Pod

The following Pod manifest contains 3 containers. You can deploy this Pod to Kubernetes using kubectl apply.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: nginx
image: nginx
volumeMounts:
- name: logs
mountPath: /var/log/nginx
- name: validate-network
image: busybox
command: ['sh', '-c', 'telnet localhost 80 && echo nginx works && sleep 3600']
- name: validate-volumes
image: busybox
command: ['sh', '-c', 'tail -f /logs/*.log']
volumeMounts:
- name: logs
mountPath: /logs
volumes:
- name: logs
emptyDir: {}

1. Shared Network IP Address and Ports

Containers within a Pod can communicate with each other using localhost. Multiple containers in the same Pod cannot bind to the same port.

In the example above, the nginx container starts and by default listens on port 80. The validate-network container runs telnet localhost 80, with the result shown below.

validate-network

2. Shared Storage Resources

A Pod can specify a set of shared storage volumes. All containers in the Pod can access these shared volumes, allowing them to share data with each other.

In the example above, the nginx and validate-volumes containers both use the shared volume named logs. The nginx container writes its logs to this volume, and the validate-volumes container reads those logs back out.

validate-volumes

3. Tightly Coupled

How to Use Pods?

Pods are designed to be relatively ephemeral (non-persistent), disposable entities. Therefore, it is not recommended to create Pods directly in Kubernetes. For example, if a Pod is created and then evicted due to insufficient resources, or if the node running the Pod goes down, the Pod cannot recover on its own.

Kubernetes provides a higher-level abstraction called a Controller that is responsible for managing Pods — for example, Deployments, ReplicaSets, and DaemonSets. These Controllers manage Pods using Pod templates. Below is an example of a ReplicaSet.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: rs-nginx
labels:
app: nginx
tier: frontend
spec:
replicas: 3
selector:
matchLabels:
tier: frontend
template:
metadata:
labels:
tier: frontend
spec:
containers:
- name: nginx
image: nginx