环境

cat /proc/version

Linux version 3.10.0-957.21.3.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) ) #1 SMP Tue Jun 18 16:35:19 UTC 2019
root@10.101.1.30 ~$ cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)

cat /etc/redhat-release

CentOS Linux release 7.5.1804 (Core)

安装

# 通过rke2安装k8scurl -sfL https://get.rke2.io | sh -# 开机启动rke2-serversystemctl enable rke2-server.service# 启动rke2-server 启动有点慢,耐心等待即可systemctl start rke2-server.service

查看rke2-server状态

systemctl status rke2-server.service

显示running表示启动成功,如下:
● rke2-server.service – Rancher Kubernetes Engine v2 (server)
Loaded: loaded (/usr/lib/systemd/system/rke2-server.service; disabled; vendor preset: disabled)
Active: active (running) since 三 2023-07-05 14:41:59 CST; 43s ago

检查 RKE2 是否正常运行

/var/lib/rancher/rke2/bin/kubectl \        --kubeconfig /etc/rancher/rke2/rke2.yaml get nodes

当输出以下结果, 状态为Ready时,表示k8s已经安装完毕
NAME STATUS ROLES AGE VERSION
node2 Ready control-plane,etcd,master 7m48s v1.25.11+rke2r1

测试集群 Pod 的健康状况

/var/lib/rancher/rke2/bin/kubectl \        --kubeconfig /etc/rancher/rke2/rke2.yaml get pods --all-namespaces

拷贝脚本和k8s配置 (可选)

/etc/rancher/rke2/rke2.yaml 需要妥善保存,它包含了连接k8s的凭证.后续用kubectl操作k8s都要读取该文件

cp /var/lib/rancher/rke2/bin/kubectl /usr/local/bin/kubectlcp /etc/rancher/rke2/rke2.yaml .kube/config# 拷贝脚本和配置之后,以上命令可以简化为 .前提是/usr/local/bin/已经添加到了环境变量中kubectl get nodeskubectl get pods --all-namespaces

完全卸载

参考

为 Rancher 设置高可用的 RKE2 Kubernetes 集群