Google Kubernetes Engine

Setting Up GKE Cluster


Google Kubernetes Engine(GKE)  provides a managed and orchestrated environment for running Docker container  and applications within Google's public cloud services. Google Kubernetes Engine is based on Kubernetes, Google's open source container management system. The features provided by GKE are :
  • Identity and Access Management
  • Hybrid Networking
  • Security and Compliance
  • Integrated logging and monitoring
  • Cluster Options
  • Auto Scale
  • Auto Upgrade
  • Auto Repair
  • Resource Limits
  • Container Isolation
  • Docker Image support and so on ...

Creating a Cluster:

Prerequisites:
  • Ensure that you have enabled the Google Kubernetes Engine API. 
  To enable GKE API for a project using the console:
  1. Go to the Cloud Console API Library .
  2. From projects list, select a project or create a new one.
  3. In the API Library, select the API you want to enable. If you need help finding the API, use the search field and/or the filters.
  4. On the API page, click ENABLE.
From the same page you can disable an API for your project if you no longer use it to avoid misuse and accidental billing charges.

  • Ensure that you have installed the Cloud SDK.
For GCP based VM instances, gcloud SDK will be already installed.Incase from other ubuntu systems, follow below steps to install gcloud SDK.

Install gcloud SDK.

# Add the Cloud SDK distribution URI as a package source
echo
"deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list

# Import the Google Cloud Platform public key
curl https
://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -

# Update the package list and install the Cloud SDK
sudo apt
-get update && sudo apt-get install google-cloud-sdk

Initialize the SDK
  • Run the following at a command prompt:
gcloud init
  • Accept the option to log in using your Google user account:
To continue, you must log in. Would you like to log in (Y/n)? Y
  • In your browser, log in to your Google user account when prompted and click Allow to grant permission to access Google Cloud Platform resources.
  • At the command prompt, select a Cloud Platform project from the list of those where you have OwnerEditor or Viewer permissions:
Pick cloud project to use:
 [1] [my-project-1]
 [2] [my-project-2]
 ...
 Please enter your numeric choice:
  • If you have access to more than 200 projects, you will be prompted to enter a project id, create a new project, or list projects.
This account has a lot of projects! Listing them all can take a while.
 [1] Enter a project ID
 [2] Create a new project
 [3] List projects
Please enter your numeric choice:
  • If you have the Google Compute Engine API enabled, gcloud init allows you to choose a default Compute Engine zone:
Which compute zone would you like to use as project default?
 [1] [asia-east1-a]
 [2] [asia-east1-b]
 ...
 [14] Do not use default zone
 Please enter your numeric choice:
  • gcloud init confirms that you have complete the setup steps successfully:
gcloud has now been configured!
You can use [gcloud config] to change more gcloud settings.

Your active configuration is: [default]


Creating a Cluster:

cluster consists of at least one cluster master machine and multiple worker machines called nodes. Nodes are Compute Engine virtual machine (VM) instances that run the Kubernetes processes necessary to make them part of the cluster. You deploy applications to clusters, and the applications run on the nodes.

The following command creates a one-node cluster. Replace cluster-name with the name of your cluster:

         
  • cluster-name: the name of your new cluster.
  • compute-zone: the compute zone in which to create the cluster.
  • channel: the type of release channel, which can be one of rapid, regular, or stable. Clusters enrolled in the rapid channel are not supported for production workloads.
  • version: the version you wish to specify for your cluster.

Get authentication credentials for the cluster:

After creating your cluster, you need to get authentication credentials to interact with the cluster and this command  configures kubectl to use the cluster you created:

gcloud container clusters get-credentials cluster-name

Create Deployment:

Now that you have created the cluster, you can run the containerized app.But before deploying the containerized app, you need to create a deployment where you can deploy and run the application.

kubectl create deployment deployment-name --image=gcr.io/google-samples/imagename:version
  • --image specifies a container image to deploy. In this case, the command pulls the example image from a Container Registry bucket

Expose Deployment:

After deploying the application, you need to expose it to the internet so that users can access it. You can expose your application by creating a Service, a Kubernetes resource that exposes your application to external traffic.

kubectl expose deployment service-name --type LoadBalancer \
  --port 80 --target-port 8080    
  • --type LoadBalancer : creates a Compute Engine load balancer for your container.
  • --port : initializes public port 80 to the internet
  • --target-port : routes the traffic to port 8080 of the application.

Inspecting and viewing the application:

Inspect the running pods by using 
kubectl get pods

Inspect the service by using 
kubectl get service service-name
From the above commands output , copy the  Service's external IP address from the EXTERNAL-IP column

View the application from web browser using the external IP address with the exposed port

http://external-ip/


You have deployed your first app in Google Kubernetes Engine !!!

Comments

Post a Comment

Popular posts from this blog