This blog post will take you through the steps to deploy an application to a GKE Cluster.
Google Kubernetes Engine is a tool developed by Google which helps manage a group of machines, known as a cluster. GKE has a number of applications, one of them being deploying an application, which we will cover here. In this blog post, we will go through the following topics:
Introduction to GKE Clusters
Clusters are essentially the backbone of the Google Kubernetes Engine system. All objects that are part of Kubernetes run atop clusters. These include all the containerized applications, for which the cluster acts as a platform. A cluster consists of at least one Control plane or cluster master machine, and multiple worker machines called nodes. These worker machines are typically the Google Compute Engine VM instances, which are created by Google once a cluster is created. The type of the machine can be specified at the time of the creation of the cluster. Clusters under GKE can be either “standard mode” or “autopilot mode”, depending on the level of control that the user wants over the functioning.
To learn more about Google Kubernetes Engine and its architecture, read our blog on Google Kubernetes Engine.
Nodes are Compute Engine virtual machine (VM) instances that run the Kubernetes processes necessary to make them part of the cluster. These Control planes Node machines run the Kubernetes cluster orchestration system.
Pods and Deployment
Pods are the most basic and smallest deployable objects in Kubernetes. A Pod represents one instance of a running process in the cluster. Pods may have one or more containers. When a pod runs multiple containers, the containers are managed as a single entity and share the pod’s resources.
Deployments represent a number of identical pods with no unique identities. A GKE Cluster deployment runs several replicas of the application and automatically replaces any instances that fail or become unresponsive. Thus, deployments make sure that one or more instances of your application are available to serve user requests. Deployments are managed by the Kubernetes Deployment controller.
Steps to Deploy Application on GKE Cluster
Now that we have a brief idea about Google Kubernetes Engine and deployment terms, let’s deploy an application on GKE Cluster.
Pre-Requisite
Before we begin, here are some prerequisites for the lab:
1.) It is assumed here that you have a working Google Cloud account, with access to Google Console. In case you don’t already have that, please follow the steps from our blog on Google Cloud Free Account to create your Google Cloud account.
2.) Once you have an account, you need to ensure that the Kubernetes Engine API is enabled on the Cloud Console, and Cloud Shell is activated. You can learn more about the console in our blog on Google Cloud Platform Console Walkthrough.
To enable Kubernetes Engine API and Cloud Shell, follow these steps:
- Navigate to the Google Cloud Console homepage and sign in using your credentials.
- In the menu on the left, select Kubernetes Engine. Click on the enable button.
- To activate Cloud Shell, press on the icon right next to the search bar at the top. This is where all commands will be entered.
Steps
1.) Select a Default Compute Zone
The Compute Zone helps set a ballpark as to where the physical location of the clusters and resources will be.
To set your default compute zone, run the following command in the cloud shell:
gcloud config set compute/zone us-central1-a
Note: If you wish, you can change us-central1-a to a zone of your choice.
2.) Create a Cluster
Create a Cluster by executing the following command:
gcloud container clusters create [CLUSTER-NAME]
Note: Replace [CLUSTER-NAME] with a unique name of your choice.
3.) Authenticating the Cluster
To interact with your cluster, it is imperative that you get the authentication credentials for the same.
To authenticate the cluster, run the following command:
gcloud container clusters get-credentials [CLUSTER-NAME]
Note: Replace [CLUSTER-NAME] with the name of your cluster.
4.) Deploy an Application to the GKE Cluster
As somewhat of a test run, we’ll go ahead and deploy the hello-app application in the newly created cluster.
- The first step for that is to create a server. To do that, run the following command
kubectl create deployment hello-server –image=gcr.io/google-samples/hello-app:1.0
- Next, you need to specify which service to use, to make your application visible to others. To do that, create a Kubernetes service by running this command
kubectl expose deployment hello-server –type=LoadBalancer –port 8080
- Now you need to inspect our server to find out our external IP. For that, use the following command
kubectl get service
- Finally, to view the application from your browser, use the following command
https://[EXTERNAL-IP]:8080
Be sure to replace [EXTERNAL-IP] with the IP gotten in the previous step
There you go! You have deployed your first containerized application to the GKE cluster.
Conclusion
This was a small guide describing the steps to deploy an application to a GKE Cluster It goes without saying, that one can also deploy more complex applications using the same method. In addition to that, clusters provide an efficient way to manage multiple applications deployed on the cloud and access them as per the user’s need.
Cluster Computing gets a number of Virtual Machines to work together and solve a task. They manage multiple nodes (which contain applications) and assign tasks to them, which facilitates the smooth functioning of the deployed application.
FAQs
- What’s the difference between a container and a cluster?
A container contains an application and runs in a pod. A group of such pods together constitute a cluster. - Is deploying applications on a cluster free of cost?
The Google Cloud Free-Tier account allows for one free zonal cluster per account. In case you need more, it shall be provided on a pay-per-use basis. - Who all can view the application deployed on the cluster?
The permissions for the specific applications can be set at the time of deployment and changed thereafter from settings.
Related References
- GCP Associate Cloud Engineer: All You Need To Know About
- GCP Professional Cloud Architect: Everything You Need To Know
- Introduction To Google Cloud Platform
- Google Cloud Services & Tools
Next Task For You
We have a complete module dedicated to Google Kubernetes Engine and deployment.
If you are also interested and want to know more about the Google Cloud Associate Cloud Engineer certification then register for the Free Class.
The post Deploying An Application To A GKE Cluster appeared first on Cloud Training Program.