You are on page 1of 5

Install Kubernetes & Setup Dashboard using Kubeadm

Create security group

Step-1: In Aws Dashboard go to `Security Groups` under Network & Security


Group. & Click on ‘Create security group`.

Enter a name for the security group. Which will use later in master instance.
We will use `K8-Master-SG` as Security group name.

Step-2: Click Add rule and under ‘Inbound rules` and add the roles.

Type Protocol Port range Source


Custom TCP TCP 6443 Anywhere-IPv4
Custom TCP TCP 2379 - 2380 Anywhere-IPv4
Custom TCP TCP 10250 Anywhere-IPv4
Custom TCP TCP 10259 Anywhere-IPv4
Custom TCP TCP 10257 Anywhere-IPv4
SSH TCP 22 Anywhere-IPv4
Custom UDP UDP 8472 Anywhere-IPv4
All traffic All All Anywhere-IPv4

Step-3: Click Add rule and under ‘Outbound rules` and add the roles.

Type Protocol Port range Source


All traffic All All Anywhere-IPv4

Step-4: Click ` Create security group` below the page & save.

Step-5: Now we have to create another security group or slave. Click on ‘Create
security group`.

Enter a name for the security group. Which will use later in master
instance. We will use `K8-Slave-SG` as Security group name.

Step-6: Click Add rule and under ‘Inbound rules` and add the roles.
Type Protocol Port range Source
Custom TCP TCP 10250 Anywhere-IPv4
Custom TCP TCP 30000 - 32767 Anywhere-IPv4
SSH TCP 22 Anywhere-IPv4
Custom UDP UDP 8472 Anywhere-IPv4
All traffic All All Anywhere-IPv4

Step-7: Click Add rule and under ‘Outbound rules` and add the roles.

Type Protocol Port range Source


All traffic All All Anywhere-IPv4

Step-8: Click ` Create security group` below the page & save.

Create EC2 Instance

Step-9: Go to the AWS Console, EC2 Service and click on `Launch instance`.
Step-10: Name of the instance as `kube-master` and choose `Ubuntu Server
20.04 LTS (HVM), SSD Volume Type` as Amazon Machine Image
(AMI).
Step-11: Choose ` t2.medium` as Instance type.
Step-12: Create key pair.
Step-13: On Network settings choose Select existing security group and select
`K8-Master-SG`. Finally click on `launch instance`.

Step-14: Repeat the steps (Step-9 to Step-13) above to create the slave instance.
Keep the same configuration and just name it `kube-slave` and choose
the `K8-Slave-SG` security group.

Working with Instance

Step-15: Connect the master instance. Run the following commands (master
instance).

$ sudo hostnamectl set-hostname master


$ bash
$ sudo su
$ sudo apt-get update && sudo apt-get upgrade -y
$ sudo reboot -f

It will take few minutes. Then reconnect the instance.

Step-16: Install kubelet, kubeadm and kubectl. Run the following commands
(master instance).

$ sudo apt -y install curl apt-transport-https


$ curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo
apt-key add -
$ echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -
a /etc/apt/sources.list.d/kubernetes.list
$ sudo apt-get update
$ sudo apt-get install -y vim git curl wget kubectl kubeadm kubelet
kubernetes-cni
$ kubectl version --client && kubeadm version
$ sudo ufw disable
$ swapoff -a
$ sudo sed -i '/swap/d' /etc/fstab
$ sudo mount -a
$ free -h

Step-17: Install Container Runtime. Run the following commands (master


instance).

$ sudo tee /etc/modules-load.d/containerd.conf <<EOF


$ overlay
$ br_netfilter
$ EOF
$ sudo modprobe overlay
$ sudo modprobe br_netfilter
$ sudo tee /etc/sysctl.d/kubernetes.conf<<EOF
$ net.bridge.bridge-nf-call-ip6tables = 1
$ net.bridge.bridge-nf-call-iptables = 1
$ net.ipv4.ip_forward = 1
$ EOF
$ sudo sysctl --system
$ sudo apt install -y curl gnupg2 software-properties-common apt-
transport-https ca-certificates
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-
key add -
$ sudo add-apt-repository "deb [arch=amd64]
https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
$ sudo apt update
$ sudo apt install -y containerd.io
$ mkdir -p /etc/containerd
$ sudo containerd config default > /etc/containerd/config.toml
$ sudo systemctl restart containerd
$ sudo systemctl enable containerd
$ systemctl status containerd

Step-18: Now connect the slave instance. Run the following commands (slave
instance).

$ sudo hostnamectl set-hostname slave


$ bash
$ sudo su
$ sudo apt-get update && sudo apt-get upgrade -y
$ sudo reboot -f

It will take few minutes. Then reconnect the instance.

Step-19: Then run the same commands on Slave node (Step-16 and Step-17).

Step-20: Now come to Master instance. Run the following commands (master
instance).

$ sudo systemctl enable kubelet


$ sudo kubeadm config images pull --cri-socket
unix:///run/containerd/containerd.sock
$ sudo kubeadm init --apiserver-advertise-
address=MASTER_INSTANCE_PRIVATE_IP --pod-network-
cidr=192.168.0.0/16 --ignore-preflight-errors=all
$ mkdir -p $HOME/.kube
$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
$ sudo chown $(id -u):$(id -g) $HOME/.kube/config
$ export KUBECONFIG=/etc/kubernetes/admin.conf
Step-21: Install Network Plugin on the Master. Run the following commands
(master instance).

$ kubectl create -f
https://raw.githubusercontent.com/projectcalico/calico/v3.25.0/manife
sts/tigera-operator.yaml
$ kubectl create -f
https://raw.githubusercontent.com/projectcalico/calico/v3.25.0/manife
sts/custom-resources.yaml
$ sudo watch kubectl get pods --all-namespaces

You might also like