Kubernetes has come out to be one of the most popular opensource container orchestration tool. It’s effectiveness in deploy, manage and scaling of containerized applications is without doubt. But, the complexity it brings requires a steeper learning curve and could be a deterrent for wider adoption.
All major cloud service providers have come up with it’s easy adoption by offering container orchestration as a managed service, often termed as Container as a Service (CaaS). The three major Kubernetes managed services currently offered are Azure Kubernetes Service (AKS) , Amazon Elastic Kubernetes Service (EKS) and Google Kubernetes Engine (GKE). GKE is a Google Cloud Platform (GCP) offering and is one of the simpler ones to use with many out of the box features and automated capabilities.
This blog is a quickstart to deploy and manage (or do not have to manage) contanerized applications in GKE
- An understanding of Kubernetes,
- familiarity with Google Cloud command-line tool –
- familiarity with Kubernetes command-line interface –
- access to GCP for performing a hands on.
Log on to GCP console and select a project.(you can also create a new project for this exercise)
Search and enable below APIs from Navigation Menu -> APIs & Services -> Library
– Artifact Registry API
– Kubernetes Engine API
Activate Google Cloud Shell. Cloud Shell comes pre-installed with
Set default project, region and zone
gcloud config set project <PROJECT ID> gcloud config set compute/zone <ZONE> e.g northamerica-northeast1-a gcloud config set compute/region <REGION> e.g. northamerica-northeast1
Creating GKE cluster
A cluster consists of at least one cluster control plane 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.
To create clusters in GKE, you need to choose a mode of operation: Standard or Autopilot.
To create Standard cluster gcloud container clusters create hello-cluster --num-nodes=1 To create cluster in Auto-Pilot gcloud container clusters create-auto hello-cluster
Cluster creation is usually quick and will take a few minutes to setup depending on the number of nodes selected and any additional properties. Alternately you can run into an errors if you do not have billing enabled for GKE ; do not have enough quota for Compute engine CPU and in-use IP address ; have not enabled the required API services.
After creating your cluster, you need to get authentication credentials to interact with the cluster.
gcloud container clusters get-credentials hello-cluster
Verify cluster details after successful completion either from command line , or from GCP portal.
Deploying an application to the newly created cluster
Here we are deploying a sample web application image by using standard Kubernetes commands.
kubectl create deployment hello-server \ --image=us-docker.pkg.dev/google-samples/containers/gke/hello-app:1.0
Verify application deployment
kubectl get deployments
Verify Running pods and service health
kubectl get pods kubectl get service hello-server
After deploying, we can expose it for external internet traffic
kubectl expose deployment hello-server --type LoadBalancer --port 80 --target-port 8080
View application from an external browser
And here we have a web application running on a cluster and accessible over the internet. You can play with cluster properties to fine tune the number of nodes, add – remove node pools, enable/disable auto-scaling, change kubernetes node properties, etc either through command-line Cloud Shell or by using GCP portal Main Navigation Menu -> Compute -> Kubernetes Engine -> Cluster
Application service can be removed either from portal or by using
kubectl delete service hello-cluster
You can delete your cluster after practice to avoid incurring additional billing charges
gcloud container clusters delete mystandard-cluster