Kubernetes Cluster Setup using Virtualbox VM

 

Kubernetes Cluster Setup using Virtualbox

Multi-node cluster installation



Prerequisites

  • A PC with virtualization technology enabled
  • Access to a user account on each system with sudo or root privileges
  • The apt package manager, included by default
  • Command-line/terminal window (Ctrl–Alt–T)

Create Virtual Machine as required

Follow this link and create a master and at least one worker node to setup Kubernetes cluster using Ubuntu 18.04 Desktop image

Steps to Setup Kubernetes Cluster

Set up and config Docker

  • sudo apt install apt-transport-https
  • sudo apt-get install docker.io
  • docker version
  • sudo systemctl enable docker
  • sudo systemctl status docker

Set up and config Kubernetes: All VM's

  • Update the package list with the command:

sudo apt-get update

  • Install curl

sudo apt-get install curl

  • Enter the following to add a signing key:

sudo curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add

  • Add software repositories

echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" >> ~/kubernetes.list

sudo mv ~/kubernetes.list /etc/apt/sources.list.d

  • Again update the package list 

sudo apt-get update

  • Install Kubernetes tools, I used Kubernetes version 1.20.7

sudo apt-get install -y kubelet=1.20.7-00 kubectl=1.20.7-00 kubeadm=1.20.7-00

  • Hold kubernetes components:
    sudo apt-mark hold kubelet kubeadm kubectl
  • Disable the swap memory on each server

sudo swapoff -a

  • Comment out the swap... line here to permanently stop swap even after reboot

sudo vi /etc/fstab

  • Check master IP details using ifconfig and update /etc/hosts as below:
    sudo vi /etc/hosts

Initialize Kubernetes: Master VM only

  • Initialize kubernetes in multi-node cluster

sudo kubeadm init --pod-network-cidr 10.10.0.0/16

  • Finish setup and check kubernetes

mkdir -p $HOME/.kube

  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

  sudo chown $(id -u):$(id -g) $HOME/.kube/config

kubectl cluster-info

  • Copy the line like below from the terminal to join worker nodes later in the cluster:
kubeadm join 192.168.0.30:6443 --token pwymf2.osdpiqn5yginzbyq \  --discovery-token-ca-cert-hash sha256:ea025f72bcd6df9950ada7b27c11244a361098ccdd40f63ed504e4d6d30e7ec9
  • To generate new token run the following command on master node:
    sudo kubeadm token create
  • Check list of already created tokens:
    sudo kubeadm token list
  • Retrieve HASH from master node:
    openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'

Configure Calico (Pod Network AddOn): Master VM only

  • Download calico configuration yaml file
    curl https://docs.projectcalico.org/archive/v3.20/manifests/calico.yaml -O
  • Setup calico pod network cidr as below
    Uncomment the following lines from the downloaded calico.yaml file and update value with 10.10.0.0/16
    name: CALICO_IPV4POOL_CIDR
    value: "10.10.0.0/16"
  • Deploy calico.yaml
    kubectl apply -f calico.yaml

Join Kubernetes cluster: Worker VM only

  • User the following command to join a cluster. Replace the UPPERCASE  portions with valid data
sudo kubeadm join --token TOKEN CONTROL_PLANE_HOST_IP:6443 --discovery-token-ca-cert-hash sha256:HASH

Remove Kubernetes Completely from each VM using the following commands

sudo kubeadm reset

sudo apt-get purge kubeadm kubectl kubelet kubernetes-cni kube* 

sudo apt-get autoremove 

sudo rm -rf ~/.kube


Comments