1.前置
官方文档:https://kubernetes.io/zh/docs/setup/production-environment/tools/kubeadm/install-kubeadm
# 关闭防火墙
sudo systemctl stop firewalld.service
sudo systemctl disable firewalld.service
# 阿里 yum 源
sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
sudo curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
sudo sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
yum makecache
# 将 SELinux 设置为 permissive 模式(相当于将其禁用)
sudo setenforce 0
sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
# 关闭 swap,swap 为 0
sudo sed -ri 's/.*swap.*/#&/' /etc/fstab
sudo swapoff -a
free -g
# 允许 iptables 检查桥接流量
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sudo sysctl --system
2.安装kubeadm
# 配置kubernetes镜像源
cat > /etc/yum.repos.d/kubernetes.repo << EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
# 安装kubelet kubeadm kubectl
sudo yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
# 开机自启
sudo systemctl enable --now kubelet
# 查看 kubelet 状态
systemctl status kubelet
kubelet --version
# 重新启动 kubelet
sudo systemctl daemon-reload
sudo systemctl restart kubelet
3.使用 kubeadm 安装 Kubernetes
:::danger Master 安装,其它节点加入 :::
# 不指定kubernetes-version,会自动获取最新版
kubeadm init \
--apiserver-advertise-address=192.168.113.128 \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.24.0 \
--service-cidr=10.96.0.0/16 \
--pod-network-cidr=192.168.0.0/16
rm /etc/containerd/config.toml
systemctl restart containerd
kubeadm reset