How to configure Multi-Cloud Multi-Node Kubernetes Cluster ?

Bhavesh S. Sonewale
6 min readJun 27, 2021

What is Kubernetes ?

🔶 Kubernetes is a portable, extensible, open-source platform for managing containerized workloads and services, that facilitates both declarative configuration and automation.

🔶 In other words, Kubernetes (also known as k8s or “kube”) is an open source container orchestration platform that automates many of the manual processes involved in deploying, managing, and scaling containerized applications.

Why Multi-Cloud ?

🔷 One of the main reasons behind moving towards a multi-cloud strategy is the rise of SaaS services and solutions.

🔷 Since the standard architecture of most businesses of today involves using SaaS providers to run traditional business processes rather than leveraging a standalone, monolith solution, companies are also moving towards multi-cloud to reduce costs and prevent the issues that might come with a single cloud provider.

🔷 According to Gartner, 81% of organizations are working with two or more public cloud providers.

🔷 A multi-cloud strategy gives companies the freedom to use the best possible cloud for each workload.

How to configure Multi-Cloud Multi-Node Kubernetes Cluster ?

Pre-requisite :- Container technology Docker should be installed and pre-configured in all the nodes.

Note :- Here, I’m using RHEL(Red Hat Enterprise Linux) OS.

How will be our Multi-Cloud Multi-Node Kubernetes Cluster architecture ?

Here in this practical, I will configure 1 master node on GCP cloud and 1 worker node on GCP cloud, AWS cloud, Azure cloud, Local Machine, respectively. Means in totality we will have 1 master node and 4 worker node.

For simplicity I have created bash script “k8s-master-setup.sh” and “k8s-slave-setup.sh” for configuring master node and worker node respectively. Now you only need to run command “bash k8s-master-setup.sh” and “bash k8s-slave-setup.sh” to configure master and worker node respectively.

You can find this both scripts in my GitHub repo :-

Please watch the below video to understand how this bash script works. Don’t worry, after video I will explain each and every command required to configure this cluster.

Now in the above video you have seen that using my created bash script, how easy it is to configure entire cluster. But how this all command (which is there in bash script) works ? So let’s discuss that :-

Commands required to configure master node :-

  1. First we need to create yum repository for installing kubeadm, kubelet and kubectl. For this enter below content in CLI :-

cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-\$basearch
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
exclude=kubelet kubeadm kubectl
EOF

  • kubeadm : the command to bootstrap the cluster.
  • kubelet : the component that runs on all of the machines in your cluster and does things like starting pods and containers.
  • kubectl : the command line util to talk to your cluster.

2. Now use below command for installing kubeadm, kubelet and kubectl :-

3. Run below command to start the kubelet service :-

4. This command will pull all the required images for configuring master node :-

Run “docker images” command for checking all the pulled images by above command i.e. “kubeadm config images pull”. You will see lots of images like kube API server, kube-scheduler, etc.

5. Change the Cgroup Driver of docker from “cgroupfs” to “systemd” :-

When you run this command “docker info | grep -i cgroup”, you will see that by default Cgroup Driver of docker is “cgroupfs”.

Now for changing Cgroup driver to “systemd”, just enter this below content in CLI :-

cat <<EOF | tee /etc/docker/daemon.json
{
“exec-opts”: [“native.cgroupdriver=systemd”]
}
EOF

Now you need to restart the docker service, for this run below command:-

“systemctl restart docker”

Now if you again run this command “docker info | grep -i cgroup” to check Cgroup driver of docker, you will find that now Cgroup Driver is “systemd”.

6. Now install “iproute-tc” to enable networking, routing, etc in our cluster. Command is :-

yum install iproute-tc

7. Now initialize the master node :-

Below command will initialize the master node and will run/start all the containers required for master node like kube API server, kube scheduler, etc.

“ — pod-network-cidr” : To provide network_name/CIDR/network_range to the master so that when we launch any pod, master will always give the IP to the pod from this range only.

“ — control-plane-endpoint” : to provide control plane endpoint.

“ — ignore-preflight-errors=NumCPU” & “— ignore-preflight-errors=Mem” : Give this option only when you have less than 2GB RAM and 2 CPU.

8. Now to check master node is properly configured or not, we need to make master node a user/client of the cluster, for this run all the below commands :-

Now for testing, run any kubernetes commands like “kubectl get pods”, etc. If this command is working means your master node is configured.

When your worker nodes will join this cluster, to check which node are there in cluster, run command “kubectl get nodes”.

9. Final step is to install CNI(Container Network Interface) for the communication between pods of each node:-

There are lots of CNI available like ACI, flannel, weave, calico, etc. Here in this cluster I’m using flannel as CNI. For this run below command :-

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

10. Now get the join command of our cluster using below command :-

kubeadm token create — print-join-command

Copy the output of above command.

Commands required to configure worker node :-

  1. Repeat above 1, 2, 3, 5, 6 steps in all the worker node.
  2. Then run following commands :-

cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF

3. Now reload the system, for this command is :-

sysctl — system

4. Now finally run that copied output of step 10 of configuring master node.

Output looks something like this :-

kubeadm join 172.31.40.209:6443 — token 3joamn.y8asi8hw2jb41xx5 — discovery-token-ca-cert-hash sha256:86dd3714b1168b8de0abcb63300a458baf838860ff9c6f53bd85707853ff4db7

You just need to run this copied command to join the cluster.

.

So, by looking at the above steps for configuring k8s cluster, you might feel that how hard and long process this is. Only for this reason I have created bash script for configuring master and worker nodes. Using this scripts, you need to run only one command i.e. “bash k8s-master-setup.sh” and “bash k8s-slave-setup.sh” for configuring master and worker node respectively.

So that’s all for today’s technical practical. Will come back again with another interesting technical practical. Thanks for reading.

Connect with me on LinkedIn :-

https://www.linkedin.com/in/bhaveshsonewale/

--

--

Bhavesh S. Sonewale

2x Red Hat Certified | Aspiring DevOps Engineer | Aviatrix Certified Engineer| AWS | Ansible | Openshift | Docker | Kubernetes