Chapter 3. First Lab to create K8s cluster with one master and 2 worker nodes

Shivani Singh
DevOps DeepDive
Published in
2 min readJun 19, 2020

--

Hello Everyone!

Let’s get our hands-on in K8s by creating a cluster environment of one master and 2 worker nodes.

Follow the below steps on Centos 7.x
The first thing that we are going to do is use SSH to log in to all machines. Once we have logged in, we need to elevate privileges using sudo.

  • sudo su

Disable SELinux.

  • setenforce 0 sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux

Enable the br_netfilter module for cluster communication.

  • modprobe br_netfilter echo '1' > /proc/sys/net/bridge/bridge-nf-call-iptables

Disable swap to prevent memory allocation issues.

  • swapoff -a vim /etc/fstab.orig -> Comment out the swap line

Install the Docker prerequisites.

  • yum install -y yum-utils device-mapper-persistent-data lvm2

Add the Docker repo and install Docker.

Configure the Docker Cgroup Driver to systemd, enable and start Docker

  • sed -i '/^ExecStart/ s/$/ --exec-opt native.cgroupdriver=systemd/' /usr/lib/systemd/system/docker.service systemctl daemon-reload systemctl enable docker --now systemctl status docker docker info | grep -i cgroup

Add the Kubernetes repo.

Install Kubernetes.

  • yum install -y kubelet kubeadm kubectl

Enable Kubernetes. The kubelet service will not start until you run kubeadm init.

  • systemctl enable kubelet

*Note: Complete the following section on the MASTER ONLY!

Initialize the cluster using the IP range for Flannel.

Copy the kubeadmin join command.

Exit sudo and run the following:

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

Deploy Flannel (network for Pod communication across the cluster)

Check the cluster state.

  • kubectl get pods --all-namespaces

*Note: Complete the following steps on the Worker NODES ONLY!

Run the join command that you copied earlier (this command needs to be run as sudo), then check your nodes from the master.

  • kubectl get nodes

P.S: Feel free to reach me in case of any doubts!
Happy Learning!
Shivani S.

--

--

Shivani Singh
DevOps DeepDive

DevOps Engineer, Passionate for new tools and Technology!