DEV Community

Ashish-Chorge
Ashish-Chorge

Posted on

Create Kubernetes Setup on Ubuntu 20.04.3 VMs

  • Make sure you have enough resources in your local laptop/desktop to deploy VMs. One VM requires at least 2 GB RAM, 2 vCPU, 50 GB HDD
  • Create 2 VMs and install Ubuntu 20.04.3 on it. Note: Don't create swap partition during installation.
  • Make sure the VMs are having internet access by using NAT network adapter. NAT will share host's IP address.
  • Login as root
sudo su -
Enter fullscreen mode Exit fullscreen mode
  • Assign static IP to both Primary and Secondary nodes. (Master = Primary and Worker = Secondary)
cat /etc/netplan/01-network-manager-all.yaml

# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      dhcp4: no
      addresses:
       - 172.23.32.10/20 # IP address which you want to assign
      gateway4: 172.23.32.1
      nameservers:
        addresses: [127.0.0.53,8.8.8.8]
Enter fullscreen mode Exit fullscreen mode
  • Apply the above configuration
netplan apply

Enter fullscreen mode Exit fullscreen mode
  • Update packages
apt-get update && sudo apt-get upgrade -y
Enter fullscreen mode Exit fullscreen mode
  • Install Curl and apt-transport-https packages
apt-get update && sudo apt-get install -y curl apt-transport-https 

Enter fullscreen mode Exit fullscreen mode
  • Add key to verify release
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -

Enter fullscreen mode Exit fullscreen mode
  • Add Kubernetes repository
cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
Enter fullscreen mode Exit fullscreen mode
  • Update packages for Kubernetes repository
apt-get update
Enter fullscreen mode Exit fullscreen mode
  • Install kubelet, kubeadm and kubectl as per your required version
apt-get install -y kubelet=1.xx.y-00 kubeadm=1.xx.y-00 kubectl=1.xx.y-00

Enter fullscreen mode Exit fullscreen mode
  • Install Docker
apt-get install docker.io
Enter fullscreen mode Exit fullscreen mode
  • apt-mark hold will will not update or remove below packages
apt-mark hold kubelet kubeadm kubectl
Enter fullscreen mode Exit fullscreen mode
  • Note down the VM Primary address. (Below command is only for Primary node)
export PRIMARY_IP=<VM management IP address> 
kubeadm init --apiserver-advertise-address=${PRIMARY_IP} --pod-network-cidr=10.100.0.0/16
Enter fullscreen mode Exit fullscreen mode
  • Create bootstrap token on the Primary server. This command is use to join seconadary node to Primary node in a cluster. (Below command is only for Secondary nodes)
kubeadm token create --print-join-command

Example: kubeadm join <Primary management IP>:6443 --token dad5o8.w3rj4bvgvdq6c7xh \
        --discovery-token-ca-cert-hash sha256:63945cc1edb6d637b536a7acb74b0b8185f587cfe16d41a36edae8fe29b2453e
Enter fullscreen mode Exit fullscreen mode
  • Install CNI
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

Enter fullscreen mode Exit fullscreen mode
  • Remove tent from Primary node to deploy pods
kubectl taint nodes <primary node hostname> node-role.kubernetes.io/master- 
Enter fullscreen mode Exit fullscreen mode

Top comments (0)