To follow this article you can get the files on - https://github.com/ProgrammingOnMars/kubernetes-for-dev
Now let's see how the smallest deployable units from Kubernetes work called Pod.
Pods are the smallest deployable units of computing that you can create and manage in Kubernetes - Retrieved August 13, 2024 from https://kubernetes.io/docs/concepts/workloads/pods/
Remember that a Pod isn't a container, it wraps a container.
Also, a Pod can have more than one container but the most common use case is "one-container-per-Pod". Thus, Kubernetes manages the pod rather than the containers directly.
An important thing to emphasise is pod is not a container or a process. It is an environment for running container workloads.
A Pod is not a process, but an environment for running container(s). A Pod persists until it is deleted. Retrieved August 13, 2024 from https://kubernetes.io/docs/concepts/workloads/pods/
We can see the image above, the Pod into a Worker Node and the container into a Pod
From now on, I recommend that you follow and put into practice the same examples as me.
Let's create a yml
file to represent a pod.
apiVersion: v1
kind: Pod
metadata:
name: nginx
labels:
app: programmingonmars
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
kubectl apply -f simple-pod.yml
What will happen after applying this configuration in my k8s cluster?
So, basically the kubectl
will request the kube-api
to schedule the Pod creation.
For now, we only need to know the pod was created its status is running, and we have 1 running.
Run the command:
kubectl get pods -o wide
to see the pods with more details.
Imagine that you have a crash in your application and you need to keep reliability and availability let's see if using a pod you can keep that.
kubectl delete pod nginx
The truth is that if you want to use a Kubernetes cluster, you probably want to manage many workload applications, maybe use a microservice architecture or increase the number of replicas of your system's specific module (microservice).
As you can see, the Pod was deleted, and that is it, we need to improve this implementation and use another kind of object to keep the scalability, availability and reliability of a good application.
How could we improve this scenario?
Let's comprehend the ReplicaSet