How to create regional and zonal clusters in Kubernetes (GKE) using the GCLOUD command line utility?

This is a beginners user guide to show you how to build, deploy and expose services using gcloud. This knowledge will allow you to script bulk deployments.

This blog will use the google cloud shell you can open it from almost any GCP window. Look for the cloud shell icon at the top right.


Regional Kubernetes Cluster

First you need to configure CloudShell to work with your project. My project is called turbonet-test

gcloud config set project turbonet-test

Next, it is best to set a default region/zone. In this demo I will use europe-west1

gcloud config set compute/region europe-west1

Next update the gcloud components by typing:

gcloud components update

(if you get a warning run as sudo)

Next type this command to build your regional cluster.

Our cluster will have:

  • 2 nodes
  • 15gb standard disk
  • autoscaling enabled (min 1 node, max 10)
  • Autorepair enabled

gcloud container clusters create turbogeek-regional-cluster –num-nodes 2 –region europe-west1 –disk-size=15gb –disk-type=pd-standard –enable-autoscaling –min-nodes 1 –max-nodes 4 –enable-autorepair

After a few minutes the cluster will be created

“cluster completed”

You can verify the deployment by checking the Kubernetes web console.

verifying in the web console – note the cluster size

You can see the cluster size is 6. We created 2 nodes, but as this is a regional cluster, additional nodes were automatically created in different availability zone. This can be confirmed by clicking on the cluster name

“configured for multiple regions”

For the gcloud commands to create a workload and expose a service skip to the end of this blog post.

Single Zone Cluster

Now we will create a single zone cluster. The process is very similar to before.

Our Cluster will have:

  • Single zone in us-central1-b
  • use premeptible compute
  • no monitoring
  • no logging

The command for this is:

gcloud container clusters create turbogeek-zonal-cluster –zone us-central1-b –preemptible –machine-type n1-standard-1 –no-enable-cloud-monitoring –no-enable-cloud-logging


Next we will use gcloud to pull information about our new cluster

The command for this is:

gcloud container clusters describe turbogeek-zonal-cluster –zone us-central1-b

This will display a huge amount of info about cluster. I have highlighted some key elements below:

describe zone

You can also check the web console to look at our new cluster and gather information about it

web console view

Earlier we deliberately disabled logging. You can update a kubernetes cluster configuration via the command line

The command for enabling logging is:

gcloud container clusters update turbogeek-zonal-cluster –zone us-central1-b –logging-service=””

After a few minutes your zone cluster will update

How to manage Kubernetes cluster with gcloud?

Firstly, when managing via gcloud command line you need to update the kubeconfig file. This is what drives Kubernetes clusters.

We will be working with turbogeek-regional-cluster in this example.

The command for this is:

gcloud container clusters get-credentials turbogeek-regional-cluster –region europe-west1 –project turbonet-test


How to create an additional node pool?

Now we have configured get-credentials type the following to view your existing cluster node pools

gcloud container node-pools list –cluster turbogeek-regional-cluster –region europe-west1

list node pool

To create a new node pool type:

gcloud container node-pools create my-pool –num-nodes=1 –cluster turbogeek-regional-cluster –region europe-west1

pool created

Now you can add your new node pool to an existing cluster

The command for this is:

gcloud container clusters resize turbogeek-regional-clusterr –region europe-west1 –node-pool my-pool –size 1

resizing cluster
confirmation from the web console

Come back next time when we shall use kubectl to create deployments and expose services

You may also like...

Leave a Reply

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