Rancher 2集群安装

先决条件

  1. 安装 ubuntu 18 使用初始化脚本
  2. 注意 docker 版本

安装 k8s 集群

ssh 互信

  1. 集群机器分别新建用户 rancher
1
2
3
4
5
6
7
8
9
10
11
12
adduser rancher
groupadd docker
usermod -a -G rancher,docker rancher

# ssh互信
ssh-keygen -t rsa
chmod 750 ~/.ssh/
chmod 600 ~/.ssh/id_rsa
chmod 600 ~/.ssh/authorized_keys

# 每台机器添加到authorized_keys,并复制到每台机器
id_rsa.pub >> authorized_keys

rke 安装

  1. 下载 rke http://mirror.cnrancher.com rancher 国内镜像站
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
cp rke_linux-amd64 rke
chomd +x rke
./rek --version

vim cluster.yml
nodes:
- address: 172.60.20.205 #节点地址
user: rancher
role:
- controlplane
- etcd
- worker
- address: 172.60.20.206
user: rancher
role:
- controlplane
- etcd
- worker
- address: 172.60.20.207
user: rancher
role:
- controlplane
- etcd
- worker
cluster_name: sz-cluster
# 外部TLS终止
ingress:
provider: nginx
options:
use-forwarded-headers: "true"

./rke up

验证 k8s 集群

1
2
cp kube_config_cluster.yml .kube/config/
kubectl get node

安装 Rancher

安装 helm

  1. 下载 helm http://mirror.cnrancher.com rancher 国内镜像站
1
2
3
4
wget http://rancher-mirror.cnrancher.com/helm/v3.4.2/helm-v3.4.2-linux-amd64.tar.gz
tar -zxvf helm-v3.4.2-linux-amd64.tar.gz
mv linux-amd64/helm .
chmod +x helm

安装 rancher

1
2
3
4
5
helm repo add rancher-stable http://rancher-mirror.oss-cn-beijing.aliyuncs.com/server-charts/stable
kubectl create namespace cattle-system

# 使用外部TLS终止
helm install rancher rancher-stable/rancher --namespace cattle-system --set hostname=sz-rancher.bdx.jiankangsn.com --set tls=external

外部 Nginx 代理 Rancher

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
worker_processes 4;
worker_rlimit_nofile 40000;

events {
worker_connections 8192;
}

http {
upstream rancher {
server IP_NODE_1:80;
server IP_NODE_2:80;
server IP_NODE_3:80;
}

map $http_upgrade $connection_upgrade {
default Upgrade;
'' close;
}

server {
listen 443 ssl http2;
server_name FQDN;
ssl_certificate /certs/fullchain.pem;
ssl_certificate_key /certs/privkey.pem;

location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://rancher;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
# 这里将允许您在 Rancher UI 中打开命令行窗口时,窗口可以保留最多15分钟。没有这个参数时,默认值为1分钟,一分钟后在Rancher中的shell会自动关闭。
proxy_read_timeout 900s;
proxy_buffering off;
}
}

server {
listen 80;
server_name FQDN;
return 301 https://$server_name$request_uri;
}
}

安装 Longhorn

格式化硬盘

1
2
3
4
5
fdisk /dev/sdb
mkfs -t ext4 /dev/sdb1
mkdir /var/lib/longhorn #默认路径
mount /dev/sdb1 /var/lib/longhorn
echo '/dev/sdb1 /var/lib/longhorn ext4 defaults 0 0' >> /etc/fstab