Create Kubernetes Clusters (k8s)

How To Create Kubernetes (K8S) Clusters on Google Cloud

Diving into the world of Kubernetes on Google Cloud Platform (GCP)? This introductory guide is tailor-made for beginners, walking you through the nuances of building, deploying, and exposing services efficiently with the gcloud command-line utility. By mastering these steps to create K8s Clusters, you’ll be well-equipped to automate and script bulk deployments seamlessly.

To streamline the process, our tutorial harnesses the power of the Google Cloud Shell—a versatile, browser-based tool integrated within GCP. As you navigate through GCP’s interface, keep an eye out for the Cloud Shell icon located in the top-right corner—it’s your gateway to executing the commands we’ll cover


Setting Up a Regional Kubernetes Cluster on GCP

Step 1: Configure CloudShell for Your Project

To start with, ensure CloudShell is properly linked to your project. In this tutorial, our project is named turbonet-test. Run the following command in CloudShell:

gcloud config set project turbonet-test

gcloud config set project turbonet-test

Step 2: Set Default Region/Zone

For the purpose of this demonstration, we’ll use the europe-west1 region. Execute:

gcloud config set compute/region europe-west1
gcloud config set compute/region europe-west1

Step 3: Update gcloud Components

To ensure you’re using the latest components, issue:

gcloud components update

In case you encounter a warning, you might need administrative privileges. In such cases, execute the command with sudo.

Step 4: Build the Regional Cluster

Let’s now create our regional cluster with the following specifications:

  • Nodes: 2
  • Disk Size: 15GB (standard disk)
  • Autoscaling: Enabled (ranging between a minimum of 1 node and a maximum of 10 nodes)
  • Auto-repair: Enabled

Run the following command to initiate the cluster creation:

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

Allow a few minutes for the cluster to be set up.

“cluster completed”

Step 5: Verify the Cluster Creation

Once you receive a “cluster completed” message, you can confirm the successful deployment by visiting 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 a different availability zone. This can be confirmed by clicking on the cluster name

“configured for multiple regions”

Understanding Cluster Creation and Management in GCP

Regional Cluster:

Upon inspection, you’ll notice the cluster size stands at 6, even though we initiated it with 2 nodes. This expansion is due to the regional nature of our cluster, which autonomously provisions extra nodes across diverse availability zones for resilience. You can validate this by:

  • Clicking on the cluster name.
  • Observing the label: “configured for multiple regions”.

For quick access to gcloud commands on creating workloads and exposing services, please refer to the conclusion of this article.

Single Zone Cluster:

Let’s shift gears to construct a single zone cluster, which closely mirrors the previous approach but with distinctive attributes.

Our cluster will encompass:

  • A solitary zone: us-central1-b.
  • Utilization of preemptive compute resources.
  • No monitoring or logging services.

To accomplish this, run:

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

This will unfurl a comprehensive overview of the cluster. Notable facets include:

  • Described zone.
  • Web console perspective.

Interestingly, we deliberately deactivated logging earlier. However, cluster configurations are mutable. To reactivate logging:

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

Elsewhere On TurboGeek:  Deploy an Application using Kubernetes on GCP


Richard Bailey, a seasoned tech enthusiast, combines a passion for innovation with a knack for simplifying complex concepts. With over a decade in the industry, he's pioneered transformative solutions, blending creativity with technical prowess. An avid writer, Richard's articles resonate with readers, offering insightful perspectives that bridge the gap between technology and everyday life. His commitment to excellence and tireless pursuit of knowledge continues to inspire and shape the tech landscape.

You may also like...

Leave a Reply

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