The kubernetes folder consists of all the config files needed to deploy a MERN app on a simple K8s cluster like Minikube (1 node).
-
Source code for the frontend app (react app) could be found here.
-
Source code for the server (express app) could be found here.
-
Clone repo on your local machine. Change directory to
kubernetes
. -
Make sure you have Minikube installed and running properly.
-
You can use a Kubernetes IDE like "Lens" to connect to your Minikube cluster. Makes it easier for monitoring changes.
-
Now first create the secret. (Holds mongodb admin username and password)
kubectl apply -f secrets/mongodb-secret.yml
-
Later create the mongodb stateful set. It will create 2 replicas.
kubectl apply -f stateful-sets/mongodb-stateful-set.yml
-
Now create the mongodb internal service so that our server can later access the mongodb pods using it.
kubectl apply -f services/mongodb-service.yml
-
Now deploy the server app by running:
kubectl apply -f deployments/note-server-depl.yml
If everything is working properly you would able to see the message connected to DB in the server pod logs.
-
Now create the server internal service for communication between the frontend and the backend.
kubectl apply -f services/note-server-service.yml
-
Deploy frontend:
kubectl apply -f deployments/note-depl.yml
-
Create external service for the frontend app (Load Balancer) by running:
kubectl apply -f services/note-service.yml
-
To get an external IP assigned to the frontend deployment you can run:
minikube service note-service
-
Open the IP adddress in browser and you will be able to see the app running!
-
If you want to run a database GUI like
mongo-express
, you can simply run:kubectl apply -f deployments/mongo-express-depl.yml
-
Later create mongo-express external service for acccessing the GUI in browser:
kubectl apply -f services/mongo-express-service.yml minikube service mongo-express-service
- Docker
- Minikube
- Kubectl
- Lens: K8s IDE (Recommended)