ECHOKE
Guides

Creating Kubernetes Cluster with Kubeadm

Engin Can Höke
#kubernetes#kubeadm#ubuntu

In this guide, we’ll walk through setting up a Kubernetes cluster with one master and two worker nodes using Kubeadm on Ubuntu servers.

Prerequisites

Ensure that all three nodes (one master and two workers) have Docker installed with version locking to prevent automated updates.

Install Docker on All Nodes

sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo -E add-apt-repository "deb https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install -y docker-ce=5:19.03.12~3-0~ubuntu-bionic
sudo apt-mark hold docker-ce

Disable Swap on Master Node

Kubelet requires swap to be disabled. After disabling swap, remove it from the fstab file to prevent it from being enabled after a reboot.

sudo swapoff -a
# Remove swap from fstab
sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab

Install Kubeadm, Kubelet, and Kubectl on Master Node

curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo -E add-apt-repository "deb https://apt.kubernetes.io/ kubernetes-xenial main"
sudo apt-get update
sudo apt-get install -y kubelet=1.18.4-01 kubeadm=1.18.4-01 kubectl=1.18.4-01
sudo apt-mark hold kubelet kubeadm kubectl

Initialize the Kubernetes Cluster on Master Node

Create a configuration file named clusterconfig.yaml with the following content:

apiVersion: kubeadm.k8s.io/v1beta2
kind: ClusterConfiguration

Then, initialize the cluster:

sudo kubeadm init --config clusterconfig.yaml

Configure kubectl on Master Node

Set up the kubeconfig file for cluster interaction:

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

At this point, the nodes may show a NotReady status because the network addon hasn’t been installed yet.

Install Calico Network Addon on Master Node

kubectl apply -f https://docs.projectcalico.org/v3.14/manifests/calico.yaml

Join Worker Nodes to the Cluster

Generate the join command on the master node:

kubeadm token create --print-join-command

Execute the printed command on each worker node to join them to the cluster.

Verify Cluster Status

After all nodes have joined, check their status:

kubectl get nodes

All nodes should display a Ready status.

For more detailed information, refer to the official Kubernetes documentation: Creating a single control-plane cluster with kubeadm

I hope this guide helps you set up your Kubernetes cluster successfully.

← Blog'a Dön