Praveenpm
techbeatly
Published in
3 min readMay 18, 2023

--

Kubernetes deployment on Bare-Metal server with Flannel Networking

Prerequisite for the Kubernetes deployment:

1. root privileges.
2. 3.75 GB or more of Ram — 6 GB for better performance.
3. 2 CPUs or more.
4. Full network connectivity between all machines in the cluster.
5. Unique hostname, MAC address, and product_uuid for every node.
6. Swap memory should be disabled. You MUST disable swap for the kubelet to work properly.

End of the documentation, the below points will be achieved:

1. How to install Docker.
2. How to install Kubernetes.
3. How to configure a master and two worker node.
4. How to join a worker node to a Kubernetes cluster

Update Ubuntu using the below commands:

sudo apt update
sudo apt upgrade

Install Docker on all the hosts:

sudo apt install docker.io
docker ––version

Start and Enable Docker:

sudo systemctl enable docker
sudo systemctl start docker
sudo systemctl status docker

If the service is not running, please run the below command:

sudo systemctl start docker

The same activity must be performed all the nodes.

Make the below changes on all the nodes in order to prepare for the Kubernetes installation:

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

Update and upgrade package list:

sudo apt-get update -y && apt-get upgrade -y

Ensure net.bridge.bridge-nf-call-iptables is set to 1 in your sysctl config.

cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sudo sysctl --system

Download the Google Cloud public signing key:

curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg

Add the Kubernetes apt repository:

echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list

Proceed to update apt package index, install kubelet, kubeadm and kubectl, and pin their version.

apt-get update -y
apt-get install -y kubelet=1.21.14-00 kubeadm=1.21.14-00 kubectl=1.21.14-00
apt-mark hold kubelet kubeadm kubectl

Create Kubernetes Cluster Master: Initialize the Kubernetes cluster in Linux:

sudo rm -Rf $HOME/.kube/config
sudo yes | kubeadm reset
sudo iptables -F && iptables -t nat -F && iptables -t mangle -F && iptables -X
sudo swapoff -a
sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab

Initialize cluster:

kubeadm init --pod-network-cidr=10.244.0.0/16

Setup config file for kubectl:

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

Setup the Network for Hybrid Cluster: Prepare Kubernetes control plane for Flannel:

sudo kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

Add the worker nodes to the kubernets cluster using the below command:

kubeadm join 10.45.2.230:6443 --token x0h1ak.n2lxs5jogh9fearf --discovery-token-ca-cert-hash sha256:5905b83d51b1225f7b9de8575e91db19d5aa4905696243c151cd34cd9a37f8d5

Check the added nods status using the below commands:

Kubectl get nodes

--

--

Praveenpm
techbeatly

Technology Lead at Hewlett Packard Enterprise