Deploying a Node.js app to the Google Kubernetes Engine (GKE)

Sergey Onufrienko

I’ll use my GitHub repo which includes a simple Node.js app, Dockerfile, and deployment.yaml. All these commands I’ll enter in Cloud Shell.

git clone https://github.com/sonufrienko/gke-simple-appcd gke-simple-app
gcloud auth configure-docker
docker build -t gcr.io/[PROJECT_ID]/app:v1 .
docker push gcr.io/[PROJECT_ID]/app:v1

Deployment YAML file contains two parts:

  • Service – will create a LoadBalancer to expose our containers to the internet
kubectl apply -f deployment.yaml --record
kubectl get deployments
kubectl get pods
kubectl get services
http://<EXTERNAL-IP>/encrypt?secret=abc&message=i-love-you

Push a new version of docker image to the Container Registry, change docker image version in deployment.yaml and then run this command to set desired deployment state.

kubectl apply -f deployment.yaml --record
kubectl rollout undo deployment/my-app-deployment

Check container logs

kubectl logs <POD NAME>
kubectl exec -it <POD NAME> bash
kubectl delete deployment my-app-deployment
kubectl autoscale deployment <DEPLOYMENT_NAME> --max 6 --min 1 --cpu-percent 60
kubectl get hpa
kubectl get pods
kubectl describe pods/<POD_NAME>

Now you know how to create a GKE cluster, deploy containers, release a new version and rollback, set autoscale policy and how to investigate problems.

  1. Labels
  2. Namespace
  3. Application health check
  4. other Service types (ClusterIP, NodePort, ExternalName)
  5. Ingress