【K8s】专题八:Kubernetes 安装方法之 RKE

以下内容均来自个人笔记并重新梳理,如有错误欢迎指正!如果对您有帮助,烦请点赞、关注、转发!欢迎扫码关注个人公众号!


一、RKE 简介

RKE 即 Rancher Kubernetes Engine,是由 Rancher 发布的一个极其简单、快速的 Kubernetes 安装程序,简化了 Kubernetes 集群的部署过程。

RKE 经过 CNCF 认证,支持多种操作系统,包括 MacOS、Linux 和 Windows,可以在裸金属服务器(BMS)和虚拟服务器(Virtualized Server)上运行。

RKE 会自动安装 CNI 插件、Ingress-Contoller 等组件。

RKE 项目地址:GitHub - rancher/rke

RKE 官网文档:产品简介 | Rancher文档


二、RKE 下载、安装
bash 复制代码
# AMD架构
wget -O /usr/bin/rke https://github.com/rancher/rke/releases/download/v1.5.9/rke_linux-amd64
chmod +x /usr/bin/rke
 
# ARM架构
wget -O /usr/bin/rke https://github.com/rancher/rke/releases/download/v1.5.9/rke_linux-arm64
chmod +x /usr/bin/rke
 
# 查看版本信息
rke -v

三、RKE 部署 Kubernetes 集群

1、准备工作

bash 复制代码
# 关闭防火墙
systemctl disable --now firewalld
 
# 关闭 selinxu
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
 
# 清空 iptables 规则
iptables -F && iptables -t nat -F
 
# 禁用 swap 分区
swapoff -a
sed -i '/swap / s/^\(.*\)$/#\1/g' /etc/fstab
 
# 配置主机间 SSH 免密(详细过程略)
 
# 安装 docker(详细过程略)

# 配置用户组
vi /etc/docker/daemon.json,添加 "group": "dockerroot"
systemctl daemon-reload && systemctl restart docker

ll /var/run/docker.sock
srw-rw---- 1 root dockerroot 0 May 17 14:05 /var/run/docker.sock

# 创建用户
useradd rke

# 加入用户组
usermod -aG dockerroot rke

# 切换用户、配置免密(不能在 root 用户下执行后续操作)
su - rke
cd .ssh && ssh-keygen -f id_rsa
cat id_rsa.pub >> authorized_keys
chmod 0600 authorized_keys 

2、创建配置

bash 复制代码
cat > cluster.yml <<EOF
cluster_name: mycluster
kubernetes_version: v1.27.13-rancher1-1
nodes:
  - address: 172.16.100.1
    user: rke
    role:
      - controlplane
      - etcd
    ssh_key_path: /home/rke/.ssh/id_rsa
    port: 22
  - address: 172.16.100.2
    user: rke
    role:
      - worker
    ssh_key_path: /home/rke/.ssh/id_rsa
    port: 22
EOF

3、部署集群

  • 方式一(默认方式)
bash 复制代码
rke up --config cluster.yml
cp kube_config_cluster.yml .kube/config

