In our previous article on Kubernetes we talked about how kube proxy works, control plane, node components, kubelet and etcd. In this article, we are going to take a look at what exactly is a pod in Kubernetes.
What is a pod?
A pod is a group of containers and is the most basic deployable object in Kubernetes. As mentioned it is a group of containers. These mean containers share pod resources. Even though they share pod resources they cannot access each other’s processes as they are separated by namespaces.
Containers on the same pod can access each other on localhost. This is because they share the same network namespace.
They can also share storage if mentioned in their specifications.
You can consider pods as a host where you can deploy multiple containers and they can talk to each other.
Why are pods needed?
You can use a pod to run an instance of your application. You generally use replicaset to create a set of the pod to run your application. Replicaset can control how many pods of your specification will run and it can make sure they are running. If a pod dies, replicaset will launch another one to satisfy the threshold.
There can also be an init container that comes up before other containers and does some admin tasks. You can read about it below
What are the different stages in pod’s lifecycle?
Pending
The pod is created in the cluster but is not launched completely yet. It may be due to a resource issue that is not scheduled, maybe due to one of the containers not coming up due to some health check or maybe downloading the image of the container.
Running
In this state, the pod is running and is ready to take traffic or do its tasks. In this state, the containers are created and one of them is running properly.
Succeded
All the containers in the pod have completed their tasks and are terminated successfully.
Failed
One of the containers is terminated due to failure. Failure means non 0 exit code.
Unknown
As mentioned the state is not known.
There are other states that you can see but they are not actually pod’s lifecycle states. The states can be CRASHLOOPBACKOFF
, IMAGEPULLBACKOFF
, etc.
Below is the spec that you can use to create a pod in Kubernetes.
apiVersion: v1
kind: Pod
metadata:
name: example
spec:
containers:
- name: busybox
image: busybox:1.25
volumeMounts:
- name: quobytevolume
mountPath: /persistent
command:
- /bin/sh
- sleep 30
volumes:
- name: quobytevolume
quobyte:
registry: ignored:7861
volume: testVolume
readOnly: false
user: root
group: root
In this spec. You can see different fields that you can use to launch the pod. In this pod, only one container is launched with an image busybox, and a volume is attached at /persistent path.
When you submit this YAML a pod will be launched with the above specifications. I am not going deep into each pod field. You can read the below documentation for reading more about these.
https://kubernetes.io/docs/tasks/configure-pod-container/
Next: You can read about what exactly are deployments.
This was very basic of what is pod we can read more about how scheduled happens etc in our next articles.
If you like the article please share and subscribe.