Steps to create a GKE cluster in GCP and Deploy Application

Steps to create the GKE using the Console

Step 1: On the GCP console, navigate to Kubernetes Engine then click on Clusters. On the cluster page, click Create. If you want to manage your cluster on your own, then select standard; otherwise, select autopilot mode, which manages the cluster automatically. Once you decide, click on configure.

 

Step 2: Type your desired cluster name and select the GCP region where you want to create a cluster.

 

Step 3: Click Next and select your network and subnet. For now, we have selected the default network. Choose your network access. Select public if you want to access the cluster from the internet else select private.

 

Step 4: Select the pod IP address range and service IP range. Specify tags if you want.

 

Step 5: Click next and configure advanced settings accordingly else leave it to default. Then click review and create. After review click create. The cluster deployment will take around 7-10 minutes. On the overview page, if the status shows a green checkmark, then your cluster is ready to use.

 

 

Steps to Deploy a Container in the GKE Cluster

Step 1: On the cluster overview page click on deploy. Specify your container image you can select an existing image or create a new image. For this tutorial, we are using the default nginx template image. You can specify the init command according to your application.

 

Step 2: Click Continue. Under Configuration specify your application/deployment name. you can add a label apart from the default app label. You can also add a YAML file for configuration details. Then select your GKE cluster from the list.

 

 

Deploy a Service

Step 3: Click Continue. Check Expose deployment as a new service. This will allow our nginx server to be exposed to the internet. Specify ports accordingly. Keep everything else default and click Deploy. Once the deployment is successful go to Workloads from the sidebar. Select the deployed app from the overview page. On the deployment overview page, you can view containers and pods.

 

Step 4: Finally, scroll to the bottom to see the exposed service.

View a deployed app

Step 5: Click on Endpoint URL to view the application in the browser. In our case, we will see the default NGINX page.

Steps to create GKE cluster using the gcloud CLI

CLI Environment Setup

By enable the cli environment using the cloud shell on the google cloud platform. We need to click the cloud shell icon and authorize to enable the cloud shell. We will get the terminal like as shown in the step one.

Step 1: To initialize the gcloud CLI, run the following command:

gcloud init

  • Authentication: It assists you with logging into your Google Cloud account first. Because it confirms that you have the right authorization to access and control resources on Google Cloud, this step is crucial.
  • Project Configuration: It then prompts you to choose an existing project or start a new one. On Google Cloud, a project is similar to a folder where you arrange your services and resources. You can instruct the SDK on where to deploy your apps or keep your data by selecting a project.
  • Region and Zone Selection: You can also select the default zone and area. Zones are distinct areas inside regions, which are geographical areas that offer Google Cloud services. You may maximize the functionality and accessibility of your apps and services by choosing a zone and location.
  • Configuration Files: Finally, your computer’s configuration files are created or updated by “gcloud init.” Your project settings, authentication credentials, and Google Cloud account information are all stored in these files. They facilitate your local machine interaction with Google Cloud services.

Step 2: Create the cluster using the below command.

gcloud container clusters create-auto gfg-gke-cluster --location us-central1

  • gcloud: This is the Google Cloud Platform command-line interface (CLI) utility for utilizing GCP resources.
  • container clusters create-auto: gcloud is instructed to establish a new Kubernetes cluster with auto mode enabled in this section of the program. GKE can handle node provisioning and management, as well as other underlying infrastructure management, for you when you choose auto mode.
  • gfg-gke-cluster: The new Kubernetes cluster is referred to by this name. The name you want for your cluster can be substituted for “gfg-gke-cluster.”
  • --location us-central1: The region the fact that cluster will be located in is indicated by this flag. The cluster will be established in the us-central1 area in this instance. Any other location with GKE accessibility can be used in place of us-central1.

Step 3: Verify the nodes in the Kubernetes cluster

kubectl get nodes

  • kubectl: Utilizing this command-line tool, one may communicate with Kubernetes clusters. It gives you the ability to oversee different facets of Kubernetes, including resource inspection, cluster configuration management, and application deployment.
  • get: This action verb instructs Kubectl on the operation you wish to carry out. Here, you are requesting that kubectl obtain data regarding a certain subject.
  • nodes: This is the particular kind of resource you are trying to find out more about. A real or virtual machine used as a worker machine in a cluster is referred to as a “node” in the Kubernetes language. Your apps execute on nodes.

Step 4: Verify the all pods in the GKE cluster by following the below command.

kubectl get pods -A

Deploying Nginx App to GKE

Step 5: Deploy the nginx pod in the GKE cluster. Here is the command to apply the nginx yaml.

kubectl apply -f nginx.yaml

apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
spec:
containers:
- name: nginx-container
image: nginx:latest
ports:
- containerPort: 80
  • apiVersion: Indicates the Kubernetes API version that you are currently using.
  • kind: Establishes the kind of Kubernetes resource you are building. This instance involves a Pod, the smallest deployable Kubernetes unit.
  • metadata: Includes details on the Pod, including its name.
  • spec: Explains the Pod’s specifications, including those of its containers.
  • containers: Gives the list of containers that are currently operating in the pod.
  • name: Name of container.
  • image: Docker image that the container should utilize. It is the most recent Nginx image in this instance.
  • ports: Indicates which ports the container is open to.
  • containerPort: The port is the location that the container watches for new traffic coming in. The port in question is 80, which is the standard port for HTTP communication.

Step 6: Get the deployed pods on the GKE cluster.

kubectl get pods

Step 7: Here is the nginx was deployed on GKE verify by uisng the console.

Monitoring the Applications

kubectl top pods
  • kubectl: The command-line tool for interacting with Kubernetes clusters is this one.
  • top: Resource use statistics are shown using this kubectl subcommand.
  • pods: We especially want to collect resource utilization data for pods, as indicated by this option.

Clean up

Step 8: Delete the pod by following the below command.

kubectl delete -f nginx.yaml

Step 9: Delete the GKE cluster by following the below command.

gcloud container clusters delete gfg-gke-cluster --zone=us-central1

Creating a GKE Cluster and Deploying a Container

In this article, we are going to see how we can create a Google Kubernetes Engine Cluster for deploying a containerized application. We are also going to see how we can deploy a containerized application in this cluster. We will use a simple application developed by GCP (Google Cloud Platform), which runs through an NGINX server. So, let’s get to it.

Similar Reads

Key Technologies

GKE Cluster: The Google Kubernetes Engine Cluster is a collection of VM nodes and a master node called a Cluster control plane. The master node handles the worker nodes while the application is run by worker nodes. Container: A container is a small package of applications with its dependencies. Containerized Application: Containerized application is software that runs in isolated containers....

Steps to create a GKE cluster in GCP and Deploy Application

Steps to create the GKE using the Console...

Conclusion

It is simple to deploy applications on Google Kubernetes Engine (GKE) using either the GCP console or the gcloud CLI. By using one of the two methods, you can streamline the deployment process for modern apps by initializing the CLI, creating a GKE cluster, deploying containerized applications, and accessing them using the specified endpoint URL....

GKE Cluster and Deploying a Container – FAQs

What is the difference between cluster and container?...