Google cloud offers its own managed Kubernetes cluster setup using google container engine aka GKE. If you use GKE you can avoid the Kubernetes administrative overhead as it is taken care by Google cloud. You just need to focus on deploying applications on Kubernetes.
Prerequisites: To follow this tutorial, you should have a Google Cloud account and google cloud SDK installed on your system. If you don’t have google cloud SDK installed, you can follow this tutorial for the setup –> Google cloud SDK setup
Setting Up Kubernetes Cluster On Google Cloud
In this tutorial, we will guide you through the steps for setting up a highly available multi zone kubernetes cluster. Follow the steps given below for the setup.
Step 1: We will launch a multi-zone cluster using the gcloud CLI. The syntax for launching a kubernetes cluster is given below.
gcloud container clusters create [cluster-name] \ --zone [primary-zone] \ --additional-zones [secondary-zones] \ --num-nodes [number of nodes per zone] \ --machine-type [machine size]
In this example, I am spinning up the cluster in
asia-east1 region with one instance per zone (total three zones) using
g1-small(1.7GB) machine type. The actual command would look like the following.
gcloud container clusters create devopscube-demo-cluster \ --zone asia-east1-a \ --additional-zones asia-east1-b,asia-east1-c \ --num-nodes 1 \ --machine-type g1-small
Now, if you check the google compute engine dashboard, you can see three instances launch in three different zones as shown below.
Step 2: You can get all the information about the GKE cluster using the following command.
gcloud container clusters describe [cluster-name] --zone [zone id]
gcloud container clusters describe devopscube-demo-cluster --zone asia-east1-a
Kubectl is a command line utility for interacting with the kubernetes cluster. You can get more information about kubectl from here
To install kubectl component, execute the following gcloud command.
gcloud components install kubectl
Now, you can get your cluster info using kubectl command using the following command.
Accessing Kubernetes Dashboard
Kubernetes has a web UI where you can monitor and manage your deployed application. The web UI is a part of Kubernetes so you cannot access it from google cloud dashboard. You can read more about the web dashboard from here. Follow the steps given below to access the web UI.
1. Head over to google cloud dashboard –> Container Engine –> Container Clusters. There you will find a connect option as shown below. Once you click the connect button, you will see a pop up with two commands.
Popup will look like the following.
2. Execute the commands as shown in the pop-up. An example is shown below.
The following command will set the credentials on your local machine to authenticate to kubernetes cluster.
gcloud container clusters get-credentials devopscube-demo-cluster --zone asia-east1-a --project devopscube
Then, you need to start the proxy using the following command.
BY default, you will be able to access kubernetes on http://localhost:8001/ui. You can also run the proxy in different port using the –port flag as shown below.
kubectl proxy --port=8080
You can run the proxy in the background by adding a
& at the end of the command as shown below.
kubectl proxy --port=8080 &
If you access the web UI, by default you will be able to view only the cluster node information as shown below. Once you start deploying applications, you can monitor and manage it from the UI.
Launching a kubernetes cluster on google cloud is very simple as compared to AWS or on-prem data center setups. In the coming series of articles, we will cover more articles on how to deploy and manage applications on a kubernetes cluster.
ONLINE COURSE: The Complete Kubernetes Course
Learn how you can run, deploy, manage and maintain containerized Docker applications on Kubernetes
- Learn to launch kubernetes cluster
- Get started with Containerization of apps
- Deploy applications on kubernetes cluster
- Run stateful and stateless applications on containers