Install Kubernetes, Controlplane and Workers

In a previous article about Kubernetes infrastructure, we introduced control-plane and workers concepts. The functionality, how is the relation between both and what are the roles of each one.

For better knowledge about the components, and the possibility to know working with a Kubernetes cluster, we need to install the software hands-on.

Install Kubernetes Software

Creating a Kubernetes cluster involves setting up a control plane (master node) and one or more worker nodes. Kubernetes provides various tools to simplify this process, and one of the popular ones is kubeadm.

If you are interested in obtaining more information, you can find it here.

In this example, I’ll guide you through the steps, to set up a Kubernetes control plane and one worker node using kubeadm. If you need to add more nodes, it is necessary to repeat all steps mentioned in the “workers” phase.

For sure, I going to share the documentation in a GitHub repo where I tried to automate my environment by using Vagrant-files to create the cluster and provision the resource nodes to make simple the setup.

My idea was to make a simple script in a simple format and put it in a GitHub repository that you can find here.

https://github.com/juanmercadoit/cka-kubernetes/tree/main/kubernetes-setup


When I finished and saw the nodes deployed, I said, “Andrew, you need to change those scripts and do it better than the ones”. So, at this moment arises the idea of doing the same steps by using vagrant files and a playbook.

But this code will be for another post. 🙂

Prerequisites

Before you start, make sure you have the following prerequisites:

  1. Linux Hosts: You will need at least two Linux machines. One for the control plane (master node) and one for the worker node. In this case, we going to install Ubuntu Server.
  2. SSH Access: Ensure that you have SSH access to both machines.
  3. Root Access: You should have root or sudo privileges on both machines.

Debian/Ubuntu family

Install Docker (Both Control Plane and Worker Node)

  • Install Docker on both machines using the following commands:
sudo apt update
sudo apt install -y docker.io
  • Start and enable Docker:
sudo systemctl start docker
sudo systemctl enable docker

Disable Swap (Both Control Plane and Worker Node)

  • Disable swap on both machines:
sudo swapoff -a

To make the swap disabling permanent, comment out or remove the swap entry from /etc/fstab.

Install kubeadm, kubelet, and kubectl (Both Control Plane and Worker Node)

  • Install the Kubernetes components: kubeadm, kubelet, and kubectl on both machines:
sudo apt update
sudo apt install -y kubeadm kubelet kubectl

Initialize the Control Plane (Master Node)

  • On the control plane node, run the following command to initialize the cluster:
sudo kubeadm init --pod-network-cidr=10.244.0.0/16

Replace 10.244.0.0/16 with the Pod network CIDR you want to use if needed.

Note down the kubeadm join command that is printed at the end. You’ll need it to join the worker node.

Set Up Kubernetes Configuration (Control Plane)

  • Run the following commands on the control plane node to set up your user’s kubeconfig:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

Install a Pod Network (Control Plane)

  • Choose a Pod network add-on, such as Calico or Flannel. In this example, we’ll use Calico:
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml

Join the Worker Node (Worker Node)

On the worker node, run the kubeadm join command you obtained from the step: Initialize the Control Plane (Master Node).

It will look something like this:

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

Replace <control-plane-host>, <control-plane-port>, <token>, and <ca-cert-hash> with the values specific to your cluster.

Verify the Cluster (Control Plane)

On the control plane node, run the following command to check if the worker node has successfully joined the cluster:

kubectl get nodes -o wide

You should see both the control plane node and worker node listed with a Ready status.

Congratulations! You have successfully set up a Kubernetes control plane and one worker node on Ubuntu.

Your cluster is now ready to deploy and manage containerized applications.

For Redhat and others, you can download this file with the complete process.