RKE2创建高可用K8S

三台节点同时做master和worker工作:
192.168.1.1 node01 2cpu 4G内存 40G硬盘
192.168.1.2 node02 2cpu 4G内存 40G硬盘
192.168.1.3 node03 2cpu 4G内存 40G硬盘

1、三个节点都执行以下操作

#分别在三台节点上设置hostname
hostnamectl set-hostname node01 && bash
hostnamectl set-hostname node02 && bash
hostnamectl set-hostname node03 && bash

#在三台节点上设置hosts
cat >> /etc/hosts << EOF
192.168.1.1 node01
192.168.1.2 node02
192.168.1.3 node03
EOF

#关闭三台节点上的防火墙
systemctl stop firewalld
systemctl disable firewalld

#关闭三台节点上的selinux
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/'  /etc/selinux/config 

#关闭三台节点上的swap分区
swapoff -a
sed -ri 's/.*swap.*/#&/' /etc/fstab

#配置三台节点上的仓库文件
curl -o /etc/yum.repos.d/Centos-7.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/docker-ce.repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

#在三台节点上安装必要的软件
yum install -y ntpdate vim wget tree httpd-tools telnet  lrzsz  net-tools bridge-utils  unzip
yum clean all && yum makecache

#同步三台节点的时区和时间到上海时区
ln -sf /usr/share/zoneinfo/Asia/Shanghai  /etc/localtime
ntpdate -u ntp.aliyun.com && date

#修改三台节点的内核参数
cat <<EOF >>  /etc/sysctl.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward=1
EOF

#加载br_netfilter网络过滤器模块
modprobe br_netfilter

#sysctl命令动态修改内核参数
sysctl -p /etc/sysctl.conf

master节点都需要安装rke2-server,先安装第一个rke2-server,后面2个需要添加config.yaml与第一个rke2-server产生连接

2、在node1上操作

1.运行安装程序,将rke2-server 服务和rke2 二进制文件安装到机器上
curl -sfL  https://get.rke2.io   | sh -
或者指定安装版本
curl -sfL http://rancher-mirror.rancher.cn/rke2/install.sh | INSTALL_RKE2_MIRROR=cn INSTALL_RKE2_VERSION=v1.21.9+rke2r1 sh -
 
2.开启rke2-server 服务 
systemctl enable rke2-server
 
3.启动服务
systemctl start rke2-server
 #大概十几二十分钟
4.查看日志
journalctl -fu rke2-server.service
#志没有报错了,可能已经安装完成了
#查看是否安装完成,完成后配置环境变量
/var/lib/rancher/rke2/bin/kubectl \
        --kubeconfig /etc/rancher/rke2/rke2.yaml get nodes

3、配置环境变量

vim /etc/profile
#把这两行加进去
export PATH=/var/lib/rancher/rke2/bin:$PATH
export KUBECONFIG=/etc/rancher/rke2/rke2.yaml

#使环境变量生效,这样就可以使用kubectl命令了
source /etc/profile
#查看node情况
kubectl  get nodes

config.yaml文件

#node1里查看下加入集群需要的token
cat /var/lib/rancher/rke2/server/node-token
#记录下来要填写在/etc/rancher/rke2/config.yaml文件
vim /etc/rancher/rke2/config.yaml
#把以下内容粘贴进行并进行修改自己的属性值,token和主机名字和ip

token: K10cc8748a3379c2828abdabd819a919f6adcac08a4bc11ab09718456355f893353::server:8b16b770abd8674c5fb0230ba64eebda
tls-san:
  - my-kubernetes-domain.com
  - another-kubernetes-domain.com
  - 192.168.1.1

node-name: "node01"

#node-taint:
#  - "CriticalAddinsonly=true:NoExecute"

node-label:
  - "node=Master"
  - "node01=Master"

在node2上配置(node3一样的步骤):

安装RKE2前先配置config.yaml文件,不然安装的node2,node3会变成另一个独立的K8S集群

mkdir -p /etc/rancher/rke2/
vi /etc/rancher/rke2/config.yaml
#把以下内容复制进去修改

#这个是自己的node1的ip
server: https://192.168.1.1:9345
#token为Node1获取
token: K10cc8748a3379c2828abdabd819a919f6adcac08a4bc11ab09718456355f893353::server:8b16b770abd8674c5fb0230ba64eebda
tls-san:
  - my-kubernetes-domain.com
  - another-kubernetes-domain.com
  - 192.168.1.1

node-name: "node02"

#node-taint:
#  - "CriticalAddinsonly=true:NoExecute"

node-label:
  - "node=Master"
  - "node02=Master"

安装rke2

#安装rke2
curl -sfL  https://get.rke2.io   | sh -

#设置开机启动rke2
systemctl enable rke2-server

#启动rke2
systemctl start rke2-server
#查看node节点情况
kubectl get nodes
#查看kube-system内服务情况
kubectl -n kube-system get pods

参考链接

https://zhuanlan.zhihu.com/p/494603305
https://docs.rancher.cn/docs/rancher2.5/installation/resources/k8s-tutorials/ha-rke2/_index

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值