- Distribution
- Ubuntu Jammy 22.04
- Ubuntu Focal 20.04
- GitHub link to the instruction
You need to set up the cluster: Master node and Worker nodes.
- Master: A Master a system that control API calls for the pods, controllers, services, nodes and other components of a Kubernetes cluster are executed.
- Worker: A Worker is a system that provides the run-time environments for the containers. A set of container pods can span multiple nodes.
Kubernetes Packages
There are 3 packages you need to install.
- kubeadm: a tool which sets up a cluster
- kubelet: a component which run containers on a node
- kubectl: command-line tool for interacting with a cluster and its resources
Prerequisite – Docker
Set up the Kubernetes Repositories
curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes.gpg
echo "deb [signed-by=/etc/apt/keyrings/kubernetes.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
- At the time of the writing, “kubernetes-xenial” is the latest Kubernetes repository.
- It might be replaced with “kubernetes-focal” or “kubernetes-jammy”.
- Check https://kubernetes.io/.
Install Kubernetes packages
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
Configure sysctl
sudo modprobe overlay
sudo modprobe br_netfilter
sudo tee /etc/sysctl.d/kubernetes.conf<<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
sudo sysctl --system
Disable Swap
vim /etc/fstab
# comment out the swap disk if exists
# /host/ubuntu/disks/swap.disk none swap loop,sw
sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
sudo swapoff -a
Reboot
sudo reboot
- Reconnect once the machine is ready again
Confirm installation of kubectl
kubectl version --client && kubeadm version
Fix Configuration
# Check the docker
sudo systemctl enable docker
sudo systemctl start docker
docker image ls
#Enable kubelet service.
sudo systemctl enable kubelet
sudo systemctl start kubelet
# Fix Configuration
sudo rm /etc/containerd/config.toml
sudo systemctl restart containerd
Initialize the cluster – Master Only
# Pull container images
sudo kubeadm config images pull
sudo kubeadm init --pod-network-cidr=10.244.0.0/16
- Copy the last part of the result — You will need this.
Set up local kubeconfig – Master Only
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
export KUBECONFIG=$HOME/.kube/config
Install Flannel networking – Master Only
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
Check the nodes – Master
kubectl get nodes
- You can see the master node.
Join Worker to the Cluster – Worker
- Run the Join command copied from the “kubeadm init” command
sudo kubeadm join 172.31.17.57:6443 --token 90wmxd.76csh4jlamyhs7io \
--discovery-token-ca-cert-hash sha256:1384a4aa86c6128a35ca3d7e4461431474f27487500f40954a7c3ce56b083bab
Check the nodes – Master
kubectl get nodes
kubectl get pods --all-namespaces
kubectl cluster-info
- You can see the master node and all worker nodes
Installing Metrics Server
https://github.com/kubernetes-sigs/metrics-server
https://github.com/kubernetes-sigs/metrics-server
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
# verify - wait for ready
kubectl get deployment metrics-server -n kube-system
# check metrics
kubectl top nodes
kubectl top pods -A
- If the deployment fails with Liveness probe failed: HTTP probe failed with statuscode: 500′, do the following.
# edit deployment
kubectl edit deploy metrics-server -n kube-system
# find the args
# add --kubelet-insecure-tls under the port
- --secure-port=4443
- --kubelet-insecure-tls
# verify - wait for ready
kubectl get deployment metrics-server -n kube-system
1 Comment