Containerd安装脚本123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990#/bin/bash# install containerd scriptcontainerd_version=1.6.15containerd_pause_version=3.9kubernetes_version=1.26.1-00function install_containerd(){ wget https://github.com/containerd/containerd/releases/download/v${containerd_version}/cri-containerd-cni-${containerd_version}-linux-amd64.tar.gz tar xf cri-containerd-cni-${containerd_version}-linux-amd64.tar.gz mkdir -p /opt/cni/bin && mkdir -p /etc/containerd mv ./opt/cni/bin/* /opt/cni/bin/ && mv ./usr/local/bin/* /usr/local/bin/ && mv ./usr/local/sbin/* /usr/local/sbin/ && mv ./etc/systemd/system/containerd.service /lib/systemd/system/} function config_containerd(){ /usr/local/bin/containerd config default > /etc/containerd/config.toml sed -i "s/SystemdCgroup = false/SystemdCgroup = true/g" /etc/containerd/config.toml sed -i "s/sandbox_image = \"registry.k8s.io\/pause:3.6\"/sandbox_image = \"registry.k8s.io\/pause:${containerd_pause_version}\"/g" /etc/containerd/config.toml systemctl enable --now containerd }function config_cri_env(){tee > /etc/modules-load.d/k8s.conf << EOFoverlaybr_netfilterip_vsip_vs_rrip_vs_wrrip_vs_shnf_conntrackEOFmodprobe overlaymodprobe br_netfilter modprobe ip_vsmodprobe ip_vs_rrmodprobe ip_vs_wrrmodprobe ip_vs_sh modprobe nf_conntracktee > /etc/sysctl.d/k8s.conf << EOFnet.bridge.bridge-nf-call-iptables = 1net.bridge.bridge-nf-call-ip6tables = 1net.ipv4.ip_forward = 1EOFsysctl --systemswapoff -ased -ri 's/.*swap.*/#&/' /etc/fstab}function install_kubernetes_google(){ apt update apt-get install -y apt-transport-https ca-certificates curl curl -fsSLo /etc/apt/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg echo "deb [signed-by=/etc/apt/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | tee /etc/apt/sources.list.d/kubernetes.list apt-get update apt-get install -y kubelet=${kubernetes_version} kubeadm=${kubernetes_version} kubectl=${kubernetes_version} apt-mark hold kubelet kubeadm kubectl systemctl enable kubelet}function install_kubernetes_ali(){apt-get update && apt-get install -y apt-transport-httpscurl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add - tee > /etc/apt/sources.list.d/kubernetes.list << EOFdeb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial mainEOFsed -i "s/sandbox_image = \"registry.k8s.io\/pause:${containerd_pause_version}\"/sandbox_image = \"registry.cn-hangzhou.aliyuncs.com\/google_containers\/pause:${containerd_pause_version}\"/g" /etc/containerd/config.tomlsystemctl restart containerd.serviceapt-get updateapt-get install -y kubelet=${kubernetes_version} kubeadm=${kubernetes_version} kubectl=${kubernetes_version}apt-mark hold kubelet kubeadm kubectlsystemctl enable kubelet}function main(){ install_containerd config_containerd config_cri_env #install_kubernetes_google install_kubernetes_ali}main