Create Regional and Zonal K8s Clusters on GCP

Reading Time: 4 minutes

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.

, Create Regional and Zonal K8s Clusters on GCP
CloudShell

Regional Kubernetes Cluster

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

, Create Regional and Zonal K8s Clusters on GCP

gcloud config set project turbonet-test

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

, Create Regional and Zonal K8s Clusters on GCP
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

, Create Regional and Zonal K8s Clusters on GCP
“cluster completed”

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

, Create Regional and Zonal K8s Clusters on GCP
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 a different availability zone. This can be confirmed by clicking on the cluster name

, Create Regional and Zonal K8s Clusters on GCP
“configured for multiple regions”
, Create Regional and Zonal K8s Clusters on GCP

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
, Create Regional and Zonal K8s Clusters on GCP
Completed

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:

, Create Regional and Zonal K8s Clusters on GCP
describe zone

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

, Create Regional and Zonal K8s Clusters on GCP
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="logging.googleapis.com"

After a few minutes, your zone cluster will update

, Create Regional and Zonal K8s Clusters on GCP

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
, Create Regional and Zonal K8s Clusters on GCP
get-credentials

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
, Create Regional and Zonal K8s Clusters on GCP
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
, Create Regional and Zonal K8s Clusters on GCP
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
, Create Regional and Zonal K8s Clusters on GCP
resizing cluster
, Create Regional and Zonal K8s Clusters on GCP
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 *