As the first step, we take our application and create a Docker image. Once the image is created, it works as a portable runtime for our application.
Now we can create a container from that image and run it in a Docker environment or in a container orchestration system like Kubernetes.
What is a Pod?
The minimum unit of deployment in Kubernetes is a Pod. So pod is the smallest unit that we can run inside Kubernetes.
Container runs inside the Pods.
NOTE
Typically, we would run a single container inside a Pod.
But it is possible(and sometimes necessary) to run multiple containers inside a Pod.
Pods Inside Nodes
NOTE
How to determine if 2 containers should stay in the same Pod or not?
Ask -> can we run these two application on two different hosts?
If the answer is yes, then these 2 containers should be on separate pods.

Elements Inside a Pod

Elements Isolated for Container inside a Pod
Inside Kubernetes, Pods have the following things isolated for each container-
Elements common for Containers inside a Pod
The following elements are common for all pods-
NOTE
The network namespace is shared so that containers can communicate with each other over localhost.
This is helpful as the containers are related and that is why we put those in the same Pod. These containers often need to communicate with each other.
Configuration
NOTE
To remember the components of a K8s configuration, just remember-
AKMS
Create a YAML file and add the following lines. Here we are creating a file named simple-nginx.yml-
# simple-nginx.yml
apiVersion: v1
kind: Pod
metadata:
name: simple-nginx
labels:
app: web
type: ui
tier: frontend
env: staging
spec:
containers:
- name: nginx
image: nginx:1.25-alpine
ports:
- containerPort: 80
YAMLUse the YAML file to create Pod-
# Apply the YAML file to create Pod
$ kubectl apply -f simple-nginx.yml
pod/simple-nginx created
# Check the Pods in the cluster
# The simple-nginx pod is not ready yet
$ kubectl get pod
NAME READY STATUS RESTARTS AGE
simple-nginx 0/1 ContainerCreating 0 4s
# Let's check again
# This time the simple-nginx Pod is running
$ kubectl get pod
NAME READY STATUS RESTARTS AGE
simple-nginx 1/1 Running 0 22s
# Delete the pod
$ kubectl delete pod simple-nginx
pod "simple-nginx" deleted
# Let's check the pod
# It is gone
$ kubectl get po
No resources found in default namespace.
Bash WARNING
Generally, Pods are not directly created in Kubernetes.
Kubernetes does not automatically monitor Pod state, so it does not ensure that the Pod is restarted when there is any issue.
In most cases, Pods are created using Deployment. We have discussed Deployment in detail in the next section.