🔔 最后一行返回 Finished building Kubernetes cluster successfully 表明创建成功
🔔 同时生成名为 kube_config_cluster.yml 的 kubeconfig 文件
🔔 所有集群组件均以 Docker 容器方式运行
CONTAINER ID   IMAGE                                  COMMAND                  CREATED         STATUS              PORTS     NAMES
a94cdfa21cee   aba045951c44                           "/usr/bin/dumb-init ..."   2 minutes ago   Up About a minute             k8s_controller_nginx-ingress-controller-z5vss_ingress-nginx_4cbff6e0-50ca-44b8-92a1-700553676379_0
7a303c87f0a8   rancher/mirrored-pause:3.7             "/pause"                 2 minutes ago   Up About a minute             k8s_POD_nginx-ingress-controller-z5vss_ingress-nginx_4cbff6e0-50ca-44b8-92a1-700553676379_0
d86e48e62ef5   b9a5a1927366                           "/metrics-server --c..."   2 minutes ago   Up 2 minutes                  k8s_metrics-server_metrics-server-657c74b5d8-zb97m_kube-system_8e54757a-7a0b-4bac-8707-ffd0be094950_0
2c03a80e4ce2   rancher/mirrored-pause:3.7             "/pause"                 2 minutes ago   Up 2 minutes                  k8s_POD_metrics-server-657c74b5d8-zb97m_kube-system_8e54757a-7a0b-4bac-8707-ffd0be094950_0
da682bea8dff   2635ad6e71aa                           "/cluster-proportion..."   2 minutes ago   Up 2 minutes                  k8s_autoscaler_coredns-autoscaler-6ff6bf758-v4chr_kube-system_780fd508-ae81-44f2-9036-55b7de27d1d6_0
7d42c99d7fe2   ead0a4a53df8                           "/coredns -conf /etc..."   2 minutes ago   Up 2 minutes                  k8s_coredns_coredns-54cc789d79-5b487_kube-system_baed273d-6438-4f58-a39c-ad6cdcf06b74_0
16aa23b63ed8   rancher/mirrored-pause:3.7             "/pause"                 2 minutes ago   Up 2 minutes                  k8s_POD_coredns-autoscaler-6ff6bf758-v4chr_kube-system_780fd508-ae81-44f2-9036-55b7de27d1d6_0
fcc86abd24a6   rancher/mirrored-pause:3.7             "/pause"                 2 minutes ago   Up 2 minutes                  k8s_POD_coredns-54cc789d79-5b487_kube-system_baed273d-6438-4f58-a39c-ad6cdcf06b74_0
a1425a946e19   4e87edec0297                           "/usr/bin/kube-contr..."   2 minutes ago   Up 2 minutes                  k8s_calico-kube-controllers_calico-kube-controllers-5b564d9b7-hcx8t_kube-system_28099c95-0e44-477c-a4ee-7040193c9d4d_0
2bed07ea7b10   rancher/mirrored-pause:3.7             "/pause"                 2 minutes ago   Up 2 minutes                  k8s_POD_calico-kube-controllers-5b564d9b7-hcx8t_kube-system_28099c95-0e44-477c-a4ee-7040193c9d4d_1
52d056f1d42a   f9c73fde068f                           "/opt/bin/flanneld -..."   2 minutes ago   Up 2 minutes                  k8s_kube-flannel_canal-d7twg_kube-system_3c098334-d690-4411-a51c-eb659446d1e1_0
2b75514aa002   1843802b91be                           "start_runit"            2 minutes ago   Up 2 minutes                  k8s_calico-node_canal-d7twg_kube-system_3c098334-d690-4411-a51c-eb659446d1e1_0
a4a584125e81   rancher/mirrored-pause:3.7             "/pause"                 2 minutes ago   Up 2 minutes                  k8s_POD_canal-d7twg_kube-system_3c098334-d690-4411-a51c-eb659446d1e1_0
efae15a3e11f   rancher/hyperkube:v1.28.9-rancher1     "/opt/rke-tools/entr..."   2 minutes ago   Up 2 minutes                  kube-proxy
4c00b668f68b   rancher/hyperkube:v1.28.9-rancher1     "/opt/rke-tools/entr..."   2 minutes ago   Up 2 minutes                  kubelet
8bda1f517147   rancher/hyperkube:v1.28.9-rancher1     "/opt/rke-tools/entr..."   2 minutes ago   Up 2 minutes                  kube-scheduler
50a74e8f5946   rancher/hyperkube:v1.28.9-rancher1     "/opt/rke-tools/entr..."   3 minutes ago   Up 3 minutes                  kube-controller-manager
0ba10b2e326e   rancher/hyperkube:v1.28.9-rancher1     "/opt/rke-tools/entr..."   3 minutes ago   Up 3 minutes                  kube-apiserver
6df5ad3c1321   rancher/rke-tools:v0.1.96              "/docker-entrypoint...."   3 minutes ago   Up 3 minutes                  etcd-rolling-snapshots
17d72af609fc   rancher/mirrored-coreos-etcd:v3.5.10   "/usr/local/bin/etcd..."   3 minutes ago   Up 3 minutes
  • 方式二(dind方式)
