Skip to main content
In this tutorial, we will integrate a backend (Django) app with a frontend (React.js) app by preparing a Helm chart.

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.
If not, check out these guides to get you started before proceeding further:

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:
Once the images are built, we need to load them into Minikube:
The above command takes the mentioned image that is available as an archive and makes it available in the cluster.

Create Helm Chart

For this guide, we’ll create a simple chart called python-react-chart, and then we’ll create some templates inside of the chart.
Once the chart is created, it will have some default templates. We don’t need them for now. Let’s copy them to another folder called 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.
Now, create a templates directory for us to write new templates.

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.
For example, if your app is published in public AWS ECR, the input will be like:

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 the PORT 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 the PORT 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
Hurray 🎉! Now we have the chart ready. Next is to install and run the app in the local Kubernetes cluster.

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, andvalues.yaml` can have actual default values.
To use another YAML file instead of the default values.yaml for local development, run:
If the installation is successful, you would see the following in your terminal output:
This will bring up 3 pods for each service/deployment we created. Run the following command to see the list of pods running:
You should see the following in your terminal:
To get the URL of the gateway service, run:
It would print the URL. Now you can access the:
  • 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 the gateway.service.type in the gateway from NodePort to LoadBalancer:
and run:
Now you can access the:
  • 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.

Next Steps

Now we have the chart ready. The next steps would be: