Working Up With Google Kubernetes Engine In Google Cloud Platform

Introduction 

 
In this article, we will learn How to get started with GKE i.e. Google Kubernetes Engine in Google Cloud Platform. GKE provides the easiest and simplest way to set up the Kubernetes cluster. Kubernetes (K8s) is an Open Source system for automating deployment, scaling, and management of the containerized applications.
 
Here are a few articles that I already wrote and might be helpful for you if you are beginning with Google Cloud Platform:
Let’s begin.
 
Step 1
 
Log in to the Google Cloud Platform by visiting https://console.cloud.google.com/ (Google provides $300 as a free trial, but for that, you need to link your credit card).
 
Working Up With Google Kubernetes Engine In Google Cloud Platform
 
Once logged in, you will be redirected to the dashboard of the Google Cloud Platform.
 
Working Up With Google Kubernetes Engine In Google Cloud Platform
 
Step 2
 
Before creating a Kubernetes cluster, we need to make sure that Kubernetes Engine API and Container Registry API. Click on Dashboard Submenu available under API & Services Menu.
 
Working Up With Google Kubernetes Engine In Google Cloud Platform
 
Search Kubernetes Engine API and Container Registry API and make sure that both API Status is Enabled.
 
Working Up With Google Kubernetes Engine In Google Cloud Platform
 
Working Up With Google Kubernetes Engine In Google Cloud Platform
 
Step 3
 
We can create the Kubernetes Cluster either by Google Cloud Shell or with Google Cloud Console. Let’s see how to create the Kubernetes cluster in both ways. Click on Google Cloud Shell Icon in order to connect with google cloud through the command line.
 
Working Up With Google Kubernetes Engine In Google Cloud Platform
 
For ease, let’s wet up the environment variable MY_ZONE and pass the zone in which we want to create our Kubernetes Cluster. We can also pass the zone directly in the command without using the environmental variable.
 
Working Up With Google Kubernetes Engine In Google Cloud Platform
 
Step 4
 
Create the Kubernetes Cluster with the below command in Google Cloud Shell.
 
gcloud container clusters create <NAME_OF_CLUSTER> --zone $MY_ZONE –num-nodes 2
 
Working Up With Google Kubernetes Engine In Google Cloud Platform
 
You can also pass the –machine-type if want a specific machine type configuration in the above command. On running the above command, you will see the message like shown in the below image on the successful creation of the Kubernetes Cluster.
 
Working Up With Google Kubernetes Engine In Google Cloud Platform
 
We can also check the Cluster by clicking on Clusters submenu of the Kubernetes Engine menu.
 
Working Up With Google Kubernetes Engine In Google Cloud Platform
 
You can see the Kubernetes Cluster created by us in the above steps with Cluster size as 2.
 
Working Up With Google Kubernetes Engine In Google Cloud Platform
 
We can also create the Kubernetes Cluster by clicking on the create cluster button and providing the Cluster Details like Cluster Name, Location as well as details related to the Nodes like the size of Nodes, enable autoscaling.
 
Working Up With Google Kubernetes Engine In Google Cloud Platform
 
Working Up With Google Kubernetes Engine In Google Cloud Platform
 
Now, let’s check the VM Instances created by Clicking VM Instances Sub menu in Compute Engine Menu. You can clearly see that 2 VM Instances are up and ready for use.
 
Working Up With Google Kubernetes Engine In Google Cloud Platform
 
Working Up With Google Kubernetes Engine In Google Cloud Platform
 
Step 5
 
Kubernetes command-line tool i.e. Kubectl allows us to run the command against the Kubernetes cluster. In case you need to check the kubectl version use kubectl version command.
 
Working Up With Google Kubernetes Engine In Google Cloud Platform
 
Let’s deploy the Nginx image with the kubectl command as shown below. You can use an image as per your need. In Kubernetes, all containers run in a pod. If pod count not provided, a single pod will be created. 
 
Working Up With Google Kubernetes Engine In Google Cloud Platform
 
Now let’s check the status of the pods with kubectl get pods command. In the below image, you can clearly see the status of the Pod is running.
 
Working Up With Google Kubernetes Engine In Google Cloud Platform
 
Once all pods are in running state, we can expose the ngnix cluster as an external service. Expose the ngnix cluster as an external service. The below command will create a network load balancer to balance the network traffic.
 
Working Up With Google Kubernetes Engine In Google Cloud Platform
 
Now, run kubectl get services and check the External_IP assigned against the Load balancer. It will take around a minute to see the value of External_IP. If not shown, wait for a minute and re-run the command to check again the External_IP.
 
Working Up With Google Kubernetes Engine In Google Cloud Platform
 
Step 6
 
Visit the external IP to see that server is being served through the load balancer.
 
Working Up With Google Kubernetes Engine In Google Cloud Platform
 
We can scale up pods running for the service with the below command.
 
Working Up With Google Kubernetes Engine In Google Cloud Platform
 
Once executed, we can check the number of pods with the kubectl get pods command. We can clearly see that now pods count is increased to 3.
 
Working Up With Google Kubernetes Engine In Google Cloud Platform
 
Let’s again check the external IP associated with load balancer service with the kubectl get services. On Increasing the pods/replica, our associated external I.P. is not affected.
 
Working Up With Google Kubernetes Engine In Google Cloud Platform
 
Again, access the application with the browser by using the external I.P. Address. Our application is still running in perfect condition after scaling up the application.
 
Working Up With Google Kubernetes Engine In Google Cloud Platform
I hope this article will help you get started with Google Kubernetes Engine in Google Cloud Platform.