This project is about creating and deploying a web application comprising a backend and frontend microservices on a Kubernetes cluster. When looking over the internet for similar projects endeavouring to understand the whole development and deployment picture, I could not find a particular example expanding on networking between microservices while using a frontend, backend and a database to store data. Thus, after assembling information from different sources, I created a simple web application using Fiber (a Go web framework).
The application is called Any Paste, and it is a cheap clone of Pastebin.com. In other words, a user can submit any text, and Any Paste will store it in a database. Afterwards, the users can retrieve a specific piece of posted text, providing its identification number.
You need access to a local or remote Kubernetes cluster, such as Minikube or AKS. You also need the kubectl
cli tool, which will allow you to connect to the desired Kubernetes cluster.
The current installation does not include automation tools such as helm
or kustomize
to automatically package and install our Kubernetes manifest files.
-
Connect to your Kubernetes cluster via kubectl - for each Kubernetes provider there is a different way to get on your cluster. Please ask Google or ChatGPT to show you the way :)
-
Create a new namespace for the application
kubectl create namespace any-paste
-
Install the mysql instance using the following commands (note that in general it is a bad idea to deploy databases on Kubernetes. Make sure you watch my full video for more details):
kubectl apply -f .k8s/database/volume.yaml --namespace any-paste
kubectl apply -f .k8s/database/secret.yaml --namespace any-paste
kubectl apply -f .k8s/database/config-map.yaml --namespace any-paste
kubectl apply -f .k8s/database/deployment.yaml --namespace any-paste
kubectl apply -f .k8s/database/service.yaml --namespace any-paste
-
Install the backend of our application using the following commands:
kubectl apply -f .k8s/api/deployment.yaml --namespace any-paste
kubectl apply -f .k8s/api/service.yaml --namespace any-paste
-
Install the frontend of our application using the following commands:
kubectl apply -f .k8s/website/deployment.yaml --namespace any-paste
kubectl apply -f .k8s/website/service.yaml --namespace any-paste
-
Enable the Ingress Contrller for your cluster. If you are on Docker Desktop you can use
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.1.0/deploy/static/provider/cloud/deploy.yaml
, while for Minikube you can useminikube addons enable ingress
. Essentially, an Ingress Controller is a loadbalancer which takes as input an Ingress Resource that describes how we want to perform loadbalancing. -
Finally, we need to deploy an Ingress Resource to describe how we want to manage the incoming traffic. Note that all deployed services (database, frontend and backend) are all deployed on a private virtual network and are not accessible from the outside world. Hence, we need to deploy ingress, which will route incoming traffic to our application. For this, use the following command:
kubectl apply -f .k8s/ingress.yaml --namespace any-paste