Website Deployment using Google Kubernetes Cluster on GCP

The article explains how to launch a website, on the Kubernetes cluster using GKE and Load Balancer services provided by Google Cloud Platform.

Kubernetes is one tool that helps in container orchestration. Google provides a superb way to manage Kubernetes services, through GKE (Google Kubernetes Engine). Kubernetes deployments help us in launching and saving the information in case of accidental deletion.

Working in a Kubernetes cluster increases the flexibility of resource usage. Now the available resources are not limited to resources of one node only. The master node will decide in which slave node a pod will be launched.

Load Balancer basically manages the traffic coming from the internet. It will direct the traffic according to the availability of nodes. In this scenario, no particular node will get high traffic and hence no server will crash providing clients a smooth service.

In Kubernetes, we can make our load balancer, but Google also provides a service for load balancers.


The entire steps are broadly divided into four parts:

  1. Create a Virtual Private Cloud(VPC) and a lab in it.
  2. Launch the Kubernetes Cluster in the same network(Lab) having 3 nodes.
  3. Launch web server pods in nodes and add the webpage files.
  4. Create a load balancer for the cluster and access the webpages using public IP provided by LB.

Below is a detailed description of the project procedure.

— — —

STEP1: Launch a Kubernetes cluster.

Select “Clusters” from the Kubernetes Engine option in the main menu.

Press the button “Create Cluster”.

Now we are supposed to fill in the details about the cluster to be launched.

First: Entered the details about like name of the cluster, region of the clustser, etc.Second: Set the number of slaves in the cluster.Third: Main thing in this section was to decide which machine to be launched.Fourth: In this Networking section, I selected the VPC and a lab in which the cluster will be.

Press the create button, and the launched cluster can be seen in the list.

— — —

STEP2: Install Google Cloud SDK

To establish a connection between our local system and cloud we need to prepare the setup for the same. All we have to do is download Google Cloud SDK and the procedure is explained in detail here.

— — —

STEP3: Connect your GCP Kubernetes Cluster to your local cloud shell.

There is an option to connect in front of the Cluster Name. The command to connect with the cluster will pop up.

Run the command on the shell. Now the shell will be connected

>kubectl.exe get nodes 
//will list all the nodes running in the cluster.
>kubectl.exe get pods
//will list all the pods running in the cluster.
// initially no pods are launched.

One drawback of using pods is that by chance it gets deleted all the data will be lost. To counter this issue one must deployments. In the case of deployments, if by chance a pod is deleted, Kubernetes will another pod with the same configuration and data.

>kubectl.exe create deployment deploy_name --image=image_name
//this command will launch a deployment with by default one pod.

Below is an illustration of how relaunching a pod after deletion works.

— — —

STEP4: Launch the Load Balancer.

A load balancer program is used to balance the traffic such no particular node gets all the traffic and another sits idle.

In Kubernetes, we can its own load balancer, but in this project, we will use the Load Balancer Service GCP provides.

>kubectl.exe expose deployment deploy_name --type=LoadBalancer --port=80
//this command will expose the port 80 of pods to the load balancer.

In the “Kubernetes Engine>>Workloads” section we can see all the load balancers launched.

— — —

STEP5: Store webpage files on the webserver.

The below image shows how to add an HTML file at usr/local/apache2/htdocs/ in the httpd docker container.


<!DOCTYPE html><html><head><style>body {
background-image: url('');
</style><title> WEBPAGE IN CLUSTER</title></head><body><h2 align = 'center' style="font-family:courier; font-size:200%; color:white; ">THIS WEBPAGE IS LAUNCHED USING GOOGLE KUBERNETES CLUSTER</h2></body></html>

— — —

STEP6: Access the website.

On clicking the load balancer, we can see all the detail of the balancer. At bottom of the page, we will get our IP address of the webpage

We will run the IP address on our local web browser. And in the below image, we can see that our website is launched.

In place of the httpd docker image, we can also create a dockerfile with Jenkins installed to automate the process and reach out to the developer or operations team in case of failure.




Happy Reading❤❤❤❤….

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store