Kubernetes (K8s)
Kubernetes is an open-source container orchestration platform commonly used to manage containerized application workloads. It provides declarative configuration and automation for container-based applications, and it can scale workloads efficiently with features such as Horizontal Pod Autoscaling (HPA).
-
Update and upgrade the packages.
bash~$ sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y -
Install the dependencies and add the repository required to install containerd.
bash~$ sudo apt install -y curl gnupg2 software-properties-common apt-transport-https ca-certificates ~$ sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmour -o /etc/apt/trusted.gpg.d/docker.gpg ~$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" -
Install and configure containerd.
bash~$ sudo apt update ~$ sudo apt install -y containerd.io ~$ containerd config default | sudo tee /etc/containerd/config.toml >/dev/null 2>&1 ~$ sudo sed -i 's/SystemdCgroup \= false/SystemdCgroup \= true/g' /etc/containerd/config.toml ~$ sudo systemctl restart containerd ~$ sudo systemctl enable containerd -
Load the required kernel modules.
bash~$ cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf overlay br_netfilter EOF ~$ sudo modprobe overlay ~$ sudo modprobe br_netfilter -
Configure the required iptables and forwarding settings.
bash~$ cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf net.bridge.bridge-nf-call-iptables = 1 net.bridge.bridge-nf-call-ip6tables = 1 net.ipv4.ip_forward = 1 EOF ~$ sudo sysctl --system -
Add the Kubernetes repository and install
kubectl,kubelet, andkubeadm.bash~$ sudo apt-get install -y apt-transport-https ca-certificates ~$ curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.28/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg ~$ echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.28/deb/ /' | 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
"Note: Run the following commands on the master node.
-
Initialize the Kubernetes cluster on the master node.
bash~$ sudo kubeadm init --pod-network-cidr=10.244.XX.0/16 ~$ mkdir -p $HOME/.kube ~$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config ~$ sudo chown $(id -u):$(id -g) $HOME/.kube/config -
Install Flannel as the pod network.
bash~$ wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml ~$ kubectl apply -f kube-flannel.yml ~$ kubectl get pods --all-namespaces -
Retrieve the join token and CA certificate hash.
bash~$ sudo kubeadm token list ~$ sudo openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'
"Note: Run the following command on each worker node.
- Join the worker node to the cluster.
bash
~$ sudo kubeadm join --token [TOKEN] [NODE-MASTER]:6443 --discovery-token-ca-cert-hash sha256:[TOKEN-CA-CERT-HASH]