Quantcast
Channel: Cloud Training Program
Viewing all articles
Browse latest Browse all 1891

How To Setup A Three Node Kubernetes Cluster For CKA: Step By Step

$
0
0

Kubernetes Cluster is a group of node or machines running together. At the highest level of Kubernetes, there exist two kinds of servers, a Master and a Worker node. These servers can be Virtual Machine(VM) or physical servers(Bare metal). Together, these servers form a Kubernetes cluster and are controlled by the services that make up the Control Plane.

If you are new to Docker & Kubernetes world, then check out our blog on Kubernetes for Beginners to get an idea about the components and concepts of Kubernetes.

In this blog, we will cover How to install and configure a three-node cluster in Kubernetes which is the first topic in Kubernetes. We have a set of Hands-on Labs that you must perform in order to learn Docker & Kubernetes and clear the CKA certification exam. Cluster Architecture, Installation & Configuration have a total weightage of 25% in the Exam.

There are 3 ways to deploy a Kubernetes cluster:
1. By deploying all the components separately.
2. Using Kubeadm.
3. Using Managed Kubernetes Services

Kubernetes three node cluster

In this blog, we will be covering the following topics:

Prerequisites For Cluster Setup

Deploying three nodes on-premises can be hard and painful, so an alternate way of doing this can be using a Cloud Platform for deploying them. You can use any Cloud Platform, here we are using Azure Cloud. Before getting on with creating a cluster make sure you have the following setup ready:

I) Create an Azure Free Account, as we will use Azure Cloud for setting up a Kubernetes Cluster.

To create an Azure Free Account, check our blog on Create Free Trial Azure Account.

II) Launch 3 Virtual Machines – one Master Node and 2 Worker Nodes. We are launching these VMs in different regions because in the Azure Free tier account we can’t create 3 virtual machines in a single region due to the service limit. So we are creating One Master node in US East Region and Two Worker node (worker-1, worker-2 in US Southcentral Region)

To create an Ubuntu Virtual Machine, check our blog on Create And Connect An Ubuntu Virtual Machine In Azure.

III) For connecting the worker node with the master node as they are in different regions and in different Vnet, we have to do VNet Peering.

To know more about Virtual Networks, refer to our blog on Virtual Network (VNet) Peering in Azure

Vnet Peering

IV) The Ports specified below are the default Port range for NodePort Services for Master and Worker Nodes.

Ports

Port numbers marked with * are overridable, so we have to make sure that any custom ports we provide are open.

Note: As we are creating a cluster only for testing purpose, so we can open all the Ports rather than opening only specified Port.

Kubenetes clusterThe specifications required for a Node:

  • One or more machines running a deb/rpm-compatible Linux OS; for example Ubuntu or CentOS.
    (Note: We are going to use Ubuntu in this setup.)
  • 8 GiB or more of RAM per machine.
  • At least 4 CPUs on the machine that you use as a control-plane node.

Installing Docker, Kubectl, And Kubeadm Packages

After doing the above-mentioned process, we have to install some packages on our machines. These packages are:

  • Docker  –  is a software responsible for running the containers.
  • kubeadm – a CLI tool that will install and configure the various components of a cluster in a standard way.
  • kubelet – a system service/program that runs on all nodes and handles node-level operations.
  • kubectl – a CLI tool used for issuing commands to the cluster through its API Server.

In order to install these packages, follow the steps mentioned below on Master as well as Worker nodes:

Step 1) We have to do SSH to our virtual machines with the username and password. If you are a Linux or Mac user then use ssh command and if you are a Windows user then you can use Putty.

 
 

Step 2) If you have logged in using another user, then we can switch to root user using the following command:

 
 

sudo command
Step 3) Now we will install the Docker package in our machine using the following command:

To Install Docker on the local system, you can check out the following blog Install Docker on Windows, Ubuntu, Mac

 


