Deploy to Kubernetes on GKE

Tech used:
Node.js
Docker
Kubernetes
GKE(Google Kubernetes Engine)
GCR(Google Container Registry)
Steps
Create kubernetes cluster on GKE.
Setup Connection to created GKE cluster in with your local machine or cloud shell.
gcloud container clusters get-credentials <CLUSTER_NAME> --zone <ZONE> --project <PROJECT_ID>Create a simple nodejs/express application.
Write Dockerfile for the application
FROM --platform=linux/amd64 node:14 WORKDIR /usr/app COPY package.json . RUN npm install COPY . . EXPOSE 80 CMD ["node","app.js"]Build the Docker image
docker build -t us.gcr.io/<PROJECT_ID>/imagename:tag .Push docker image to GCR(Google Container Registry)
docker push us.gcr.io/<PROJECT_ID>/imagename:tagTest the application using docker.
docker run -d -p 3000:80 us.gcr.io/<PROJECT_ID>/imagename:tagWrite kubernetes manifest file for deployment.
deploy.ymlapiVersion: apps/v1 kind: Deployment metadata: name: nodeappdeployment labels: type: backend app: nodeapp spec: replicas: 1 selector: matchLabels: type: backend app: nodeapp template: metadata: name: nodeapppod labels: type: backend app: nodeapp spec: containers: - name: nodecontainer image: us.gcr.io/<PROJECT_ID>/imagename:tag ports: - containerPort: 80Write kubernetes manifest file for service.
service.ymlkind: Service apiVersion: v1 metadata: name: nodeapp-load-service spec: ports: - port: 80 targetPort: 80 selector: type: backend app: nodeapp type: LoadBalancerApply manifest file to create deployment.
kubectl apply -f deploy.ymlCheck status of the deployment.
kubectl get deployApply manifest file to create load balancer service.
kubectl apply -f service.ymlCheck status of service.
kubectl get svcCheck the external IP of the service in the browser.





