三臺節(jié)點同時做master和worker工作:
192.168.1.1 node01 2cpu 4G內(nèi)存 40G硬盤
192.168.1.2 node02 2cpu 4G內(nèi)存 40G硬盤
192.168.1.3 node03 2cpu 4G內(nèi)存 40G硬盤
1、三個節(jié)點都執(zhí)行以下操作
#分別在三臺節(jié)點上設(shè)置hostname
hostnamectl set-hostname node01 && bash
hostnamectl set-hostname node02 && bash
hostnamectl set-hostname node03 && bash
#在三臺節(jié)點上設(shè)置hosts
cat >> /etc/hosts << EOF
192.168.1.1 node01
192.168.1.2 node02
192.168.1.3 node03
EOF
#關(guān)閉三臺節(jié)點上的防火墻
systemctl stop firewalld
systemctl disable firewalld
#關(guān)閉三臺節(jié)點上的selinux
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
#關(guān)閉三臺節(jié)點上的swap分區(qū)
swapoff -a
sed -ri 's/.*swap.*/#&/' /etc/fstab
#配置三臺節(jié)點上的倉庫文件
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
#在三臺節(jié)點上安裝必要的軟件
yum install -y ntpdate vim wget tree httpd-tools telnet lrzsz net-tools bridge-utils unzip
yum clean all && yum makecache
#同步三臺節(jié)點的時區(qū)和時間到上海時區(qū)
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
ntpdate -u ntp.aliyun.com && date
#修改三臺節(jié)點的內(nèi)核參數(shù)
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網(wǎng)絡(luò)過濾器模塊
modprobe br_netfilter
#sysctl命令動態(tài)修改內(nèi)核參數(shù)
sysctl -p /etc/sysctl.conf
master節(jié)點都需要安裝rke2-server,先安裝第一個rke2-server,后面2個需要添加config.yaml與第一個rke2-server產(chǎn)生連接
2、在node1上操作
1.運行安裝程序,將rke2-server 服務(wù)和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 服務(wù)
systemctl enable rke2-server
3.啟動服務(wù)
systemctl start rke2-server
#大概十幾二十分鐘
4.查看日志
journalctl -fu rke2-server.service
#志沒有報錯了,可能已經(jīng)安裝完成了
#查看是否安裝完成,完成后配置環(huán)境變量
/var/lib/rancher/rke2/bin/kubectl \
--kubeconfig /etc/rancher/rke2/rke2.yaml get nodes
3、配置環(huán)境變量
vim /etc/profile
#把這兩行加進去
export PATH=/var/lib/rancher/rke2/bin:$PATH
export KUBECONFIG=/etc/rancher/rke2/rke2.yaml
#使環(huán)境變量生效,這樣就可以使用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
#把以下內(nèi)容粘貼進行并進行修改自己的屬性值,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
#把以下內(nèi)容復(fù)制進去修改
#這個是自己的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 -
#設(shè)置開機啟動rke2
systemctl enable rke2-server
#啟動rke2
systemctl start rke2-server
#查看node節(jié)點情況
kubectl get nodes
#查看kube-system內(nèi)服務(wù)情況
kubectl -n kube-system get pods
參考鏈接文章來源:http://www.zghlxwxcb.cn/news/detail-504534.html
https://zhuanlan.zhihu.com/p/494603305
https://docs.rancher.cn/docs/rancher2.5/installation/resources/k8s-tutorials/ha-rke2/_index文章來源地址http://www.zghlxwxcb.cn/news/detail-504534.html
到了這里,關(guān)于RKE2創(chuàng)建高可用K8S的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!