Kubernetes clusterTo verify if Docker is installed or not in our VMs, we can check the version of it. To do so use the following command:

 
 

Step 4) We have to download packages like Kubeadm and kubectl using https, so we have to download the https package first. Use the following command for this:

 


installing https cmdStep 5) We have to add the required GPG key to our apt-sources to authenticate the Kubernetes related packages we will install:

 


Gpg keyTo add Kubernetes to the package manager’s list of resources, use the following command:
(Note: Type the following command carefully)

 


kubernetes clusterBefore installing the packages, update the apt-get command:

 


aptget update cmdNow we will install Kubelet, Kubeadm, and kubectl packages into our machines. Run the following command:

 
 

Installing kubeadm, kubelet and kubectlTo hold the installed packages at their installed versions, use the following command:

 

 


Kubernetes clusterCreate A Kubernetes Cluster

As we have successfully installed Kubeadm, next we will create a Kubernetes cluster using the following mentioned steps:

Step 1) We have to initialize kubeadm on the master node. This command will check against the node that we have all the required dependencies. If it is passed, then it will install control plane components.
(Note: Run this command in Master Node only.)

 
 

Kubernetes cluster
You will see a similar output:Kubernetes cluster If cluster initialisation has succeeded, then we will see a cluster join command. This command will be used by the worker nodes to join the Kubernetes cluster, so copy this command and save it for the future use.

Step 2) To start using the cluster, we have to set the environment variable on the master node.
To temporarily set the environment variables on the master node, run the following commands:
(Note: Every time you are starting the Master, you have to set these Environment Variables.)


 


Kubernetes clusterJoin Worker Nodes to the Kubernetes Cluster

Now our Kubernetes master node is set up, we should join Worker nodes to our cluster. Perform the following same steps on all of the worker nodes:

Step 1) SSH into the Worker node with the username and password.

 

Step 2) Run the kubeadm join command that we have received and saved.

 


(Note: Don’t use this same command, use the command that you have received and saved while doing kubeadm init command.)

Kubernetes clusterIf you have forgotten to save the above received kubeadm join command, then you can create a new token and use it for joining worker nodes to the cluster.

 

 


Kubernetes clusterTesting the Kubernetes Cluster

After creating the cluster and joining worker nodes, we have to make sure that everything is working properly. To see and verify the cluster status, we can use kubectl command on the master node:

Using Kubectl get nodes command, we can see the status of our Nodes (master and worker) whether they are ready or not.

 


Kubernetes Cluster nodesWe have to install CNI so that pods can communicate across nodes and also Cluster DNS to start functioning. Apply Weave CNI (Container Network Interface) on the master node.

Note: If you want to know more about Network Policy, then check our blog on Network Policies in Kubernetes

 


CNIWait for a few minutes and verify the cluster status by executing kubectl command on the master node and see that nodes come to the ready state.

 


Testing Kubernetes ClusterTo verify the status of the system pods like coreDNS, weave-net, Kube-proxy, and all other master node system processes, use the following command:

To know more about Pods in Kubernetes, check our blog on Kubernetes Pods for Beginners.

 


Kubernetes clusterYour output should match with the shown output above. If not, you will have to check whether you have performed all the steps correctly and on the mentioned node only.

Related Post

Download the Free Guide

Get a Free step-by-step activity guide on Bootstrap a Kubernetes Cluster Using Kubeadm. This Guide will help you in Creating 3 VMs to set up Kubeadm cluster, Installing Packages like Docker, Kubectl & Kubeadm, and Initialising the Cluster. Get this Free Guide to take one step in learning Docker & Kubernetes by registering for it.

Click on the below image to Get a Free Guide on Bootstrapping a Kubernetes Cluster Using Kubeadm.

The post How To Setup A Three Node Kubernetes Cluster For CKA: Step By Step appeared first on Cloud Training Program.


Viewing all articles
Browse latest Browse all 1891

Trending Articles