Create a kubernetes cluster
This tutorial has been tested with an ubuntu 18.04 distribution and its purpose is to create a controller host and any number of worker…
This tutorial has been tested with an ubuntu 18.04 distribution and its purpose is to create a controller host and any number of worker hosts.
The bellow steps must executed to all hosts of the cluster
Containerd
We will use containerd as CRI runtime, this means that we need to enable and load some kernel modules and do some network configuration changes as well.
Execute the following as root or with sudo
cat <<EOF | sudo tee /etc/modules-load.d/containerd.conf
overlay
br_netfilter
EOF
sudo modprobe overlay
sudo modprobe br_netfilter
# Setup required sysctl params, these persist across reboots.
cat <<EOF | sudo tee /etc/sysctl.d/99-kubernetes-cri.conf
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
EOF
# Apply sysctl params without reboot
sudo sysctl --systemNow we need to install containerd
apt-get update && sudo apt-get install -y containerd
mkdir -p /etc/containerd
containerd config default | sudo tee /etc/containerd/config.toml
systemctl restart containerdDisabling swap
Kubernetes requires swap being disabled to work
swapoff -a
sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstabInstall kubeadm, kubelet, kubectl
apt-get update && sudo apt-get install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
sudo apt-get update
sudo apt-get install -y kubelet=1.20.1-00 kubeadm=1.20.1-00 kubectl=1.20.1-00
sudo apt-mark hold kubelet kubeadm kubectlThe following steps needs to performed on control host only
Initiate the cluster
sudo kubeadm init --pod-network-cidr 192.168.0.0/16
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/configInstall Calico network add-on.
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yamlWait until the Calico related pods have been start using the following command
kubectl get pods -n kube-systemCreate a join token
To add workers to the cluster we need first to generate a join command, to do this on the control host enter
kubeadm token create --print-join-commandAdding a worker to the cluster
Copy the join command fron the previous step and run it as sudo or root on the worker host
How to verify cluster
To verify that all cluster members are up and running enter the following on the control hostkubectl get nodes
You should see something like this
