Kubeadm 安裝 透過 ContainerD 安裝自己的K8s

Kubeadm 安裝 透過 ContainerD 安裝自己的K8s

Step 1 設定 Hostname & hosts

K8s會使用到Hostname 所以要設定一個不重複的host名稱

# hostname設定 
sudo vi /etc/hostname 
 
# host設定主機ip 
sudo vi /etc/hosts

Step 2 關閉SWAP交換分區

swap 分區的使用會在高負載情況下導致 K8s 系統的整體效能下降並有可能導致應用程式的崩潰

sudo swapoff -a 
sudo sed -i '/swap/s/^/#/' /etc/fstab 
 
sudo reboot

Step 3 設定網卡

sudo modprobe br_netfilter 
sudo echo "br_netfilter" | sudo tee /etc/modules-load.d/br_netfilter.conf 
 
sudo 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 
sudo sysctl --system

修改網卡名稱, 改系統的網卡命名模式

sudo vim /etc/default/grub 
 
GRUB_CMDLINE_LINUX="net.ifnames=0" 
 
sudo grub-mkconfig -o /boot/grub/grub.cfg 
sudo reboot

Step 4 安裝Containerd

ContainerD Download

runC Download

cni Download

# 下載 ContainerD 
wget https://github.com/containerd/containerd/releases/download/v1.7.13/containerd-1.7.13-linux-arm64.tar.gz 
wget https://raw.githubusercontent.com/containerd/containerd/main/containerd.service 
 
sudo tar Cxzvf /usr/local containerd-1.7.13-linux-arm64.tar.gz 
sudo mkdir -p /usr/local/lib/systemd/system 
sudo mv containerd.service /usr/local/lib/systemd/system/containerd.service 
sudo systemctl daemon-reload 
sudo systemctl enable --now containerd 
 
# 下載 runC  
wget https://github.com/opencontainers/runc/releases/download/v1.1.12/runc.arm64 
sudo install -m 755 runc.arm64 /usr/local/sbin/runc 
 
# 下載 cni 
wget https://github.com/containernetworking/cni/archive/refs/tags/v1.1.2.tar.gz 
sudo mkdir -p /opt/cni/bin 
sudo tar Cxzvf /opt/cni/bin v1.1.2.tar.gz

Step 5 安裝kubeadm

可參照官網

sudo apt-get update 
sudo apt-get install -y apt-transport-https ca-certificates curl gpg 
sudo mkdir -m 755 /etc/apt/keyrings 
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

Step 6 調整cluster設定

微調設定,生成ContainerD設定檔 -> config.toml

sudo mkdir /etc/containerd 
sudo containerd config default | sudo  tee /etc/containerd/config.toml

Vim 開啟 將SystemdCgroup 改成true

sudo vim /etc/containerd/config.toml 
 
# SystemdCgroup = true 預設為false

下載 calico yaml

wget https://docs.projectcalico.org/manifests/calico.yaml 
 
若無和本地衝突 拿掉註解即可 , 該範例用 10.30.0.0/16

Step 7 啟動 Cluster

sudo kubeadm init --pod-network-cidr=10.30.0.0/16 
export KUBECONFIG=/etc/kubernetes/admin.conf

Step 8 安裝CNI

kubectl apply -f calico.yaml