Part 3 – Deploy kubernetes on GCP with Google Container Engine (aka GKE)

Introduction

Since Kubernetes was created by Google it seems natural to run it on GCP.
And indeed, running a K8S cluster in GCP is very straightforward !
To avoid confusion between terms

  • GCP : Google Cloud Platform
  • GCE : Google Compute Engine
  • GCK : Google Container Engine ….

You can go through the console but here we will use the glcoud sdk.

Pre requisite

  • A GCP Account
  • Install gcloud SDK

First you’ll need to configure the CLI to access your gcloud account and project, to do so use the following command :

gcloud init

Follow the gcloud steps to configure your account. Once it’s done you can test your configuration by listing your running instances :

gcloud compute instances list

And that’s it !

Deploy the cluster

Since kubernetes is natively supported by GCP we don’t need to use any other tools. Gcloud container will deploy a pure K8S cluster on top of Google Compute engine (virtual machines/instances) and will let us use it using the native kubectl tool.

To Deploy a simple cluster run the following :

gcloud container clusters create "techful-kops-cluster01" --zone "europe-west1-d" --machine-type "custom-1-1024" --image-type "GCI" --disk-size "100"  --num-nodes "2" --network "default" --enable-cloud-logging --no-enable-cloud-monitoring

The options are self explanatory. However note that you could use several zones with  :

--additional-zones "europe-west1-b"

The only two images available are :

  • GCI
  • Container VM

More info on images here

Once the cluster is running you’ll be able to see the instances launched by GKE

gcloud compute instances list

NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
gke-techful-kops-cluster-default-pool-86c719c1-8135 europe-west1-d custom (1 vCPU, 1.00 GiB) 10.132.0.2 35.187.20.58 RUNNING
gke-techful-kops-cluster-default-pool-86c719c1-zcln europe-west1-d custom (1 vCPU, 1.00 GiB) 10.132.0.3 35.187.31.62 RUNNING

Again here, gcloud export all necessary information to you kubectl config :

- See the config file : cat ${HOME}/.kube/config

- See the different contexts configured : kubectl config get-contexts
- See current context : kubectl config current-context

- See all cluster configured in the config file : kubectl config get-clusters

To interact with your kubernetes cluster :

- See your nodes : kubectl get nodes

- See the available namespaces : kubectl get namespaces

- See the pods : kubectl get pods --namespace kube-system

On GCP as you can see the dashboard is installed by default

⇒ kubectl get pods --namespace kube-system
NAME READY STATUS RESTARTS AGE
fluentd-cloud-logging-gke-techful-kops-cluster-default-pool-8f6ae37d-krc7 1/1 Running 0 2m
fluentd-cloud-logging-gke-techful-kops-cluster-default-pool-8f6ae37d-tv05 1/1 Running 0 22m
heapster-v1.2.0-1912761325-zt3j9 2/2 Running 0 7m
kube-dns-v20-0aihy 3/3 Running 0 7m
kube-dns-v20-xu3ci 3/3 Running 0 21m
kube-proxy-gke-techful-kops-cluster-default-pool-8f6ae37d-krc7 1/1 Running 0 2m
kube-proxy-gke-techful-kops-cluster-default-pool-8f6ae37d-tv05 1/1 Running 0 22m
kubernetes-dashboard-v1.4.0-04b55 1/1 Running 0 7m
l7-default-backend-v1.0-3asdt 1/1 Running 0 21m

To access the dashboard simply run the proxy command

kubectl proxy

and browse to :

http://localhost:8001/api/v1/proxy/namespaces/kube-system/services/kubernetes-dashboard/

Resize cluster

If you want to change the number of nodes in your cluster, use the resize commdn :

gcloud container clusters resize "techful-kops-cluster01" --size=3 --zone "europe-west1-d"

The fun thing is that you can resize your cluster to 0 node. It will kill machines but keep your cluster configuration so that you can relaunch it as is later.

Documentation on the command here

Delete the cluster

Finally, to entirely delete your cluster run the following :

gcloud container clusters delete "techful-kops-cluster01" --zone "europe-west1-d"

Conclusion

Running a k8s cluster on GCP with GKE is very easy, however you won’t have the same level of configuration that you have with more custom solution (such as KOPS or even a manual install). But you will benefit from the stability of the platform, auto update and so on.

Leave a Reply

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