# 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 ```bash! swapoff -a ``` - Forwarding IPv4 and letting iptables see bridged traffic ```bash! 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](https://github.com/containerd/containerd/blob/main/docs/getting-started.md) Dowload page for [containerd](https://containerd.io/downloads/) - 安裝 ```bash! # 安裝 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 ```diff [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc] ... [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options] - SystemdCgroup = false + SystemdCgroup = true ... ``` - 重啟 containerd ```bash systemctl restart containerd ``` - 查看使用的 port ```bash netstat -nlput | grep containerd ``` ### kubeadm kubelet kubectl [K8s doc](https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/#installing-kubeadm-kubelet-and-kubectl) ```bash! 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 ```bash! # 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 ```bash # 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 ``` ```bash # worker # copy the command generated form master above kube kubeadm join ... ``` ### label the role of node ```bash kubectl label node $node kubernetes.io/role=$role ``` ## Remove 1. 移除 node ```bash kubectl drain $node ``` <https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#drain> 2. 清除安裝時的設定 ```bash sudo kubeadm reset ``` <https://kubernetes.io/docs/reference/setup-tools/kubeadm/kubeadm-reset/> 3. 刪除其他相關設定 [reset and uninstall](https://github.com/DeepSpider/kubernetes-installation/blob/main/04-reset_uninstall.sh) [洗掉 kubernetes 環境重新來過](https://ithelp.ithome.com.tw/articles/10262330)
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up