k8s

Install Kubernetes On Ubuntu 18.04

Setup k8s cluster on Bandwagon

Posted by Wilson on November 28, 2021

Prerequisites

  1. 2 or more Linux servers running Ubuntu 18.04 in Bandwagon or other cloud provider
  2. Access to a user account on each system with sudo or root privileges

Step 1: Install Docker on all linux nodes

add sudo if you are not running with root account

apt-get update
apt-get --assume-yes  install curl
apt-get install -y vim
apt-get install  -y docker.io
systemctl enable docker

Step 2: Install Kubernetes

apt-get install -y gnupg
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add
apt-get install -y software-properties-common
apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"
apt-get install -y kubeadm kubelet kubectl
apt-mark hold kubeadm kubelet kubectl
#Verify the installation with:
kubeadm version

Repeat for each server node.

Step 3: Disabling the swap memory on each server

swapoff -a
#Change /etc/fstab, and comment below line
sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab

Step 4: Assign Unique Hostname for Each Server Node

#run in master node
hostnamectl set-hostname master-node
#run in worker node
hostnamectl set-hostname worker01

Step 5: Initialize Kubernetes on Master Node

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

#if you are not using root account
mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config

Step 6: Deploy Pod Network to Cluster

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

Step 7: Join Worker Node to Cluster

# run below to get join command in master
kubeadm token create --print-join-command
#run join command in worker
kubeadm join 74.120.175.86:6443 --token aht1ld.rs5ukoixskygc168 --discovery-token-ca-cert-hash sha256:7df05220abbad9b71879bd8a9e2832f27a5acbcd6201e66bf614f96841b4dd4e

Step 8: Check nodes

#Switch to the master server, and enter
kubectl get nodes