1.前置

官方文档:https://kubernetes.io/zh/docs/setup/production-environment/tools/kubeadm/install-kubeadm

  1. # 关闭防火墙
  2. sudo systemctl stop firewalld.service
  3. sudo systemctl disable firewalld.service
  4. # 阿里 yum 源
  5. sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
  6. sudo curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
  7. sudo sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
  8. yum makecache
  9. # 将 SELinux 设置为 permissive 模式(相当于将其禁用)
  10. sudo setenforce 0
  11. sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
  12. # 关闭 swap,swap 为 0
  13. sudo sed -ri 's/.*swap.*/#&/' /etc/fstab
  14. sudo swapoff -a
  15. free -g
  16. # 允许 iptables 检查桥接流量
  17. cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
  18. br_netfilter
  19. EOF
  20. cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
  21. net.bridge.bridge-nf-call-ip6tables = 1
  22. net.bridge.bridge-nf-call-iptables = 1
  23. EOF
  24. sudo sysctl --system

2.安装kubeadm

  1. # 配置kubernetes镜像源
  2. cat > /etc/yum.repos.d/kubernetes.repo << EOF
  3. [kubernetes]
  4. name=Kubernetes
  5. baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
  6. enabled=1
  7. gpgcheck=0
  8. repo_gpgcheck=0
  9. gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
  10. EOF
  11. # 安装kubelet kubeadm kubectl
  12. sudo yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
  13. # 开机自启
  14. sudo systemctl enable --now kubelet
  15. # 查看 kubelet 状态
  16. systemctl status kubelet
  17. kubelet --version
  18. # 重新启动 kubelet
  19. sudo systemctl daemon-reload
  20. sudo systemctl restart kubelet

3.使用 kubeadm 安装 Kubernetes

:::danger Master 安装,其它节点加入 :::

  1. # 不指定kubernetes-version,会自动获取最新版
  2. kubeadm init \
  3. --apiserver-advertise-address=192.168.113.128 \
  4. --image-repository registry.aliyuncs.com/google_containers \
  5. --kubernetes-version v1.24.0 \
  6. --service-cidr=10.96.0.0/16 \
  7. --pod-network-cidr=192.168.0.0/16
  1. rm /etc/containerd/config.toml
  2. systemctl restart containerd
  1. kubeadm reset