ubuntu 一键安装 k8s 1.22.15 脚本

共计 1616 个字符,预计需要花费 5 分钟才能阅读完成。

#!/bin/bash
set -ex

# 安装 containerd 
apt-get update && apt-get install -y containerd

sudo mkdir -p /etc/containerd
containerd config default | sudo tee /etc/containerd/config.toml
# 设置containerd的Cgroup驱动为systemd
sudo sed -i 's/SystemdCgroup = false/SystemdCgroup = true/g' /etc/containerd/config.toml
sudo sed -i 's/registry.k8s.io/k8s.m.daocloud.io/g' /etc/containerd/config.toml
sudo systemctl restart containerd
sudo systemctl enable containerd

# 禁用swap
swapoff -a
sed -i '/swap/d' /etc/fstab

modprobe br_netfilter
# 调整内核参数
cat <<EOF >  /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
sysctl --system

# 添加阿里云的Kubernetes软件源
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF
curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -

sudo apt update
# 安装Kubeadm, Kubelet和Kubectl
sudo apt-get install -y kubelet=1.22.2-00 kubeadm=1.22.2-00 kubectl=1.22.2-00

# 初始化Kubernetes集群
kubeadm init --kubernetes-version=v1.22.15 --pod-network-cidr=10.244.0.0/16 --cri-socket=/run/containerd/containerd.sock -v5 --image-repository=k8s.m.daocloud.io

# 使kubectl命令对当前用户生效
mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config

# 安装Calico插件
curl https://mirror.ghproxy.com/raw.githubusercontent.com/projectcalico/calico/v3.26.1/manifests/tigera-operator.yaml -k -LO && curl https://mirror.ghproxy.com/raw.githubusercontent.com/projectcalico/calico/v3.26.1/manifests/custom-resources.yaml -k -LO && sed -i 's/192.168.0.0\/16/10.244.0.0\/16/g' custom-resources.yaml  && kubectl create -f tigera-operator.yaml && kubectl create -f custom-resources.yaml 
正文完
 0
评论(没有评论)