Multi-Cloud Setup of Kubernetes

·

4 min read

Hey Folks! I hope you are doing fantastic, In this blog, I will write about how we can set up a Multi-Cloud Kubernetes setup.

Here we go…

Steps we are going to Do…

  1. Configure Master Node in AWS

  2. Configure Node in AWS, GCP, Azure

  3. Result: To see Cluster Nodes

Let’s first learn about Kubernetes.

In Kubernetes world, the basic unit is the pod which is the container wrapped with the metadata about that container so that It becomes easier to manage

There are different ways to install Kubernetes Cluster,

  • Kind

  • Minukube

  • kubeadm

we are going to use kubeadm to set up Multi-cloud Kubernetes Cluster.

Learn more about kubeadm here,

Kubeadm

Kubeadm is a tool built to provide kubeadm init and kubeadm join as best-practice "fast paths" for creating Kubernetes…

kubernetes.io

1. Configure Master Node in AWS

  • Launch an Instance

Login into AWS and launch an AWS Instance. Name it as Master Node

  • Configure Master Node
  1. Configure Repository

To Install kubectl, kubeadm, kubelet, first, we have to configure the repository for the packages.

Write the following contents in the file /etc/yum.repos.d/k8s.repo with vim or any editor you like

vim /etc/yum.repos.d/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

2. Install the required software

yum install docker kubelet kubeadm kubectl iproute-tc -y

The above command will install kubelet which is the node agent, which will run on all nodes. kubelet will register the nodes with the API server

3. Start and Enable the service

systemctl enable -now docker
systemctl enable -now kubelet

The command will start and enable docker and kubelet which we installed.

4. Pull images used by kubeadm

kubeadm config images pull

kubeadm will pull all the images used for the configuration of Kubernetes

5. Change the docker cgroup driver to systemd

Cgroup is known as a control group which is responsible to limit the resources used by a container.

  • Open the file /etc/docker/daemon.json
{ 
“exec-opts”: [“native.cgroupdriver=systemd”]
}

6. Restart Docker

We have made changes to Docker, we have to restart the docker service to make the changes come into action

systemctl restart docker

7. Setup Network Bridge to 1

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

8. Kubeadm init Command — Important step

kubeadm will initiate the Kubernetes configuration program. we are passing on some options based on our use case.

kubeadm init \
  --pod-network-cidr=10.244.0.0/16 \
  --control-plane-endpoint=<public_ip_of_Master>:6443 \
  --ignore-preflight-errors=NumCPU \
  --ignore-preflight-errors=Mem

Let’s see in detail

--pod-network-cidr=10.244.0.0/16

To Specify the range of IP addresses for the pod network. If set, the control plane will automatically allocate CIDRs for every node

--control-plane-endpoint=<public_ip_of_Master>:6443

To Specify a stable IP address or DNS name for the control plane.

--ignore-preflight-errors=NumCPU

A list of checks whose errors will be shown as warnings. We are using this to ignore errors when we use less CPU for our Master Node

--ignore-preflight-errors=Mem

We are using this to ignore errors when we use less Memory for our Master Node

9. Configure kubectl

kubectl is the CLI client to interact with Kubernetes we need to configure the kubectl to interact with Kubernetes

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

10. Configure flannel as Kubernetes Network

Flannel is a simple and easy way to configure a layer 3 network fabric designed for Kubernetes.

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

11. Final Step in Master Configuration: Print Join command — Step to Remember

Create bootstrap tokens on the server

kubeadm token create -print-join-command

Save the join token we will use them when we configure, the worker Nodes

kubeadm join — token <token> <control-plane-host>:<control-plane-port> — discovery-token-ca-cert-hash sha256:<hash>

2. Configure Node in AWS, GCP, and Azure

The nodes are where your workloads (containers and Pods, etc) run.

  • Launch instance in AWS

  • Launch a VM in GCP

  • Launch Virtual machine in Azure

  • Configure all 3 nodes with the following steps…

Repeat the following steps in all nodes you launched in AWS, GCP, and Azure.

  1. Configure Repository
vim /etc/yum.repos.d/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

2. Install the required software

yum install docker kubelet kubeadm kubectl iproute-tc -y

3. Start and Enable the service

systemctl enable -now docker
systemctl enable -now kubelet

4. Pull images used by kubeadm

kubeadm config images pull

5. Change the docker cgroup driver to systemd

  • Open the file /etc/docker/daemon.json
{ 
“exec-opts”: [“native.cgroupdriver=systemd”]
}

6. Restart Docker

systemctl restart docker

7. Setup Network Bridge to 1

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

8. Joining the Cluster — Important step

copy and paste the token generated in Master Node.

It looks like in this

kubeadm join — token <token> <control-plane-host>:<control-plane-port> -discovery-token-ca-cert-hash sha256:<hash>

3. Result: To see Cluster Nodes

Finally, we can see all nodes in the cluster from Master Node, ’cause we configured the kubectl in the Master Node

kubectl get nodes

We can see all the nodes connect to the cluster from different cloud Platforms

I hope you learn something new, Thanks for reading 😊🚀

If you like my Content, Let’s connect 🤝

Srivardhan T | LinkedIn

Srivardhan-T (Srivardhan ) (github.com)