Kubernetes Multi Node Cluster Setup on AWS Cloud

Sonam Kumari Singh
4 min readJul 8, 2022

--

In This Article, you can follow the same steps to create the Multi Node cluster in your virtual machines and connect as many nodes you need..

I will be using AWS cloud to setup Multi Node cluster of K8s. I will be using 3 ec2 instances , 1 for Master Node and 2 for slave / worker node.

So lets launch 3 instances first!

Launching Aws instances

  • Search ec2
  • Click on Launch instances
  • Select Amazon Linux
  • Select t2.micro
  • Number of instances = 3
  • Allow all traffic
  • Remaining keep as it is and launch the instance

So Launching the instances is now complete , you can now change the name of one of the instance to kubernetes Master.

Now login to kubernetes master

Install the container Runtime -docker

#sudo yum install docker -y
#sudo systemctl enable docker --now

Install the following Packages in all the machines

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

Before installing the above packages you have to first configure yum repository

//yum configuration file 
#cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
EOF
#sudo yum repolist
#sudo yum install kubeadm kubectl kubelet -y //Starting kubelet services
#sudo systemctl enable kubelet --now //downloading necessary images required for the cluster
#kubeadm config images pull

ok Now it’s time to setup the master

//to setup the master we use the below command
#kubeadm init

but the command will fail with some warnings and errors, so lets check everything one by one.

  • Specify range of IP addresses for the pod network by using the option
    — pod-network-cidr
  • changing the docker cgroup driver to systemd
#cd /etc/docker
#vi daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"]
}
#cat daemon.json //after changing the conf file of docker we have to restart it
#systemctl restart docker
  • Install one software called iproute-tc
#yum install iproute-tc -y
  • The minimum Ram and CPU requirement for this setup is 2GB and 2 CPU,
    but i am using only 1GB Ram and 1 CPU ,so you will get one error for this .
    You can either increase your Ram and CPU else ignore this error for setting up this cluster.

so finally to setup the master run the below command

#kubeadm init --pod-network-cidr=10.244.0.0/16 --ignore-preflight-errors=NumCPU --ignore-preflight-errors=Mem
#mkdir -p $HOME/.kube
#sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
#sudo chown $(id -u):$(id -g) $HOME/.kube/config //to check the total nodes we have
#kubectl get nodes//Setting up CNI
#kubectl apply -f https://raw.githubusercontent.com/flannel-io/flannel/master/Documentation/kube-flannel.yml

Your Master Node is ready ,now we can connect the slave nodes to Master.

For connecting the slave to master we require the token

//copy the output of this command.
#kubeadm token create --print-join-command

Now login to your Slave Node and run the below commands
we are running almost the same command ,that we run on master

#sudo yum install docker -y
#sudo systemctl enable docker --now
#cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
EOF
#sudo yum repolist
#sudo yum install kubeadm kubectl kubelet -y
#systemctl enable kubelet --now
#cd /etc/docker
#vi daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"]
}
#cat daemon.json //after changing the conf file of docker we have to restart it
#systemctl restart docker
#yum install iproute-tc -y //Letting iptables see bridged traffic
#cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
#sudo sysctl --system //This is the final step
Paste the command that you copied from the master after running kubeadm token create --print-join-command

So Now our Multi Node cluster is ready.

//Run this in master node#kubectl get nodes

Thats it!!
Hope you guys have got some information about Multi-Node setup.

Thank You!💕

--

--

Sonam Kumari Singh
Sonam Kumari Singh

Written by Sonam Kumari Singh

SONAM here! Grateful for your connection! Tech enthusiast exploring new languages, deep into DevOps, with a spotlight on Linux. 😊🚀

No responses yet