A MULTI-CLOUD SETUP OF K8S CLUSTER

What is Kubernetes?

To know about kubernetes visit the below blog:

What is Multi Cloud Kubernetes Cluster?

Multicloud is a cloud architecture composed of more than one cloud vendor, possibly in combination with private cloud or on-premise resources.

Multi cloud setups differ in complexity, there are several use cases that may require Kubernetes cluster nodes to be deployed across different cloud services. Some such use cases include:

  • Reducing geographic latency and related performance constraints
  • Regulatory or compliance factors
  • Disaster recovery requirements
  • Specific capabilities such as custom hardware or access to certain vendor-managed services

Let’s head over our practical ➡️

Configuring AWS

Setting Up the EC2 Instance

The first stage will be to set up your Amazon EC2 instance.

You can use either above step or below steps mentioned:

First, log in to the AWS Portal

→ In the portal, click on “Services,” then select “EC2” under theCompute services category.

→ Now go to the panel on the left side of the EC2 console and select “Instances.”

→ On the Instances page, click on “Launch Instance.”

→ The next page will lists number of machine images that can be used for various workloads.

For our task we use the “Amazon Linux 2 AMI” image, as it simplifies provisioning since there are no manual steps required to install OS and storage.

→ You can also opt for any machine image running a Linux distribution for setting up the workload.

→ Once you pick an image of your choice, click “Select.”

→ Next, select the Instance type you would like to use.

→ To Configure Instance, Add Storage, and Add Tags settings, accept the default configurations and skip to the next step.

→ In the Security Group settings menu, click on “Create a new security group,” which initiates a security group with the default settings.

→ Once done, verify the instance configuration settings. This redirects to a key-pair creation page. The AWS console can create private and public RSA keys if a pair doesn’t exist. Create these keys, download them, and keep them safe as these will be used for secure access to the EC2 endpoint.

→ Click “Launch” to activate the instance.

Configuring Azure

Now let’s launch slave on Azure Cloud

→ Go to azure cloud and create new virtual machine and resource group

→ Fill all the required information like Resource group, virtual machine name, region, Image say RedHat Image

→ We also have to set Authentication, So here I am selecting password based authentication

→ Now choose the disk type according to requirement

→ Now lets do some networking part, here you have to select your subnet, virtual network and public IP so that other system can connect you

→ In next step we have to do Management and Advance setting (choose default settings)

→ In next page we have to add Tags to our Virtual machine

→ Now review all the options and Launch the Virtual machine

Here our all required instances launched successfully.

Configure Kubernetes master node

Steps to configure master node

kubernetes is based on docker so first we have to install docker on master node and also start and enable the docker services

command:-

yum install docker -y

systemctl start docker

systemctl enable docker

Configure cgroup drive

vim /etc/docker/daemon.json{  
"exec-opts": ["native.cgroupdriver=systemd"]
}

Since we have made changes in docker, we need to restart the docker service :

systemctl restart docker

For installing kubelet, kubeadm, kubectl first, we need to set up a repo for this :

vim /etc/yum.repos.d/k8s.repo
# content inside repo k8s.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://packa

Installing required software :

Kubelet: An agent that runs on each node in the cluster. It makes sure that containers are running in a Pod. The kubelet takes a set of PodSpecs that are provided through various mechanisms and ensures that the containers described in those PodSpecs are running and healthy. The kubelet doesn’t manage containers that were not created by Kubernetes.

Kubeadm: It is a Kubernetes cluster management tool. It performs the necessary actions to create a Kubernetes cluster. It also useful for upgrading, joining multiple nodes, manages Kubernetes certificates, external authentications for the cluster.

Kubectl: It is Kubernetes command-line tool, allows you to run commands against Kubernetes clusters.

yum install docker kubelet kubeadm kubectl iproute-tc -y

Starting and enabling services :

systemctl enable --now docker
systemctl enable --now kubelet

We also need to pull docker images using kubeadm. It pulls images of the config files.

kubeadm config  images pull

The important step is while initializing Master,

We need to associate the token to the public IP of instance, so that any of the other nodes can easily connect, so for this use :
--control-plane-endpoint=<PUBLIC_IP>:6443
kubeadm init --pod-network-cidr=10.244.0.0/16 --control-plane-endpoint=<public_ip>:6443 --ignore-preflight-errors=NumCPU --ignore-preflight-errors=Mem

  • pod-network-cidr: IP range (for pods inside the slave nodes)
  • Control plane endpoint: assign the cluster with a public IP with port
  • ignore-preflight-errors: Ignoring the unwanted CPU errors and memory errors

Now, make a directory for Kube config files and give permission to them :

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

Apply flannel :

To connect the nodes of the master and slave we use a flannel.

Flannels act as a DHCP server as well as a router in the cluster. It will create a connection between the pods running in the cluster. The flannel works on the underlying network.

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

Final step:

Generate token so that slave nodes could connect to master node :

kubeadm token create --print-join-command

Configure Kubernetes slave node

Setting up Kubernetes nodes on Azure:

For installing kubelet, kubeadm, kubectl first, we need to set up a repo for this :

vim /etc/yum.repos.d/k8s.repo
# content inside repo k8s.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

Installing required software :

yum install docker kubelet kubeadm kubectl iproute-tc -y

Starting and enabling services :

systemctl enable --now docker
systemctl enable --now kubelet

We also need to pull docker images using kubeadm. It pulls images of the config files :

kubeadm config  images pull

Now, we need to change the docker cgroupdriver into systemd :

vim /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"]
}

Since we have made changes in docker, we need to restart the docker service :

systemctl restart docker

Setting up a network bridge to 1 :

echo "1" > /proc/sys/net/bridge/bridge-nf-call-iptable

Copy-paste the token generated in the master node

Finally, in the master node :

kubectl get nodes

You will see that all the nodes are connected and are ready !

So here our task completed!!

THANKS FOR READING

If you find anything that could be improved please let me know💚💛

For more such articles, Stay Connected 😄

--

--

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store