Pods are the atomic units of deployment in Kubernetes.
A Pod is a special container that defines one or more containers that can run inside of it.
Containers, running inside a Pod, share the Pod's resources: IP address, ports, hostname, volumes, ...
They can communicate with each other using localhost interface.
To share resources, containers leverage Linux features: Control groups (cgroups) and kernel namespaces.
Control groups (cgroups) allow containers to use only their assigned resources: cpu, ram, and iops.
Kernel namespaces (Network, UTS, IPC, ...) allow containers to have their own unique and limited view of the system resources (filesystem, network interfaces, disk, ...):
It's recommended to have only one container inside a Pod.
But there might be use cases where it will be acceptable to have more than one container running inside a Pod.
For example, it's possible to co-locate multiple containers that provide services that are tightly coupled
and/or they need to share the Pod's resources.
It's also possible to have one main container inside the Pod
and add one or more sidcar containers that provide additional features to the main container (for example: logging, monitoring, ...).
To create/deploy a Pod, you need first to create a manifest file (YAML).
The manifest file describe the Pod and its components (name, image, port, ...).
You can use kubectl (or any rest client tool) to post the manifest file to the API server.
If applicable, the API server verifies that the request is authenticated, validates it's authorized, and runs the admission controllers on it.
The API server verifies the manifest file and, if no issues, it writes a record for that manifest in the cluster store (etcd).
The scheduler will then read the record and deploy it to a healthy worker node with enough available resources.
You can also use imperative commands (kubectl command-line tool) to create and manage Pods.
Here's the list of events that leads to the creation of a Pod:
-
You define a Pod in a manifest file (YAML)
-
You post the manifest file to the API server.
-
The API server validates the manifest and persist it in the cluster store (etcd) as record of intent (desired state)
-
The scheduler reads the record, converts it into a PodSpec, and schedules the PodSpec to healthy worker node with enough available resources.
-
The kubelet (a Kubernetes agent) accepts the PodSpec and start the creation of the Pod.
-
The Pod enters the Pending state while the container runtime, on the worker node, download the images and starts the containers.
-
The Pod remains in the Pending state until all of its containers are created.
-
The Pod enters the running state, if its containers are created successfully.
-
The Pod enters the succeeded state, if it successfully finishes its tasks.
-
The Pod enters the failed state, if one or more container failed.
The Pod won't be rescheduled.