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.
CLOUDSTACK SERVER SETUP
- We have already created 3 VM’s in cloudstack environment using Ubuntu 20.04 template.
- We use 2 VCPU and 2 GB RAM for all 3 nodes for this demo setup. To view complete HCL (Hardware compatibility List) for kubernetes. Please check this URL: https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/
- Also, from the cloudstack network perspective, we are using single isolated network with source NAT enabled.
- And also, enabled port forwarding the all the required VM’s.
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.
- Add an hash ( # ) tag at being of swap.img line.
- save the file and exit. Then reboot the VM.
- 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
Installing transport https and Curl commands
- Use the below to install transport https and curl packages.
apt-get install -y apt-transport-https curl
- 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 –
Adding Kubernetes Repository
- The command is,
apt-add-repository “deb http://apt.kubernetes.io/ kubernetes-xenial main”
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
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
Enable IP Forwarding
- Edit the /etc/sysctl.conf file and delete the hash symbol for under IP forwarding settings.
- Save and exit the file.
- Then run the below command to enable the IP forwarding on virtual filesystem (/proc)
echo ‘1’ > /proc/sys/net/ipv4/ip_forward
- The run the below command to apply the changes to the current running kernel.
sysctl -p /etc/sysctl.conf
Containerd status
- Use the below command to check the containerd status.
systemctl status containerd
- 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
- 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.
- After few minutes, kubernetes cluster has been configured successfully.
- Take a copy of node join command, which will be use to join the Kubernetes node later.
- If you are running as root user, then open run the below command.
export KUBECONFIG=/etc/kubernetes/admin.conf
- Also, add this line in bashrc file. To do that, edit the file using vi ~/.bashrc command.
- Go to last line of that file and add the below line and save it.
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
- Flannel network has been created in kubernetes master node.
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
- First node joined successfully to the cluster.
- Second nodes joined successfully to the cluster.
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
- 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
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.