kubernetes-node-application

Docker image URL:

https://hub.docker.com/layers/ankitdawra/nodejs-image/latest2/images/sha256-1c9b51b7784e0f0a7fc8a4e203252cb1a9380950f5b0ad35218af7eee41fdc68

URL for Service Tier (when setup done)

http://localhost:5000

Name: Ankit Dawra

Employee ID: 3161666


Setup guidelines:

Step 1: Start all the containers, services, configMaps, secrets, hpa with the below command

kubectl apply -f __db_volume.yaml && kubectl apply -f __configMaps.yaml && kubectl apply -f __secrets.yaml && kubectl apply -f __db_deployment.yaml && kubectl apply -f __deployment.yaml

Note: (In case of any issues, we can delete all containers, services, configMaps etc.. by running below command and start afresh from step 1)

kubectl delete -f __deployment.yaml && kubectl delete -f __db_deployment.yaml && kubectl delete -f __secrets.yaml&& kubectl delete -f __configMaps.yaml && kubectl delete -f __db_volume.yaml

Step 2: Database Import

docker cp db.sql [mysql_container_id]:/db.sql (Copy the database file to db container)
docker exec -it [mysql_container_id] /bin/bash (exec into db container)
mysql -u root -p (login into mysql)
ENTER PASSWORD as "password"
source db.sql (Run db.sql file to import database)

Note: We can find mysql_container_id from "docker ps" command

Run the application

Run the application on http://localhost:5000 if you are running on local or http://[IP_ADDR]:5000 where IP_ADDR is IP address where your node-js service is exposed.

If everything works well, you will see something like this:

image

To Run HPA Demo follow the steps below:

kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
kubectl edit deploy -n kube-system metrics-server (That will open a text editor with the deployment yaml-file)
Add "- --kubelet-insecure-tls" spec.template.spec.containers.args
kubectl apply -f __hpa.yaml
Visit http://localhost:5000/upscale/30 if you are running on local or http://[IP_ADDR]:5000/upscale/30 to increase the load on pods, it will upscale the number of pods to 5 as per the current configuration. And, it will downscale to 1 depending upon the load.

References:

https://github.com/kubernetes-sigs/metrics-server/tree/master?tab=readme-ov-file#installation

image

In case of errors, you might see below screens:

When Database server not configured properly
image
When Database not setup properly
image
When no user record exists
image