How To Setup and Configure Kubernetes Cluster On Google Cloud (GCE)

Setup Kubernetes Cluster On Google Cloud

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.

google container engine instances

Step 2: You can get all the information about the  GKE cluster using the following command.

Syntax:

gcloud container clusters describe [cluster-name] --zone [zone id]

Example Command:

gcloud container clusters describe devopscube-demo-cluster --zone asia-east1-a

Kubectl Utility

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.

kubectl cluster-info

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.

kubernetes dashboard

Popup will look like the following.

connecting kubernetes dashboard

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.

kubectl proxy

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.

kubernetes dashboard

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.


Kubernetes2

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

 

Setup Kubernetes Cluster On Google Cloud

How to Setup and Configure Docker Swarm Cluster

docker swarm

In this tutorial, you will learn how to set up a four node docker swarm cluster.

Prerequisites

  • Minimum two nodes with Docker installed ( swarm manager and cluster nodes)
  • All the nodes should be able to talk to each other using public or private IP addresses.

In this setup, I have total 4 nodes. 1 Swarm manager node and three other nodes to join the cluster with the following private IP addresses

Manager - 10.140.0.2
Node1   - 10.140.0.6
Node2   - 10.140.0.4
Mode3   - 10.140.0.5

Follow the steps given below for a multi node swarm cluster.

On Manager Node

1. Execute the following command with the manager nodes IP for initializing the swarm cluster.

docker swarm init --advertise-addr <MANAGER-IP>

For example,

docker swarm init --advertise-addr 10.140.0.2

You will get the following output once swarm is initialized.

[[email protected] ~]$ docker swarm init --advertise-addr 10.140.0.2
Swarm initialized: current node (0qjtv7kblhbrbub4yyk1tq1e7) is now a manager.

To add a worker to this swarm, run the following command:

    docker swarm join \
    --token SWMTKN-1-3l50pb6ko5ci23134wzt17gqkb4nsbv4e52ciwdwq80hmmx1si-d3kv6s6qtgf0crqmz9dxix2oc \
    10.140.0.2:2377

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

[[email protected] ~]$

As you can see, the output has the steps to join other nodes to this swarm manager node.

[irp posts=”647″ name=”Jenkins Tutorial For Beginners – Getting Started Guide”]

2. To know the swarm cluster info, execute the following command.

docker info

In the output, you will see the following.

Swarm: active
 NodeID: 0qjtv7kblhbrbub4yyk1tq1e7
 Is Manager: true
 ClusterID: zj0ioxrvl0tsyxasbhwyu947l
 Managers: 1
 Nodes: 1

3. To know the information about all the nodes in the cluster, you can run the following command.

docker node ls

On Node 1, 2 and 3

Now that we have the swarm manager ready, we can add our other nodes to the manager to form a multi node cluster.

1. Execute the swarm join command from the manager output on all the extra nodes as shown below. The swarm token and IP will change based on your environment.

Note: You can get the swarm token with the command by executing docker swarm join-token worker on the manager node.

sudo docker swarm join \    
--token SWMTKN-1-3l50pb6ko5ci23134wzt17gqkb4nsbv4e52ciwdwq80hmmx1si-d3kv6s6qtgf0crqmz9dxix2oc  \
10.140.0.2:2377

Swarm Configuration and Testing

1. Once you joined all the extra nodes, you can list the swarm node information by executing the following command on the manager node.

sudo docker node ls

You will get the output will the swarm cluster info as shown below.

[[email protected] ~]$ sudo docker node ls
ID                           HOSTNAME     STATUS  AVAILABILITY  MANAGER STATUS
0qjtv7kblhbrbub4yyk1tq1e7 *  manager  Ready   Active        Leader
adig05zbyuxt4x0oltrbrc523    node2        Ready   Active        
bzupprwwasy6vvwh4hn0s4txz    node1        Ready   Active        
ug20slq1qyk6uzwgfv3a5zd86    node3        Ready   Active

Now our cluster is ready. You can start deploying applications to your swarm cluster.


logoONLINE COURSE:  Docker Mastery: The Complete Toolset From a Docker Captain

Check out the docker course which thousands of students have already enrolled.

  • Learn Docker and Compose
  • Best practices for making Dockerfiles
  • Learn to build multi node swarm cluster
  • Rolling application deployments without downtime

 

docker swarm