Prerequisites
- Docker to build standalone containers to serve your production app.
- Helm package that contains all the resources you need to deploy an application to a Kubernetes cluster.
- Minikube to set up Kubernetes clusters locally.
This guide assumes that you have basic knowledge of the above-mentioned technologies and tools. If you are not
familiar with any of them, it is highly recommended to review their official documentation and tutorials to get up to
speed before proceeding with this guide.By this time, it is assumed that you have a backend with Django and a frontend application, both dockerized and
published to a registry.
- Building and packaging a Python app using Django
- Building and packaging a React app
- Publishing Docker images to a registry
Setup Minikube
Minikube is local Kubernetes, focusing on making it easy to learn and develop for Kubernetes. Refer to the installation guide for installing Minikube on your machine. Since we are building and testing the images locally, you might have built the react-app and python-app already. In short, run these commands from the root of the respective project to build the images:Create Helm Chart
For this guide, we’ll create a simple chart calledpython-react-chart
, and then we’ll create some templates inside of
the chart.
templates-bak
. You might need them later for reference or you can remove them.
When you’re writing production-grade charts, having basic versions of these charts can be really useful. So in your
day-to-day chart authoring, you probably won’t want to remove them.
Create/Modify values.yaml
Assume that you have built the images locally. You might have a values.yaml
file in the root directory created by Helm
with sample content. Let’s clear the contents and update them with the following to specify the images and the tag to be
used for deployments.
values.yaml
Here we are using the locally built images for testing. In a real app scenario, the repository will be replaced with
the actual registry URL depending on where it is published.
Create Deployments/Kubernetes Manifests
Now let’s create deployments for all three services:- frontend - a React app
- backend - a Python app built with Django
- gateway - an Nginx server to route traffic to the frontend and backend depending on the URL path
Frontend Deployment
Let’s create a manifest that will create a deployment for the frontend application, specifying the Docker image and setting thePORT
environment variable. It also creates a service to expose the frontend application.
templates/frontend.yaml
Backend Deployment
Create another manifest that will create a deployment for the backend application, specifying the Docker image and setting thePORT
environment variable. It also creates a service to expose the backend application.
templates/backend.yaml
Gateway Deployment
We need one more manifest, which will create a deployment for the Nginx gateway. This gateway service will route traffic to the frontend and backend services based on the request path. It also creates a service to expose the gateway.templates/gateway.yaml
Nginx ConfigMap
This ConfigMap defines the Nginx configuration, specifying the routing rules to direct traffic to the appropriate service based on the request path.templates/nginx-config.yaml
Install the Chart
To install the services, run the following from the root of the chart directory:The
helm install
command would pick the values from values.yaml
and spin up the cluster. Alternatively, you
can create another file called `local-values.yamlwhich contains the local images, and
values.yaml` can have actual default values.values.yaml
for local development, run:
- Frontend at
http://127.0.0.1:<PORT>/
- Backend at
http://127.0.0.1:<PORT>/api/<YOUR_PATH>
Alternatively, you could also use Minikube tunnel to view the app.
Change thegateway.service.type
in the gateway from NodePort
to LoadBalancer
:
- Frontend at
http://localhost:4000/
- Backend at
http://localhost:4000/api/<YOUR_PATH>
LoadBalancer should be used only for development purposes. While pushing Helm charts to production for use with
LocalOps, use
NodePort
.Uninstalling the Helm App
To clean up the app, run the following:Before Publishing to Helm Registry
Remove the
imagePullPolicy: IfNotPresent
from the deployment scripts. This is needed only to test the local
images.Replace the repository in your values.yaml
with actual registry images or use the custom YAML via the -f
flag in the
Helm CLI.