Step-by-Step to install 2 Node Kubernetes cluster in Cloudstack using Ubuntu 20.04

Posted by

In this blog, we will show you the steps to install two node kubernetes cluster in 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.

image

CLOUDSTACK SERVER SETUP

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

image

  • Also, from the cloudstack network perspective, we are using single isolated network with source NAT enabled.

image

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

image

KUBERNETES COMPONENTS INSTALLATION (ON MASTER AND WORKER NODES)

Note: Please 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.

image

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

image

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

image

image

  • 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

image

Installing transport https and Curl commands

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

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

image

  • 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 –

image

Adding Kubernetes Repository

  • The command is,

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

image

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

image

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


image

Enable IP Forwarding

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

image

image

  • Save and exit the file.

image

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

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

image

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

sysctl -p /etc/sysctl.conf

image

Containerd status

  • Use the below command to check the containerd status.

systemctl status containerd

image

  • 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.

image

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

image

  • 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

image

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 *