Step-by-Step Guide to Install a 2-Node Kubernetes Cluster in Cloudstack Using Ubuntu 20.04

How to Install 2 Node K8s Cluster in ACS Using Ubuntu 20.04?

Posted by

In this blog, we will demonstrate the steps to install two node kubernetes cluster in Apache Cloudstack environment.

ENVIRONMENT OVERVIEW

  • For demo purpose, we are using 2 worker nodes and 1 master mode. Please check the below image for your reference.

Step-by-Step guide to Install a 2-Node K8 Cluster in ACS Using Ubuntu 20.04 - StackBill Cloud Management Portal

APACHE CLOUDSTACK SERVER SETUP

  • We have already created 3 VM’s in Apache CloudStack Cloudstack environment using Ubuntu 20.04 template.

Step-by-Step guide to Install a 2-Node K8 Cluster in ACS Using Ubuntu 20.04 - StackBill Cloud Management Portal

Step-by-Step guide to Install a 2-Node K8 Cluster in ACS Using Ubuntu 20.04 - StackBill Cloud Management Portal

  • And also, enabled port forwarding the all the required VM’s.

Step-by-Step guide to Install a 2-Node K8 Cluster in ACS Using Ubuntu 20.04 - StackBill Cloud Management Portal

KUBERNETES COMPONENTS INSTALLATION (ON MASTER AND WORKER NODES)

Note: Kindly follow the below steps on both Master and Node VM’s.

Disable SWAP Memory

  • Login into the VM and open /etc/fstab using an editor.

