Kubernetes/部署文档/Rancher/Rke2单机快速部署Kubernetes.md
offends 7a2f41e7d6
All checks were successful
continuous-integration/drone Build is passing
synchronization
2024-08-07 18:54:39 +08:00

2.7 KiB

本文作者:丁辉

Rke2文档

Rancher中文文档

Rke2单机快速部署Kubernetes

节点名称 IP Kubernetes角色
k8s-master-1 192.168.1.10 Controlplane,etcd,worker,keepalived-master

环境准备

!!!每次部署都写挺麻烦的索性都放在一个文件内了请查看 Kubernetes基础环境准备 ,请按照此文档初始化环境

所有节点执行

  1. 更改主机名

    hostnamectl set-hostname k8s-master-1 && bash
    
  2. 在三台节点上配置 NetworkManager

    • 配置 cali 和 flannel 的网卡不被 NetworkManager 管理

      mkdir -p /etc/NetworkManager/conf.d
      

      内容如下

      cat <<EOF > /etc/NetworkManager/conf.d/rke2-canal.conf
      [keyfile]
      unmanaged-devices=interface-name:cali*;interface-name:flannel*
      EOF
      
    • 重启 NetworkManager

      systemctl daemon-reload
      systemctl restart NetworkManager
      

开始部署

Rke2-Github-releases

  1. 安装 RKE2

    curl -sfL https://get.rke2.io | sh -
    
    • 使用国内源

      curl -sfL http://rancher-mirror.rancher.cn/rke2/install.sh | INSTALL_RKE2_MIRROR=cn INSTALL_RKE2_TYPE="server" sh -
      
    • 指定版本

      curl -sfL https://rancher-mirror.rancher.cn/rke2/install.sh | INSTALL_RKE2_MIRROR=cn INSTALL_RKE2_TYPE="server" INSTALL_RKE2_VERSION="v1.29.3+rke2r1" sh -
      
  2. 开始部署主节点

    systemctl enable rke2-server.service
    systemctl start rke2-server.service
    

    启动失败查看日志

    rke2 server --config /etc/rancher/rke2/config.yaml --debug
    
  3. 配置 RKE2 可执行文件加入到系统的 PATH 中

    echo "export PATH=$PATH:/var/lib/rancher/rke2/bin" >> /etc/profile && source /etc/profile
    
  4. 配置 config 文件

    mkdir ~/.kube && cp /etc/rancher/rke2/rke2.yaml ~/.kube/config
    
  5. 验证

    kubectl get node
    
  6. 配置 crictl 软链接

    ln -s /var/lib/rancher/rke2/agent/etc/crictl.yaml /etc/crictl.yaml
    
  7. 验证

    crictl ps
    

卸载节点

  1. 停止 Rke2

    rke2-killall.sh
    
  2. 卸载 Rke2

    rke2-uninstall.sh