avatarAndrea Perera

Summary

The provided content outlines a comprehensive guide on setting up a standard Kubernetes cluster on Google Kubernetes Engine (GKE) in Google Cloud Platform (GCP), including prerequisites, step-by-step instructions, and security and metadata configurations.

Abstract

The article "How to Set Up a Kubernetes Cluster in Google Cloud Platform" offers a detailed three-step guide for creating a Kubernetes cluster using Google Kubernetes Engine (GKE). It begins by introducing GKE as a managed cloud service that simplifies the deployment, scaling, and operations of containerized applications. The author then lists the prerequisites, such as creating a GCP account and project, installing Kubectl and gcloud-sdk, and creating a service account with Kubernetes Engine Admin permissions. The core of the article is a step-by-step walkthrough of setting up a Kubernetes cluster, which includes enabling the Kubernetes Engine API, configuring cluster basics like name and location type, and customizing node pools with options for size, autoscaling, and machine type. Security and metadata configurations are also covered, along with advanced networking options such as creating a private cluster. The article concludes with methods to connect to the newly created Kubernetes cluster, emphasizing the use of Google Cloud Console and Cloud Shell for ease of access.

Opinions

  • The author recommends using a regional cluster for production due to its high availability benefits.
  • For ease of maintenance and upgrades, the author suggests choosing a release channel for the control plane version rather than a static version.
  • The article emphasizes the importance of autoscaling for production applications to manage varying workloads efficiently.
  • The author advises on the use of general-purpose machine types and specifies a preference for n1-standard-4 with 15GB memory for the use case described.
  • The author notes the benefits of surge upgrades to minimize interruptions during cluster maintenance.
  • The article highlights the convenience of using the Google Cloud Console for cluster creation and management, as well as the command-line interface for those who prefer it.
  • A special mention is made about the Enlear Academy YouTube Channel, which is recommended for readers who are new to Kubernetes and want to learn more through video tutorials.

Deploy a React Application in Kubernetes | Dockerizing a React Application

How to Set Up a Kubernetes Cluster in Google Cloud Platform

3 Step Guide to Set Up Standard Kubernetes Cluster on Kubernetes Engine in Google Cloud Console

Created by the author

The Google Cloud Platform provides Kubernetes as a service. Google Kubernetes Engine (GKE) is a managed cloud service offered by Google Cloud Platform.GKE provides a production-ready environment with features like autoscaling, load balancing, security, and other features to manage containerized applications.

In this article, I will demonstrate the steps of creating a Kubernetes cluster in GKE.

Need to know more details of the GKE clusters ?? I recommend watching the Kubernetes Cluster Setup on Google Cloud Platform on Enlear Acadamy YouTube Channel. It covers how to set up a Kubernetes Cluster in GKE along with a demo at the end and will bring you up to speed.

Prerequisites

  1. Create a GCP account and create a project.

Steps to create a project,

a.Visit Google Cloud Console.

b. Click on Select a project dropdown and select the project if you have already created one or click on NEW PROJECT.

  1. Install Kubectl (Kubernetes command-line tool) to run commands against Kubernetes clusters.
  2. Install gcloud-sdk to access and manage GCloud resources.
  3. Create a service account.

Steps to create a service account,

Visit the menu in gcloud console and go to IAM & admin, and click Service accounts.

a. Give a name for your service account and click Create.

Service account creation

b. Give Kubernetes Engine Admin permission for the service account and click on DONE.

Created Service account

c. Under the Action dropdown, click Manage keys, click the Create key button, JSON selected, and save the file.

Note: Do not lose this file,GCP will only provide you with a copy.

Step 1 — Set up a Kubernetes Cluster in GKE

Steps to create a Kubernetes Cluster in Google Cloud Console,

  1. Visit the Google Kubernetes Engine menu in the gcloud console and go to Clusters.
  2. Enable Kubernetes Engine API.

3. Click CREATE.

  1. Choose the GKE Standard template and click on CONFIGURE to customize the template with the necessary following fields.

Section 1 — Cluster basics

  • Name: It must be unique within the project and the zone.
  • Location Type: Zonal or Regional

You can’t change the cluster type after the cluster is created, but you can change whether you want a single zone or multi-zone. Choose a Zone or Region closer to your location.

I do recommend using a regional cluster for production as it offers high availability.

Note: In order to create a multi-zone cluster check the “Specify default node locations” checkbox and select the additional zones.

Snapshot of how to create a multi-zone cluster

Chose the version of Kubernetes you want to use for your cluster. I do recommend the option of the Release channel because it will automatically upgrade or update your cluster. If you choose the static version, you need to manually specify the version and upgrade or update your cluster.

Section 2 — default-pool