Step-by-Step guide to Install a 2-Node K8 Cluster in ACS Using Ubuntu 20.04 - StackBill Cloud Management Portal

  • Add an hash ( # ) tag at being of swap.img line.

Step-by-Step guide to Install a 2-Node K8 Cluster in ACS Using Ubuntu 20.04 - StackBill Cloud Management Portal

  • save the file and exit. Then reboot the VM.

Step-by-Step guide to Install a 2-Node K8 Cluster in ACS Using Ubuntu 20.04 - StackBill Cloud Management Portal

Step-by-Step guide to Install a 2-Node K8 Cluster in ACS Using Ubuntu 20.04 - StackBill Cloud Management Portal

  • Follow the same steps on other worker nodes.

Note: We are running all the command under root privileges, so we don’t use “SUDO” as prefix for each command. In case, if you are trying to installing from an user account, make sure that you have added sudo as prefix for all the commands.

Updating Local Package

  • Execute the below command to update the Ubuntu packages.

apt-get update

Step-by-Step guide to Install a 2-Node K8 Cluster in ACS Using Ubuntu 20.04 - StackBill Cloud Management Portal

Installing transport https and Curl commands

  • Use the below to install transport https and curl packages.

apt-get install -y apt-transport-https curl

Step-by-Step guide to Install a 2-Node K8 Cluster in ACS Using Ubuntu 20.04 - StackBill Cloud Management Portal

  • By installing apt-transport-https, you enable your system to use HTTPS for package downloads and updates, enhancing the security of your package management system.

Download the Google Cloud package

  • Below command is used to download the Google Cloud package signing key and add it to the system’s list of trusted keys.

curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add –

Step-by-Step guide to Install a 2-Node K8 Cluster in ACS Using Ubuntu 20.04 - StackBill Cloud Management Portal

Adding Kubernetes Repository

  • The command is,

apt-add-repository “deb http://apt.kubernetes.io/ kubernetes-xenial main”

Step-by-Step guide to Install a 2-Node K8 Cluster in ACS Using Ubuntu 20.04 - StackBill Cloud Management Portal

Installing Kubernetes components

  • Use the below command to install the kubernetes components in Master node.

sudo apt-get update && sudo apt-get install -y kubelet kubeadm kubectl containerd

Step-by-Step guide to Install a 2-Node K8 Cluster in ACS Using Ubuntu 20.04 - StackBill Cloud Management Portal

Enable bridge network capabilities

  • The below command will use to load netfilter kernel module in Linux.
  • This module provides support for the bridging firewall rules related to network address translation (NAT) and IP packet filtering.

modprobe br_netfilter

Step-by-Step guide to Install a 2-Node K8 Cluster in ACS Using Ubuntu 20.04 - StackBill Cloud Management Portal

Enable IP Forwarding

  • Edit the /etc/sysctl.conf file and delete the hash symbol for under IP forwarding settings.

image

Step-by-Step guide to Install a 2-Node K8 Cluster in ACS Using Ubuntu 20.04 - StackBill Cloud Management Portal

  • Save and exit the file.

Step-by-Step guide to Install a 2-Node K8 Cluster in ACS Using Ubuntu 20.04 - StackBill Cloud Management Portal

  • Then run the below command to enable the IP forwarding on virtual filesystem (/proc)

echo ‘1’ > /proc/sys/net/ipv4/ip_forward

Step-by-Step guide to Install a 2-Node K8 Cluster in ACS Using Ubuntu 20.04 - StackBill Cloud Management Portal

  • The run the below command to apply the changes to the current running kernel.

sysctl -p /etc/sysctl.conf

Step-by-Step guide to Install a 2-Node K8 Cluster in ACS Using Ubuntu 20.04 - StackBill Cloud Management Portal

Containerd status

  • Use the below command to check the containerd status.

systemctl status containerd

Step-by-Step guide to Install a 2-Node K8 Cluster in ACS Using Ubuntu 20.04 - StackBill Cloud Management Portal

  • Make sure that containerd is in running state.
  • Now we have installed all the required components on master and worker nodes.

CONFIGURE MASTER NODE

Note: In this demo, we are using Flannel network as networking module for this cluster.

  • Use kubeadm command to initiate the cluster configuration in master node.

The syntax is: kubeadm init –apiserver-advertise-address <Master node eth0 address> –pod-network-cidr=<Your desire POD address for your cluster>

Example:  kubeadm init –apiserver-advertise-address 10.1.1.200  –pod-network-cidr=10.244.0.0/16

image

 

  • In the example, pod-network-cidr=10.244.0.0/16 address is the default flannel network IP range. So we use the default for demo purpose.
  • Now executing the kubernetes cluster initiating process.

image

  • After few minutes, kubernetes cluster has been configured successfully.

image

  • Take a copy of node join command, which will be use to join the Kubernetes node later.

image

  • If you are running as root user, then open run the below command.

export KUBECONFIG=/etc/kubernetes/admin.conf

image

  • Also, add this line in bashrc file. To do that, edit the file using vi ~/.bashrc command.

image

  • Go to last line of that file and add the below line and save it.

image

CONFIGURE NETWORK ON MASTER NODE

  • Execute the below command in the master node to configure Flannel network for kubernetes cluster.

kubectl apply -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml

  • If you download and open this kube-flannel.yml file, you can able to see the default network CIDR for flannel network

image

  • Flannel network has been created in kubernetes master node.

image

JOINING WORKER NODES TO THE CLUSTER

  • From each worker node, paste the kubenetes join command which we copied from the cluster configuration.

Example command:  kubeadm join 10.1.1.200:6443 –token udcswr.zwg8wap9bppebmtv \
–discovery-token-ca-cert-hash sha256:7ff11680d29dacd9c255141dbf5a92739f337aaae1f02ef676ebbdc50c7cdce9

image

  • First node joined successfully to the cluster.

image

  • Second nodes joined successfully to the cluster.

Step-by-Step guide to Install a 2-Node K8 Cluster in ACS Using Ubuntu 20.04 - StackBill Cloud Management Portal

VERIFYING THE CLUSTER

  • From the master node, type the below command to list all the available nodes in the cluster. Make sure all the nodes are in ready status.

kubectl get nodes

Step-by-Step guide to Install a 2-Node K8 Cluster in ACS Using Ubuntu 20.04 - StackBill Cloud Management Portal

  • Also, make sure that kubernetes cluster related pods are in running state. To verify that, run the below command.

kubectl get pods –n kube-system

Step-by-Step guide to Install a 2-Node K8 Cluster in ACS Using Ubuntu 20.04 - StackBill Cloud Management Portal

Thanks for reading this blog. We hope it was useful for you to learn about the Step-by-Step to install 2 Node Kubernetes cluster in Cloudstack using Ubuntu 20.04.

Leave a Reply

Your email address will not be published. Required fields are marked *