bash 复制代码
rke up --config cluster.yml --dind
cp kube_config_cluster.yml .kube/config

🔔 最后一行返回 Finished building Kubernetes cluster successfully 表明创建成功
🔔 同时生成名为 kube_config_cluster.yml 的 kubeconfig 文件
🔔 所有集群组件均以 Docker in Docker 方式运行
CONTAINER ID   IMAGE                                              COMMAND                  CREATED          STATUS          PORTS           NAMES
6fbd35ab313a   docker:20.10.23-dind                               "sh -c 'mount --make..."   5 minutes ago    Up 5 minutes    2375-2376/tcp   rke-dind-172.16.100.1

4、实测结果

Kubernetes 集群组件均以容器方式运行。


四、RKE 常用命令
bash 复制代码
rke -h
NAME:
   rke - Rancher Kubernetes Engine, an extremely simple, lightning fast Kubernetes installer that works everywhere

USAGE:
   rke [global options] command [command options] [arguments...]

VERSION:
   v1.5.9

AUTHOR:
   Rancher Labs, Inc.

COMMANDS:
   up       Bring the cluster up
   remove   Teardown the cluster and clean cluster nodes
   version  Show cluster Kubernetes version
   config   Setup cluster configuration
   etcd     etcd snapshot save/restore operations in k8s cluster
   cert     Certificates management for RKE cluster
   encrypt  Manage cluster encryption provider keys
   util     Various utilities to retrieve cluster related files and troubleshoot
   help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --debug, -d    Debug logging
   --quiet, -q    Quiet mode, disables logging and only critical output will be printed
   --trace        Trace logging
   --help, -h     show help
   --version, -v  print the version
bash 复制代码
# 查看集群版本
rke version

# 生成配置(交互方式)
rke config --name cluster.yml

# 生成配置(空模版)
rke config --name cluster.yml --empty

# 清理集群,可选参数:--config 指定配置,--force 强制清理
rke remove

五、写在最后

本文之后,关于 kubernetes 安装方法的专题介绍将告一段落,各位读者可以按照自己的喜好以及需求场景,选择部署 kubernetes 集群的方法。

此外,笔者还使用和验证过 kubeadm、kubeasz、kubekey 等工具,以及二进制方式手动安装 kubernetes 的方法,感兴趣的读者可以私信留言,了解相关信息。

相关推荐
ZHOU西口43 分钟前
微服务实战系列之玩转Docker(十八)
分布式·docker·云原生·架构·数据安全·etcd·rbac
牛角上的男孩1 小时前
Istio Gateway发布服务
云原生·gateway·istio
JuiceFS3 小时前
好未来:多云环境下基于 JuiceFS 建设低运维模型仓库
运维·云原生
景天科技苑3 小时前
【云原生开发】K8S多集群资源管理平台架构设计
云原生·容器·kubernetes·k8s·云原生开发·k8s管理系统
wclass-zhengge4 小时前
K8S篇(基本介绍)
云原生·容器·kubernetes
颜淡慕潇4 小时前
【K8S问题系列 |1 】Kubernetes 中 NodePort 类型的 Service 无法访问【已解决】
后端·云原生·容器·kubernetes·问题解决
昌sit!12 小时前
K8S node节点没有相应的pod镜像运行故障处理办法
云原生·容器·kubernetes
A ?Charis15 小时前
Gitlab-runner running on Kubernetes - hostAliases
容器·kubernetes·gitlab
茶馆大橘16 小时前
微服务系列五:避免雪崩问题的限流、隔离、熔断措施
java·jmeter·spring cloud·微服务·云原生·架构·sentinel
北漂IT民工_程序员_ZG16 小时前
k8s集群安装(minikube)
云原生·容器·kubernetes