Rancher HA 集群搭建(v2.4.11)

765 阅读1分钟

前期准备:

  • 私有仓库harbor搭建
  • 同步rancher 2.4.11 版本的基础镜像
  • 域名和域名证书

集群安装

rancher HA 集群

一、节点准备

负载均衡节点 192.168.142.171 rancher节点: 192.168.142.111-113 待补充……

1.1 开启节点端口/或者关闭防火墙
sudo sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
firewall-cmd --zone=public --add-port=1-65535/tcp –permanent
firewall-cmd --zone=public --add-port=1-65535/udp –permanent
firewall-cmd –reload
1.2 同步时间

以192.168.142.112为时间同步服务器

sudo yum install -y ntp
echo "SYNC_HWCLOCK=yes" >> /etc/sysconfig/ntpd
sudo systemctl start ntpd
sudo ntpdate 192.168.142.112
1.3 安装docker

此处安装docker-ce 18~19版本;不能使用20

yum install -y yum-utils  device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install docker-ce -y

修改docker路径可以参考我之前的博客

1.4 授权非root用户运行docker

因为centos有安全限制,不建议使用root远程运行docker;所以需要创建一个普通用户来运行 useradd rancher -G docker echo "123456" | passwd --stdin rancher

如果是已经存在的用户则需要运行 sudo gpasswd -a ${USER} docker sudo service docker restart

1.5 配置ssh key

在192.168.142.111/112/113 服务器上运行 在rancher用户下运行: ssh-keygen 一直回车,不设置密码 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys sz id_rsa 到Nginx负载的节点 chmod 700 .ssh chmod 600 authorized_keys

二、安装RKE

2.1 下载rke_linux-amd64

rancher-2.4.11对应版本

mv rke_linux-amd64 rke
chmod a+x rke
2.2 创建RKE配置文件
# vi rancher-cluster.yml
nodes:
  - address: 192.168.142.111 # 离线环境节点 IP
    user: rancher
    role: ["controlplane", "etcd", "worker"]
    ssh_key_path: ./id_rsa111
  - address: 192.168.142.112 # 离线环境节点 IP
    user: rancher
    role: ["controlplane", "etcd", "worker"]
    ssh_key_path: ./id_rsa112
  - address: 192.168.142.113 # 离线环境节点 IP
    user: rancher
    role: ["controlplane", "etcd", "worker"]
    ssh_key_path: ./id_rsa113
private_registries:
  - url:  # 私有镜像库地址
    user: 
    password:  
    is_default: true
services:
  kube-api:
    service_node_port_range: 1-65535
2.3 安装kubernetes
./rke up --config ./rancher-cluster.yml
第一次执行会稍微慢点,如果出现错误就在运行一遍以下命令
./rke up --update-only --config ./rancher-cluster.yml

三、配置nginx负载均衡

worker_processes 4;
worker_rlimit_nofile 40000;

events {
    worker_connections 8192;
}

stream {
    upstream rancher_servers_http {
        least_conn;
        server 192.168.142.111:80 max_fails=3 fail_timeout=5s;
        server 192.168.142.112:80 max_fails=3 fail_timeout=5s;
        server 192.168.142.113:80 max_fails=3 fail_timeout=5s;
    }
    server {
        listen 80;
        proxy_pass rancher_servers_http;
    }

    upstream rancher_servers_https {
        least_conn;
        server 192.168.142.111:443 max_fails=3 fail_timeout=5s;
        server 192.168.142.112:443 max_fails=3 fail_timeout=5s;
        server 192.168.142.113:443 max_fails=3 fail_timeout=5s;
    }
    server {
        listen     443;
        proxy_pass rancher_servers_https;
    }

}

四、helm生成rancher yaml文件

helm repo add rancher-stable https://releases.rancher.com/server-charts/stable
helm fetch rancher-stable/rancher --version 2.4.11
helm template rancher ./rancher-2.4.11.tgz --output-dir .     
--namespace cattle-system     
--set hostname=xxxx.xxx.com     
--set rancherImage=xxx.xxx.xxx/rancher/rancher    
--set ingress.tls.source=secret     
--set systemDefaultRegistry=harbor.xxx.com     
--set useBundledSystemChart=true 

五、安装kubectl

curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod a+x kubectl
5.1 创建命名空间
./kubectl --kubeconfig kube_config_rancher-cluster.yml create namespace cattle-system
./kubectl --kubeconfig kube_config_rancher-cluster.yml -n cattle-system create secret tls tls-rancher-ingress   --cert=tls.crt   --key=tls.key
5.2 、安装rancher
./kubectl --kubeconfig kube_config_rancher-cluster.yml -n cattle-system apply -R -f ./rancher

六、注意点

待补充