The following Django based application consists of two main parts:
- Order Placement Form: A form that allows users to place orders for pizza. This form should include: a. A dropdown menu for selecting the type of pizza (e.g., Margherita, Pepperoni, Vegetarian, etc.). b. A text area for comments or special instructions.
- Orders Table: A page that displays all placed orders in a tabular format. Each row should display the type of pizza ordered and any comments associated with the order.
- Docker [1]
- Minikube [2]
- Kubectl [3]
To run this container app locally the following commands:
docker build -t django-pizza-app .
docker run -p 8000:8000 django-pizza-app
For this initial setup, Minikube [2] was selected to run this application locally. Any other Kubernetes provider can be used (EKS, GKE, ...) if decided to move to a Production workload.
- Install the Minikube CLI tool, for MacOS run:
brew install minikube
- Start and activate Minikube env, this will also point your local
kubectl
profile to the Minikube cluster:
minikube start
eval $(minikube docker-env)
-
Deploy Docker image with either one of the following two options, if any local testing is needed, the Minikube registry can be used before making any updates on the currently DockerHub [4] hosted image.
-
Deploy image locally to Minikube registry
- Enable Minikube Registry add-on:
minikube addons enable registry
- Build Docker image:
docker build -t django-pizza-app .
- Tag and push the image to Minikube:
docker tag django-pizza-app:latest localhost:5000/django-pizza-app:latest docker push localhost:5000/django-pizza-app:latest
- Set
k8s/deployment.yaml
image
value to:localhost:5000/django-pizza-app:latest
-
Use DockerHub image [5]
-
Make an update on one of the following directories:
pizza_app
ororders
, or on theDockefile
, make a PR and once merged it will trigger a CI pipeline that will build and push the image toalejandroariaszuluaga/django-pizza-app
DockerHub. -
Set
k8s/deployment.yaml
image
value to:alejandroariaszuluaga/django-pizza-app:latest
-
-
-
Apply Kubernetes manifests:
kubectl apply -f k8s/deployment.yaml
kubectl apply -f k8s/service.yaml
- Port-forward the app to localhost:
kubectl port-forward svc/django-pizza-app-service 8000:8000
- Access the app through your local browser at http://localhost:8000/
There are two main Kubernetes objects here:
-
Deployment: determines how the application will be deployed by defining physical Memory+CPU resource requests/limits, as well as how many containers (pods) will be deployed by defining a replica count.
-
Service: exposes the application pods through the same service IP, and allows networking being simplified by making it possible to route requests to the service without having to access the IP address of the pod resource.
Two workflows were developed for this application that can be found at .github/workflows
:
- Lint:
lint.yaml
runs two flake8 recommended initial checks that can be tweaked according to the user's requirements. Triggered whenever a new Pull Request is open and checks all Python syntax. - CI for Docker image:
ci.yaml
runs a Docker build and push against the corresponding DockerHub repository. It uses two secrets stored at this repository's configs:DOCKER_HUB_USERNAME
andDOCKER_HUB_ACCESS_TOKEN
to get Read/Write access to the DockerHub. Triggered whenever there are changes in any of the Python files or on the Dockerfile
Implement CD components such as an ArgoCD configuration where ArgoCD monitors and handles the GitOps side of this application: k8s/
directory and its files. Also, this current app was deployed to Minikube, which is a very useful tool when testing and learning about Kubernetes, but it is always recommended to deploy an app to a Cloud-based Kubernetes cluster provider such as EKS. For infrastructure such as that, any form of Infrastructure as Code will be required (Terraform, CloudFormation, CDK...), which will also require a new pipeline definition to handle that side of Cloud infrastructure GitOps.