In this article we will create a cluster in Kubernetes with 1 master and 3 workers.
1 Master host responsible for managing the cluster and 3 Workers that will be connected to the cluster for deployments distribution.
Define hostnames of machines:
MASTER
hostname kube-master
echo "kube-master" > /etc/hostname
WORKERS
hostname kube-worker-1
echo "kube-worker-1" > /etc/hostname
hostname kube-worker-2
echo "kube-worker-2" > /etc/hostname
hostname kube-worker-3
echo "kube-worker-3" > /etc/hostname
Run the commands below on all machines:
curl -fsSL https://get.docker.com | sh
sudo apt-get update && sudo apt-get install -y apt-transport-https ca-certificates curl
sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
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
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
sudo swapoff -a
Make this setting only on the Master machine.:
kubeadm init
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
Do this setting on workers only.:
Replace the values below according to the result of the “kubeadm init” command above:
kubeadm join 192.168.12.50:6443 --token 97qkmt.wn0eqzu45geha6l7 \
--discovery-token-ca-cert-hash sha256:f8a26cf969f453ccbe75d74246a6699aa25cea3db81ebd7c7d67312648e53419
Run this command on the master:
kubectl get pods