1 Master – 2 Worker K8s Cluster installation with Kubeadm on Ubuntu servers;
Firstly, we need to install Docker and lock the versions to prevent automated backups at all 3 nodes;
more info: https://docs.docker.com/engine/install/ubuntu/
### Apply all 3 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
Then, we can continue with the kubeadm installation only at master node.
Warning: kubelet needs to swap be disabled. After disabling the swap, we also need to remove swap from the fstab file.
more info: https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/
### Apply only at the master node
sudo swapoff -a
# removing the swap from fstab;
sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
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
After installation of the kubeadm we can move forward to applying Cluster Configuration. We need to create a file named clusterconfig.yaml and paste the below content.
apiVersion: kubeadm.k8s.io/v1beta2
kind: ClusterConfiguration
Now we can initialize the configuration with kubeadm init CLI command;
sudo kubeadm init --config config.yml
For interacting with the Kubernetes Cluster we need to set up Kube config.
### Apply only at the master node
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
You should see the nodes at NotReady state. This is because the network addon didnt installed yet. We can move forward with installing Calico here;
### Apply only at the master node
kubectl apply -f https://docs.projectcalico.org/v3.14/manifests/calico.yaml
kubeadm token create --print-join-command
### Copy the printed command and apply at the Worker nodes
kubectl get nodes
You should see all 3 nodes with Ready state within a second.
I hope this document helped you.