Common Setup Steps for CKA K8s Cluster
Categories:
Disable Swap
Immediately turn off swap with the following command:
sudo swapoff -a
To ensure swap remains off after a reboot, modify the fstab
file:
sudo sed -i 's|^/swap.img|#/swap.img|g' /etc/fstab
Load Modules
Load the necessary modules:
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF
Then, run the following commands:
sudo modprobe overlay
sudo modprobe br_netfilter
Sysctl Parameters
Set the required sysctl
parameters that will persist across reboots:
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
Apply the sysctl
parameters without rebooting:
sudo sysctl --system
Install CRI-O Runtime
Update the package list and install required packages:
sudo apt-get update -y
sudo apt-get install -y \
software-properties-common \
curl \
apt-transport-https \
ca-certificates
Add the CRI-O package repository:
curl -fsSL https://pkgs.k8s.io/addons:/cri-o:/prerelease:/main/deb/Release.key |
gpg --dearmor -o /etc/apt/keyrings/cri-o-apt-keyring.gpg
echo "deb [signed-by=/etc/apt/keyrings/cri-o-apt-keyring.gpg]
https://pkgs.k8s.io/addons:/cri-o:/prerelease:/main/deb/ /" |
tee /etc/apt/sources.list.d/cri-o.list
Next, install CRI-O:
sudo apt-get update -y
sudo apt-get install -y cri-o
Enable and start the CRI-O service:
sudo systemctl daemon-reload
sudo systemctl enable crio --now
sudo systemctl start crio.service
Install Kubeadm
Add the Kubernetes package signing key:
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.28/deb/Release.key |
gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
Add the Kubernetes repository:
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
Update package lists and install the required Kubernetes components:
sudo apt update
sudo apt install -y kubeadm=1.28.15-1.1 \
kubelet=1.28.15-1.1 \
kubectl=1.28.15-1.1
Disable Auto-Update Services
Prevent the auto-update of specific packages:
sudo apt-mark hold kubelet kubectl kubeadm cri-o
Final Configuration
Install jq
for processing JSON data:
sudo apt install jq -y
Retrieve the local IP address for configuration:
local_ip="$(ip --json a s | jq -r '.[] | if .ifname == "eth1" then .addr_info[] | if .family == "inet" then .local else empty end else empty end')"
Create or modify the Kubelet configuration:
cat > /etc/default/kubelet << EOF
KUBELET_EXTRA_ARGS=--node-ip=$local_ip
${ENVIRONMENT}
EOF
Finally, restart the Kubelet service:
sudo systemctl restart kubelet
sudo systemctl status kubelet
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.