Last Updated : 23 Jul, 2025
In this article, we will study how we can deploy Django web applications to Kubernetes. We will also see how to dockerize and build an image of the Django application using Dockerfile. For this article, you should know about setting up a VM in Azure. We will see how to deploy applications on Linux Server.
Introduction to DjangoDjango is a Python framework for developing web applications and APIs. It is most commonly used for Content Management Systems and APIs but it also supports microservices. Django is based on Python, which allows integrations with the most used Python libraries and AI/ML libraries.
Steps to Deploy Django Application in Kubernetes Step 1: Create and set up a Django ProjectCreate a new Django project or use an existing one using django-admin. For this article, you can use the project from the below link
GitHub Link
Once the project is done, start the project and test it in the browser
python manage.py runserver
Hit the URL in the browser to get the desired output.
If the project is working correctly, then freeze the pip modules in requirements.txt file.
pip freeze > "requirements.txt"
As Docker currently supports python version 3.9.19, make sure your requirements contains module versions according to python version.
Step 2: Create Dockerfile and build Docker imageFROM python:3.9.19-alpine
RUN mkdir /DjangoHelloWorld
WORKDIR /DjangoHelloWorld
COPY / .
RUN pip install -r requirements.txt
EXPOSE 8000
CMD python manage.py runserver 0.0.0.0:8000
docker build -t <REPOSITORY-NAME>/<IMAGE-NAME>:<TAG> .
docker run -dp <hostport>:<containerport> IMAGE-NAME
If everything is correct, you should be able to view the application in the browser. After you are satisfied with the output, kill the container.
Step 3: Create Deployment configuration and deploy to KubernetesBefore going to Kubernetes, push the docker image to the docker Hub.
docker push <IMAGE-NAME>
apiVersion : v1
kind : Service
metadata :
name : djangohelloworld
spec :
selector :
app : djangohelloworld
type : LoadBalancer
ports :
- port : 8000
targetPort : 8000
---
apiVersion : apps/v1
kind : Deployment
metadata :
name : djangohelloworld
spec :
replicas : 1
selector :
matchLabels :
app : djangohelloworld
template :
metadata :
labels :
app : djangohelloworld
spec :
containers :
- name : djangohelloworld
image : deepcodr/django-hello-world
ports :
- containerPort : 8000
imagePullPolicy : Always
kubectl apply -f <FILE-NAME>
kubectl get svc
kubectl get podsStep 4: Test the application
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4