☸️ Deploying First Docker Image as a Kubernetes Pod Using K3s
A beginner-friendly guide to deploying a Docker image in Kubernetes using K3s.
Introduction
After completing Docker fundamentals, including Dockerfiles, Docker Compose, Volumes, Multi-Stage Builds, and Docker Hub, I decided it was time to take the next step and start Kubernetes.
To keep things simple, I used K3s, a lightweight Kubernetes distribution, and deployed one of my previously created Docker images as a Kubernetes Pod.
In this article, I'll walk through the process of deploying my first application in Kubernetes and explain some of the basic commands used to manage Pods.
Why Kubernetes?
Docker helps us package and run applications inside containers.
However, when applications grow, we need additional capabilities such as:
Automated container management
Self-healing
Scaling
Service discovery
High availability
This is where Kubernetes comes in.
What is a Pod?
A Pod is the smallest deployable unit in Kubernetes.
You can think of it as:
Docker Container
↓
Kubernetes Pod
A Pod can contain one or more containers.
For this project, I deployed a Flask application container inside a single Pod.
Project Structure
k8s-flask-pod/
├── pod.yaml
└── README.md
Creating the Pod Manifest
Create a file named pod.yaml.
apiVersion: v1
kind: Pod
metadata:
name: flask-pod
spec:
containers:
- name: flask-app
image: hmanojbabu/flask-app:v1
ports:
- containerPort: 5000
Let's understand the important fields:
apiVersion:
apiVersion: v1 --> Specifies the Kubernetes API version.
kind:
kind: Pod --> Defines the resource type.
image:
image: hmanojbabu/flask-app:v1 -- > The Docker image stored in Docker Hub.
containerPort:
containerPort: 5000 --> The port exposed by the Flask application.
Deploying the Pod
Deploy the Pod using:
kubectl apply -f pod.yaml
Output:
pod/flask-pod created
Kubernetes downloads the image and starts the container.
Verifying the Pod
Check Pod status:
kubectl get pods
Example output:
NAME READY STATUS RESTARTS
flask-pod 1/1 Running 0
The status Running confirms that the application is running successfully.
Viewing Pod Details
kubectl describe pod flask-pod
This command provides useful information such as:
Pod IP Address
Container Status
Events
Image Details
Resource Information
Viewing Application Logs
To view logs:
kubectl logs flask-pod
This is similar to:
docker logs <container-name>
and is extremely useful for troubleshooting applications.
Accessing the Container
To open a shell inside the running container:
kubectl exec -it flask-pod -- sh
This allows us to inspect files and troubleshoot the application directly.
Exit the container:
exit
Accessing the Application
Since the Pod is not exposed externally, I used port forwarding.
kubectl port-forward --address 127.0.0.1 pod/flask-pod 5000:5000
Output:
Forwarding from 127.0.0.1:5000 -> 5000
Now the application can be accessed through:
http://localhost:5000
or
curl http://localhost:5000
Cleaning Up
Delete the Pod:
kubectl delete pod flask-pod
Docker vs Kubernetes
One thing I found helpful was comparing Docker commands with Kubernetes commands.
| Docker | Kubernetes |
|---|---|
| docker run | kubectl apply |
| docker logs | kubectl logs |
| docker exec | kubectl exec |
| docker rm | kubectl delete |
| Container | Pod |
Conclusion
Deploying first Docker image as a Kubernetes Pod was an exciting milestone. It helped bridge the gap between Docker and Kubernetes and provided a practical introduction to container orchestration.
If you're already familiar with Docker, learning Pods is a great place to start your Kubernetes journey.
Happy Learning!

