Turorial - Using GCP GKE to create a Kubernetes cluster

imt

1. Objective

We are going to setup a Kubernetes cluster on GKE (Google Kubernetes Engine) manually by using free credits I’ve requested for teachings.

Important
Credits are limited to 50$! make sure to destroy the cluster after the project
Note
We will use Terraform to automate such GKE provisioning later in this teaching unit

2. Install Google Cloud CLI gcloud on your machine

3. Install Kubernetes CLI kubectl on your machine

Note
if you prefer you can also build a Docker image with gcloud and kubectl or try to find an existing one, and then run the container in interactive mode with a bash (see the tutorial on the Docker CLI)
Note
gcloud can also install kubectl for you with > gcloud components install kubectl

4. Create a Google Cloud Platform account and get your credits

  • Create an account on GCP with a personal gmail address

  • You received from me a "coupon" email for credits on GCP, follow these instructions to get your credits on your account

Important
Use your alias email address prenom.nom@imt-atlantique.fr

5. Create a project on GCP

Create a new project on the GCP web interface

gcp2

Give a name to the project and associate this project (for example login-k8s) with your educational credits!

gcp3

6. Activate services

To be able to interact with GCP outside the web interface we also need to activate some services. In this course we need:

  • Kubernetes Engine API

Go to the APIs library.

apis3

7. Setup gcloud and use it to create a Kubernetes cluster

You first have to setup your authentication to GCP.

> gcloud auth login

You then have to set the project on which you want to work.

> gcloud config set project PROJECT-ID

You can now create a Kubernetes cluster by using the command gcloud container clusters create (documentation)

> gcloud container clusters create NAME-CLUSTER --machine-type n1-standard-2 --num-nodes 3 --zone us-central1-c

Above we ask for three worker nodes in the cluster with machines of type n1-standard-2

The deployment of a Kubernetes cluster takes time so let’s go back to the course after initiating the cluster creation!

created

After clicking on the cluster, click on "se connecter".

connect1

You should see the following window giving you the gcloud command line to connect to your cluster locally on your machine.

connect2

The command should look like this:

> gcloud container clusters get-credentials CLUSTER-NAME --region REGION --project PROJECT-ID

Now you are able to execute kubectl commands on the distant GKE cluster.

> kubectl get nodes

NAME                                  STATUS   ROLES    AGE     VERSION
gke-zeus-default-pool-8d102f6f-0w7m   Ready    <none>   7m41s   v1.27.8-gke.1067004
gke-zeus-default-pool-8d102f6f-gbfl   Ready    <none>   7m42s   v1.27.8-gke.1067004
gke-zeus-default-pool-8d102f6f-h721   Ready    <none>   7m42s   v1.27.8-gke.1067004

You can also do

> kubectl cluster-info

8. Deleting the cluster

> gcloud container clusters delete CLUSTER-NAME --zone us-central1-c

> gcloud config configurations delete CLUSTER-NAME