GCP: Kubernetes Networking

Part 1 : Creating the Kubernetes Cluster

In this article, we will take a look at the various Kubernetes components and resources created. We will focus on general networking, network security and routing of traffic across the cluster. This article is a continuation of the article – GCP: Deploying a Containerised Web Application.

You will get the best out of this article by first watching the video in the article – GCP: Deploying a Containerised Web Application.


Our objective in this part of the article is to highlight all the master and node components created. Let’s first take a quick walk-through all the steps we used to re-create our cluster.

Re-creating our Kubernetes Cluster

gcloud container clusters create hello-cluster --num-nodes=3 --machine-type=f1-micro
gcloud compute instances list

With this simple command, we created a cluster with a master and 3 nodes. The cluster is represented in the introduction diagram above. The 3 node instances created can be seen below.

Next we exposed the application to the Internet.

kubectl expose deployment hello-web --type=LoadBalancer --port 80 --target-port 8080
kubectl get service

On our browser we can view the web page using the external IP address

And next, we scaled the application cluster to 4 replicas.

kubectl scale deployment hello-web --replicas=4
kubectl get deployment hello-web

And now we can see that node gke-hello-cluster-default-pool-12eb8e40-dtq2 is hosting two pods, while the other 2 nodes are hosting one pod each.

Next, we deployed a new version of our hello-app to display “Hi, Planet earth!“. The new version was created by editing the web server application file main.go to display the text “Hi, Planet earth!” instead of “Hello, world“.

docker build -t gcr.io/${PROJECT_ID}/hello-app:v2 .
gcloud docker -- push gcr.io/${PROJECT_ID}/hello-app:v2
kubectl set image deployment/hello-web hello-web=gcr.io/${PROJECT_ID}/hello-app:v2

We can view the contents of the web page by typing the external IP address in our web browser.

Note that the Hostname displayed in the web browser differs from the pod names observed earlier. Kubernetes pods are mortal. When pods get deleted they do not come back. That means new pods replacing deleted ones come with new host names. This behavior is based on this inherent property of immutable infrastructure used by Kubernetes. When the application version was updated it created a new set of pods and deleted the old ones.

Go to the next page to view Part 2: Master Components

Leave a Reply

Your email address will not be published. Required fields are marked *