curl -sfL https://rancher-mirror.rancher.cn/rke2/install.sh | INSTALL_RKE2_MIRROR=cn sh -

RKE2

是 Rancher 的下一代 Kubernetes 发行版
它继承了 K3s 的可用性、易操作性和部署模型
它还继承了 RKE1 与上游 Kubernetes 的紧密结合关系。为了优化边缘部署,K3s 在某些地方与上游 Kubernetes 有所不同,但 RKE1 和 RKE2 可以与上游保持紧密一致。

RKE2 不像 RKE1 一样依赖 Docker。RKE1 使用 Docker 来部署和管理 control plane 组件以及 Kubernetes 的容器运行时。RKE2 将 control plane 组件作为由 kubelet 管理的静态 pod 启动。嵌入式容器运行时是 containerd。

https://docs.rke2.io/zh/install/quickstart
安装参数:https://docs.rke2.io/zh/install/configuration

rke2安装不支持环境参数,通过文件指定

master安装

mkdir -p /etc/rancher/rke2/
cat >/etc/rancher/rke2/config.yaml <<EOL
token: lren20240802
system-default-registry: registry.cn-hangzhou.aliyuncs.com
EOL


curl -sfL https://rancher-mirror.rancher.cn/rke2/install.sh | INSTALL_RKE2_MIRROR=cn sh -
#指定版本 INSTALL_RKE2_CHANNEL=stable/latest/testing
curl -sfL https://rancher-mirror.rancher.cn/rke2/install.sh | INSTALL_RKE2_MIRROR=cn INSTALL_RKE2_CHANNEL=stable sh -
指定版本方法一
curl -sfL https://rancher-mirror.rancher.cn/rke2/install.sh | INSTALL_RKE2_MIRROR=cn INSTALL_RKE2_VERSION=v1.30.2-rke2r1 sh -

systemctl enable rke2-server.service
systemctl start rke2-server.service
journalctl -u rke2-server -f

查看token:  cat  /var/lib/rancher/rke2/server/node-token

两个清理脚本 rke2-killall.sh 和 rke2-uninstall.sh

server节点添加

cat >/etc/rancher/rke2/config.yaml <<EOL
server: https://172.16.122.63:9345
token: <token from server node>
system-default-registry: registry.cn-hangzhou.aliyuncs.com
EOL
curl -sfL https://rancher-mirror.rancher.cn/rke2/install.sh | INSTALL_RKE2_MIRROR=cn sh -
启动命令同上

agent安装

mkdir -p /etc/rancher/rke2/
cat >/etc/rancher/rke2/config.yaml <<EOL
server: https://172.16.122.63:9345
token: lren20240802
EOL
curl -sfL https://rancher-mirror.rancher.cn/rke2/install.sh | INSTALL_RKE2_MIRROR=cn INSTALL_RKE2_TYPE="agent" sh -
systemctl enable rke2-agent.service
systemctl start rke2-agent.service
journalctl -u rke2-agent -f

命令目录kubectl ctr crictl

cp -r /var/lib/rancher/rke2/bin/kubectl  /usr/local/bin/kubectl
mkdir ~/.kube
cp /etc/rancher/rke2/rke2.yaml .kube/config
或者
export KUBECONFIG=/etc/rancher/rke2/rke2.yaml
或者
cat <<EOL >>~/.bashrc
KUBECONFIG=.kube/confg
EOL
source ~/.bashrc

检查命令

crictl images

kubectl命令

cat <<EOL >>~/.bashrc
alias k='kubectl'
alias ka='kubectl apply'
alias kg='kubectl get'
alias kgnd='kubectl get nodes'
alias kgdp='kubectl get Deployment'
alias kgds='kubectl get DaemonSet'
alias kd='kubectl describe'
alias kdel='kubectl delete'
alias kl='kubectl logs'
alias kt='kubectl top'
alias keit='kubectl exec -it'
EOL
source ~/.bashrc