In this assignment, you will build and deploy a containerized Django web application backed by a MySQL database. The two components will be hosted on a public cloud Kubernetes cluster, following production-style best practices.
Youβll work with Docker, Kubernetes ConfigMaps, Secrets, Deployments, and Services, leveraging MySQL as the backend. This simulates a real-world DevOps workflow using infrastructure-as-code principles.
- A basic Django project with one app.
- A default
settings.pyfile (use database values from here). - Example models and views for testing.
- Create a
Dockerfileto containerize the Django application. - Your Docker image must:
- Install dependencies from
requirements.txt - Automatically run database migrations
- Start the Django development server on port 8000
- Install dependencies from
- Create a ConfigMap with the following keys:
MYSQL_HOSTMYSQL_PORTMYSQL_DATABASE
- π‘ Hint: Use the environment variable names referenced in
django_project/settings.py.
- Create a Secret containing database credentials:
MYSQL_USER: djangoMYSQL_PASSWORD: securepassword
- Deploy MySQL using the
mysql:8image. - Use environment variables from the ConfigMap and Secret.
- Deploy the Django application using your custom Docker image.
- Expose container port 8000
- Load environment variables from both the ConfigMap and Secret.
- Create a ClusterIP service for MySQL on port 3306
- Create a LoadBalancer service for Django:
- Service port: 80
- Target port: 8000
-
Ensure the Django app connects to the MySQL database using the provided credentials.
-
Use the following command to retrieve the external IP of your LoadBalancer:
kubectl get svc
Access the Django Admin Panel at: http://EXTERNAP-IP/admin
