[GSP015] Running a Node.js Container on Google Kubernetes Engine


You can find coupons for labs here. I didn’t pay money for this. Because i am poor.


Google Kubernetes Engine makes it easy to run Docker containers in the cloud. Google Kubernetes Engine uses Kubernetes, an open source container scheduler, to ensure that your cluster is running exactly the way you want it to at all times.

In this lab you will learn how to launch a container and how to launch replicas of that container on Google Kubernetes Engine.

Creating a Cluster

$ gcloud config set compute/zone us-central1-a
$ gcloud container clusters create hello-world

Building and Publishing the Node.js App


$ git clone https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git

$ cd nodejs-docs-samples/containerengine/hello-world/

$ cat Dockerfile
FROM node:6-alpine
COPY server.js .
CMD node server.js
$ docker build -t gcr.io/$DEVSHELL_PROJECT_ID/hello-node:1.0 .

// Publish the container
$ gcloud docker -- push gcr.io/$DEVSHELL_PROJECT_ID/hello-node:1.0

Deploying the Node.js App

$ kubectl run hello-node --image=gcr.io/$DEVSHELL_PROJECT_ID/hello-node:1.0 --port=8080

$ kubectl get deployments

$ kubectl get pods

// Allow External Traffic
$ kubectl expose deployment hello-node --name=hello-node --type=LoadBalancer --port=80 --target-port=8080

$ kubectl get svc hello-node
NAME         TYPE           CLUSTER-IP    EXTERNAL-IP      PORT(S)        AGE
hello-node   LoadBalancer   80:30099/TCP   88s OK