How To Set up a Simple Kubernetes Cluster on Google Cloud Platform

Sumudu Liyanage
6 min readFeb 17, 2022

--

Kubernetes is now the leading solution for container orchestration. It is easy to learn and has some tangible benefits.Most probably, you might be a beginner to Kubernetes who is trying to set up a simple Kubernetes cluster on GCP. If it is, you are at the right place. This blog post will guide you to set up the Kubernetes cluster with easy simple steps.

Before setting up the Kubernetes cluster, you need to have a GCP account. Below section will guide you to create a GCP account successfully. If you already have an account, skip this step.

1. Register a GCP Account

Google Cloud Platform provides you a free trial that gives you $300 for 90 days. Use this link to register in Google Cloud Platform. After visiting the page, give “Get started for free” option to continue. And now, if you are not signed into your Google account, you will have to sign into your google account giving your credentials. Right after that, you will be headed to the window below which is step 1 of the process.

Fill your country and select the category. If you are a person who is doing your individual project or assessment, select class project / assignment category and continue.

After verifying your phone number,you will be directed to the last step of the account creation. In step 3, make sure to put the Account type as Individual. Fill your address and you should enter card details to create the account. You don’t have to worry about giving the card details, since this is a free trial.

2. Setting Up A Kubernetes Cluster In GCP

The basic element of Kubernetes is the Node in which containerized applications are running. We also call them Minions. A Kubernetes Cluster consists of the set of nodes. In a Kubernetes cluster, there are two types of nodes called worker and master. The worker nodes actually execute the containers and applications. Master is responsible for managing the cluster and for orchestration of containers in the worker nodes. Google Cloud provides Google Kubernetes Engine (GKE) with which we can set up a K8 cluster in the cloud.

Let’s follow a simple set of steps to create a K8 cluster in GCP. In the navigation menu in GCP, find Kubernetes Engine under the COMPUTE section and select clusters. Then you have the option to create a cluster. When creating the cluster, you have to provide necessary details.

Under cluster basics tab, you will have to provide below details.

  • You have to provide a name for the cluster.
  • You have to set the location type. You are able to select either Zonal or Regional and need to specify the Zone or Region according to that. Note that after creating the cluster, you cannot change the name and the location of the cluster.
  • You have two options in the Master version as Release channel and Static version. If you go with the Release channel, the K8 cluster will get updated automatically when new versions are released. If you select the Static version, you will have to manually update the cluster, when new releases are available.
  • Under the node pools section, you can view the default pool where there are three key things called Nodes, Security and Metadata. You can change the name of the node pool and number of nodes in it by accessing the default pool section. The default number of nodes is three.
  • Under the Nodes section, you will have to set different fields like Image type, Machine family, Series, Machine type, Boot disk type, maximum pods per node etc. You need to specify the values in this section according to the requirements of your project. But, if you are an absolute beginner, you can keep the default values as it is.

Tip: Put a tick in the “Enable preemptible nodes” option available. Preemptible nodes are Compute Engine instances that last up to 24 hours and provide no availability guarantees, but are priced lower.So, enabling this option will reduce your Compute Engine costs significantly.

  • Other sections like Security and Metadata option in node pool and other cluster details can be kept default. But, those fields can be changed according to your requirements.After following these steps, you are done. Give Create option! Creating the cluster will take a few minutes.

You have successfully created the Kubernetes Cluster on GCP!

Now, connect to the cluster giving the connect option.

Now, to configure kubectl command line access (kubectl is a command line tool which allows you to run commands against Kubernetes clusters) , execute the given command in the cloud shell. So, you have to give “Run In Cloud Shell” option. Then, you will get the shell where you will build everything!

Now you have done it!

I’ll guide you to install Nginx Ingress Controller and Cert Manager in your environment. These two things are very useful in K8.

3. How To Install The NGINX Ingress Controller On Google Kubernetes Engine

Several services can run in a Kubernetes cluster. Kubernetes Ingress is an API object which provides routing rules to direct the external users’ access into the correct service. The Ingress consists of an Ingress Controller and an Ingress Resource. Ingress Resource is a collection of rules for the inbound traffic to reach the services. The Ingress Resource is defined by us specifying paths and their services. Ingress Controller acts upon rules defined in Ingress Resource.

NGINX is one of the most common Ingress Controllers we use. Use below commands to deploy NGINX Ingress Controller.

Commands

  1. Add the nginx-stable Helm repository in Cloud Shell.

helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx

helm repo update

2. Deploy an NGINX controller Deployment and Service.

helm install nginx-ingress ingress-nginx/ingress-nginx

3. Check whether you have deployed correctly.

You have deployed the NGINX Ingress controller successfully!

4. How To Install Cert Manager On GKE

HTTP is an application layer protocol which deals with web content. The data transferred by HTTP is not encrypted. So, data is not secure at all. Because of that, HTTPS comes into the picture, which creates a secure HTTP connection encrypting the data transferred between the client and the server. In HTTPS, certificates are used to authenticate the identity of the website. They are issued by the web server to the clients. After getting the certificate, the client replies back with acknowledgement. Then, encrypted data can be transferred.

Now, we have the question.What is the Cert Manager?

Cert-Manager adds certificates and certificate issuers to Kubernetes clusters as resource types, making the process of obtaining, renewing, and utilizing certificates easier. It can issue certificates from Let’s Encrypt, HashiCorp Vault, and Venafi, among other approved sources.

Use below commands to install Cert Manager on GKE.

  1. Create a namespace to run cert-manager

kubectl create namespace cert-manager

2. Install Cert Manager

kubectl apply — validate=false -f https://github.com/jetstack/cert-manager/releases/download/v0.13.1/cert-manager.yaml

kubectl create clusterrolebinding cluster-admin-binding \ — clusterrole=cluster-admin \— user=$(gcloud config get-value core/account)

--

--