🚀 DevOps & SRE Certification Program 📅 Starting: 1st of Every Month 🤝 +91 8409492687 🔍 Contact@DevOpsSchool.com

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

Kubernetes cluster provisioning with Rancher’s RKE command

Step 1 – Install docker

Step 2 – Install RKE

URL to download – https://github.com/rancher/rke/releases

$ sudo yum install wget -y
$ wget https://github.com/rancher/rke/releases/download/v1.3.10/rke_linux-amd64
$ chmod 755 rke_linux-amd64
$ mv rke_linux-amd64 rke
$ echo $PATH
$ sudo mv rke /usr/sbin

Step 3 – Add normal user to docker group


$ sudo groupadd docker
$ sudo gpasswd -a $USER docker
$ docker ps

Step 4 – Create rke config file


[centos@ip-172-31-11-29 ~]$ rke config
[+] Cluster Level SSH Private Key Path [~/.ssh/id_rsa]:
[+] Number of Hosts [1]: 1
[+] SSH Address of host (1) [none]: 172.31.11.29
[+] SSH Port of host (1) [22]:
[+] SSH Private Key Path of host (172.31.11.29) [none]: ~/.ssh/id_rsa
[+] SSH User of host (172.31.11.29) [ubuntu]: centos
[+] Is host (172.31.11.29) a Control Plane host (y/n)? [y]: y
[+] Is host (172.31.11.29) a Worker host (y/n)? [n]: y
[+] Is host (172.31.11.29) an etcd host (y/n)? [n]: y
[+] Override Hostname of host (172.31.11.29) [none]: host1
[+] Internal IP of host (172.31.11.29) [none]: 172.31.11.29
[+] Docker socket path on host (172.31.11.29) [/var/run/docker.sock]:
[+] Network Plugin Type (flannel, calico, weave, canal, aci) [canal]: weave
[+] Authentication Strategy [x509]:
[+] Authorization Mode (rbac, none) [rbac]:
[+] Kubernetes Docker image [rancher/hyperkube:v1.22.9-rancher1]:
[+] Cluster domain [cluster.local]:
[+] Service Cluster IP Range [10.43.0.0/16]:
[+] Enable PodSecurityPolicy [n]:
[+] Cluster Network CIDR [10.42.0.0/16]:
[+] Cluster DNS Service IP [10.43.0.10]:
[+] Add addon manifest URLs or YAML files [no]:
[centos@ip-172-31-11-29 ~]$

Step 5 – Run rke up command

Set up a Highly Available Kubernetes Cluster using Rancher RKE

Follow this documentation to set up a highly available Kubernetes cluster on Ubuntu 20.04 LTS machines using Rancher's RKE.

This documentation guides you in setting up a cluster with three nodes all of which play master, etcd and worker role.

Vagrant Environment

Role FQDN IP OS RAM CPU
Master, etcd, worker node1.example.com 172.16.16.101 Ubuntu 20.04 2G 2
Master, etcd, worker node2.example.com 172.16.16.102 Ubuntu 20.04 2G 2
Master, etcd, worker node3.example.com 172.16.16.103 Ubuntu 20.04 2G 2
  • Password for the root account on all these virtual machines is kubeadmin
  • Perform all the commands as root user unless otherwise specified

Pre-requisites

If you want to try this in a virtualized environment on your workstation

  • Virtualbox installed
  • Vagrant installed
  • Host machine has atleast 8 cores
  • Host machine has atleast 8G memory

Bring up all the virtual machines

vagrant up

Download RKE Binary

Download the latest release from the Github releases page

Rancher RKE Releases - Github

Set up password less SSH Logins on all nodes

We will be using SSH Keys to login to root account on all the kubernetes nodes. I am not going to set a passphrase for this ssh keypair.

Create an ssh keypair on the host machine
ssh-keygen -t rsa -b 2048
Copy SSH Keys to all the kubernetes nodes

The root password is kubeadmin

ssh-copy-id root@172.16.16.101
ssh-copy-id root@172.16.16.102
ssh-copy-id root@172.16.16.103

Prepare the kubernetes nodes (node1, node2, node3)

Disable Firewall
ufw disable
Disable swap
swapoff -a; sed -i '/swap/d' /etc/fstab
Update sysctl settings for Kubernetes networking
cat >>/etc/sysctl.d/kubernetes.conf<<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
Install docker engine
{
  apt install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common
  curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
  add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
  apt update && apt install -y docker-ce=5:19.03.10~3-0~ubuntu-focal containerd.io
}

Bring up Kubernetes cluster

Create cluster configuration
rke config

Once gone through this interactive cluster configuration, you will end up with cluster.yml file in the current directory.

Provision the cluster
rke up

Once this command completed provisioning the cluster, you will have cluster state file (cluster.rkestate) and kube config file (kube_config_cluster.yml) in the current directory.

Downloading kube config to your local machine

On your host machine

mkdir ~/.kube
cp kube_config_cluster.yml ~/.kube/config

Verifying the cluster

kubectl cluster-info
kubectl get nodes
kubectl get cs

Have Fun!!

view raw README.md hosted with ❤ by GitHub
Subscribe
Notify of
guest


1 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
bala
bala
1 year ago

How to setup with containerd instead of docker?

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.

1
0
Would love your thoughts, please comment.x
()
x