Under the node pool: choose the default node pool and customize it with the necessary fields.

Snapshot of Section 2
  • size: The number of nodes to create in the cluster. For this use case, the number of nodes is 3.
  • Enable autoscaling: You can enable autoscaling when you deploy your production application. Pod autoscaler will scale the number of pods in a replication-controller/deployment/replica-set based on observed CPU utilization provided metrics.
  • Surge upgrade: surge upgrades minimize interruptions to your nodes while performing cluster maintenance and allow you to control the number of nodes upgraded concurrently.

A. Nodes

Snapshot of Nodes section
  • Image type: select the node image from the drop-down list. For this use case, I selected the default.
  • Machine Configuration: There are different types of configurations under the Machine family. I choose the GENERAL-PURPOSE.
  • Machine type: Compute Engine machine type to use for the instances. Each machine type is billed differently. The default machine type is n1-standard-1. I changed it to n1-standard-4 15GB memory

B. Security

  • You can configure all the security settings in this section.
Snapshot of Security Tab

C. Metadata

  • You can configure all the meta settings in this section.
Snapshot of Metadata Tab

Section 3— CLUSTER

This section can be used for advanced configurations.

Snapshot of Networking Tab

Note: In order to create a private cluster select Private cluster in the Network Tab. A private cluster is a type of VPC-native cluster in which nodes are isolated from internal and external traffic by assigning them an internal IP address only.

  • For this use case, I will select the public cluster.

Step 2— Create a Kubernetes Cluster in GKE

There are three methods to create a Kubernetes cluster in GKE.

  1. Using the command line on your local machine or the cloud shell in Gcloud.
The gcloud command to create a cluster
cloud beta container --project "red-abstraction-327505" clusters create "cluster-demo"--zone "us-centrall-c" --no-enable-basic-auth--cluster-version "1.20.9-gke.1001 --release-channel "regular"
--machine-type "n1-standard-1" --image-type "COS_CONTAINERD" --disk-type "pd-standard" --disk-size "100" --metadata disable-legacy-endpoints-true-- scopes"https://www.googleapis.com/auth/devstorage.read_only", "https://www.googleapis.com/auth/logging.write."https://www.googleapis.com/auth/monitoring","https://www.googleapis.com/auth/servicecontrol "https://www.googleapis.com/auth/service.management.readonly*,"https://www.googleapis.com/auth/trace.append" --max-pods-per-node "118" --num-nodes "3" --logging=SYSTEM, WORKLOAD --monitoring-SYSTEM--enable-ip-alias --network*projects/red-abstraction-327505/global/networks/default --subnetwork "projects/red-abstraction-327505/regions/us-central1/subnetworks/default" --no-enable-intra-node-visibility --default-max-pods-per-node "118" --no -enable-master-authorized-networks --addonsHorizontalPodAutoscaling,HttpLoadBalancing,GcePersistentDisksiDriver --enable-autoupgrade --enable-autorepair --max-surge-upgrade1 --max-unavailable-upgrade 0 --enable-shielded-nodes--node-locations "us-centrall-c"
  • Go to the terminal and paste this command.

2. using a Rest Request.

Snapshot of Rest Request

3. Using the Google Cloud Console (UI)

I will use Google Cloud Console to create a Kubernetes Cluster in GKE.

  • In the end, click on Create.
  • Navigate to Clusters under the Kubernetes Engine in the GCloud console and see the status.
Snapshot of the created cluster

Step 3— Connect to the Kubernetes cluster.

There are two methods to connect to a Kubernetes cluster in GKE.

  1. Using the command line in your local machine.
  2. Using the cloud shell in Gcloud

Steps to connect using the cloud shell in Gcloud,

  1. Click on the cluster name in the Kubernetes clusters.
  2. Click on ‘CONNECT’

3. Click on “RUN IN CLOUD SHELL.”

Note: To connect via command line in your local machine, copy the Command-line access command and paste it in your local machine (Configure kubectl command-line access by running the following command: gcloud container clusters get-credentials <CLUSTER_NAME> — zone <ZONE> — project <PROJECT_NAME>)

- Go to the terminal and paste the command

Cloud Shell

Tada👏, now you have successfully created a Kubernetes Cluster in GKE and access the cluster!!!🥳

Conclusion

As you have seen, you can create your Kubernetes cluster using GKE, which is a managed cloud service, and you can create and customize it based on your needs.

Thanks for Reading! 😊

New to Kubernetes? I recommend watching the Kubernetes for beginners tutorial on Enlear Acadamy YouTube Channel. It covers all the basics of Kubernetes and will bring you up to speed.

Read More

Google Cloud Platform
Kubernetes
Google Kubernetes Engine
Setup
DevOps
Recommended from ReadMedium