Today I am going to talk about how to we can create a scalable web application with microservice. 🐳
I wanted to deploy a full-stack application on a Kubernetes cluster but never found a good video that does it, so that’s what I will be doing today.
What our stack consists. It’s just a POC, so I’m not going to use anything fancy.
This application has a front end which has been created with HTML/CSS and will be hosted with nginx and a backend with Node.js express and connected to Mongo DB. Initially, I did not want to add the database in the stack as it does not work in production as it is not scalable🙅♂️, but why not.
BackEnd Application | Express Node js ⚙️
this Is a simple server app where it sends data that backend is connected and the database is also connected
FrontEnd | NGINX 💻
I'm using Tailwind to have a nice display and get the data from the backend to display it.
lastly, I'm just using a mondoDB image from docker hub
Build the Docker Image 🐳
docker build -t frontendvm .
docker build -t backendvm .
docker build -t mongo .
So now we can scale it with microservice architecture.
we are going to use Docker to containerise our application
Now we can deploy the image as a container and scale it up
we need to create a deployment for the application and service to deliver the application. We will start by creating a deployment from this YAML file we have got.
Create the Deployment and services
Likewise, we can deploy the service from the YAML file.
If you have a Kubernetes service named frontend-service, you can use mongo-service as the DNS name of your application. It’s the responsibility of Kubernetes to forward the request to the corresponding pod.
kubectl apply -f nginx-deployment.yaml
kubectl apply -f nginx-service.yaml
kubectl apply -f server-deployment.yaml
kubectl apply -f server-service.yaml
kubectl apply -f mongo-deployment.yaml
kubectl apply -f mongo-service.yaml
So this is the final output we will get when you enter
minikube service nginx-service --url
Feel free to reach out to me. 😊