Skip to main content

Pod - The smallest unit in Kubernetes

I have gone through Kubernetes architecture in the past, you can go over here. In that article, we know Kubernetes run application in the place call Pod

meme

What is Pod?​

Pod is the smallest unit in Kubernetes for deploy and run an application. Pod can contain one or many containers and they sharing the pod's resource for each others.

pod_1

Pod example

Deploy the first app​

I would use simple image okteto/hello-world:node for test. Or you can deploy custom image to docker hub by yourself, I have written in this article

apiVersion: v1 
kind: Pod # Declare Pod resource
metadata:
name: hello-pod # The name of the pod
spec:
containers:
- image: okteto/hello-world:node # Image to create the container
name: hello-pod # The name of the container
ports:
- containerPort: 3000 # The port the app is listening on
protocol: TCP

Access to your master node and create the file test.yaml with content above. After that, run

kubectl apply -f test.yaml

Check it deploy success or not by the command

kubectl get pod

It must show the pod with name hello-pod and status is running

first app

If status is ContainerCreating, wait for a few minutes and try again because the container is being create. To ensure the image runs correctly, I will use a network proxy for expose the port. Currently, here is my app

pod_status

Run the command

kubectl port-forward pod/hello-pod 3000:3000 

It will expose port 3000, listening and coordinating access to the container app on the same port.

port expose

Test it with curl localhost:3000, if you receive hello message...You have your first app with Kubernetes 🎉

award

Conclusion​

We have deploy and run simple app with pod in Kubernetes. In reality, no one deploy and run app like this 🤣, they usually use Deployment, StatefulSet, DaemonSet. But that is another article, the goal of this post is to show you what a Pod is and its intend.

In the next article, I will write how to group and manage pod by label and namespace

Happy Coding!