Rancher Kubernetes Engine (RKE) 是一个开源工具,用于部署和管理 Kubernetes 集群。它特别适合在物理服务器、虚拟机或云提供商上部署集群。本文将指导您在 CentOS 系统上轻松安装 RKE,并快速搭建起 Kubernetes 集群。

步骤 1:准备 CentOS 环境

在开始之前,请确保您的 CentOS 系统满足以下要求:

  • CentOS 7 或 CentOS 8
  • 系统更新至最新状态
  • 确保系统防火墙和 selinux 已经关闭或调整策略
  • 确保系统时钟同步(推荐使用 NTP)

以下是一些必要的命令:

sudo yum update -y
sudo systemctl stop firewalld
sudo systemctl disable firewalld
sudo systemctl stop iptables
sudo systemctl disable iptables
sudo setenforce 0
sudo systemctl stop NetworkManager
sudo systemctl disable NetworkManager
sudo systemctl start ntpd
sudo systemctl enable ntpd

步骤 2:安装 Docker

RKE 需要 Docker 来运行 Kubernetes 集群,因此首先需要安装 Docker。

sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install -y docker-ce docker-ce-cli containerd.io
sudo systemctl start docker
sudo systemctl enable docker
sudo docker --version

步骤 3:安装 RKE

从 RKE 的 GitHub 仓库下载 RKE:

mkdir -p /usr/local/bin
cd /usr/local/bin
curl -LO https://github.com/rancher/rke/releases/download/v1.2.7/rke_linux-amd64
chmod +x rke_linux-amd64
mv rke_linux-amd64 rke

步骤 4:配置 RKE

创建一个新的 RKE 配置文件 cluster.yml

cat > cluster.yml <<EOF
nodes:
  - address: 192.168.1.2
    role: controlplane
    user: root
    password: rootpassword
  - address: 192.168.1.3
    role: worker
    user: root
    password: rootpassword
EOF

请根据您的实际情况修改上述配置文件中的 IP 地址、角色和用户信息。

步骤 5:部署 Kubernetes 集群

使用 RKE 部署 Kubernetes 集群:

sudo rke up cluster.yml

RKE 会自动在指定的节点上安装和配置 Kubernetes 和容器运行时(如 Docker),并启动集群。

总结

通过以上 5 个步骤,您可以在 CentOS 系统上轻松安装 RKE 并快速搭建起 Kubernetes 集群。RKE 提供了简单、高效的方式来部署和管理 Kubernetes 集群,让您的应用能够快速上线。