Try   HackMD

k8s 安裝移除

Installation

https://zhuanlan.zhihu.com/p/612051521
https://blog.jks.coffee/on-premise-self-host-kubernetes-k8s-setup/
https://earthly.dev/blog/deploy-kubernetes-cri-o-container-runtime/

建議 sudo su 後在 root 權限下執行

Setup

  • 關閉 swap

    ​​​​swapoff -a
    
  • Forwarding IPv4 and letting iptables see bridged traffic

    ​​​​cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
    ​​​​overlay
    ​​​​br_netfilter
    ​​​​EOF
    
    ​​​​modprobe overlay
    ​​​​modprobe br_netfilter
    
    ​​​​# 设置所需的 sysctl 参数
    ​​​​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
    
    ​​​​# 应用 sysctl 参数
    ​​​​sysctl --system
    
    ​​​​# 检验配置是否生效
    ​​​​lsmod | grep br_netfilter
    ​​​​lsmod | grep overlay
    
    ​​​​sysctl net.bridge.bridge-nf-call-iptables net.bridge.bridge-nf-call-ip6tables net.ipv4.ip_forward
    

Container Runtime

follow the instructions on Getting started with containerd
Dowload page for containerd

  • 安裝

    ​​​​# 安裝 containerd
    ​​​​wget https://github.com/containerd/containerd/releases/download/$VERSION/containerd-$VERSION-$OS-$ARCH.tar.gz
    ​​​​tar Cxzvf /usr/local containerd-$VERSION-$OS-$ARCH.tar.gz
    
    ​​​​# 設定 systemd
    ​​​​# make sure if containerd.service store roght data
    ​​​​wget https://raw.githubusercontent.com/containerd/containerd/main/containerd.service -o /usr/lib/systemd/system/containerd.service
    ​​​​systemctl daemon-reload && systemctl enable containerd
    
    ​​​​# 安裝 runc
    ​​​​wget https://github.com/opencontainers/runc/releases/download/$VERSION/runc.$ARCH
    ​​​​install -m 755 runc.$ARCH /usr/local/sbin/runc
    
    ​​​​# 安裝 CNI plugins
    ​​​​mkdir -p /opt/cni/bin
    ​​​​wget https://github.com/containernetworking/plugins/releases/download/$VERSION/cni-plugins-$OS-$ARCH-$VERSION.tgz
    ​​​​tar Cxzvf /opt/cni/bin cni-plugins-$OS-$ARCH-$VERSION.tgz
    
    ​​​​# 產生 containerd 預設檔案
    ​​​​mkdir /etc/containerd
    ​​​​containerd config default > /etc/containerd/config.toml
    
  • 修改設定檔案
    /etc/containerd/config.toml

[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]
...
  [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
-    SystemdCgroup = false
+    SystemdCgroup = true
...
  • 重啟 containerd

    ​​​​systemctl restart containerd
    
  • 查看使用的 port

    ​​​​netstat -nlput | grep containerd
    

kubeadm kubelet kubectl

K8s doc

sudo apt-get update
# apt-transport-https may be a dummy package; if so, you can skip that package
sudo apt-get install -y apt-transport-https ca-certificates curl

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 # set package not to update

Setup Cluster

initialize cluster

# only do on master
sudo kubeadm init \
--pod-network-cidr=10.244.0.0/16 \
--cri-socket unix:///var/run/containerd/containerd.sock \ # if only one CRI is installed, then will auotmaic select it. Otherwise will need to set it
--apiserver-advertise-address=$HOST_IP # default is local IP

join the node

# master
# generate the command for joinging the worker
kubeadm token create --print-join-command \
--cri-socket unix:///var/run/containerd/containerd.sock # if only one CRI is installed, then will auotmaic select it. Otherwise will need to set it
# worker
# copy the command generated form master above
kube kubeadm join ...

label the role of node

kubectl label node $node kubernetes.io/role=$role

Remove

  1. 移除 node

    ​​​​kubectl drain $node
    

    https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#drain

  2. 清除安裝時的設定

    ​​​​sudo kubeadm reset
    

    https://kubernetes.io/docs/reference/setup-tools/kubeadm/kubeadm-reset/

  3. 刪除其他相關設定
    reset and uninstall
    洗掉 kubernetes 環境重新來過