开篇
引言:
三人行必有我师焉
- 知识共享,天下为公
- 《K3s 系列文章》
- 《Rancher 系列文章》
方案
在腾讯云的 K3S 上安装 Rancher
方案目标
- 高可用
- 3 台 master 的 k3s 集群
- 高可用模式的 rancher
- 数据备份
- rancher 数据备份到 腾讯云对象存储 cos
- 不能存在 http,全部是 https
- 公网可访问;
前提条件
QcloudTAGFullAccess
-
该腾讯云账号有对应的 API 密钥,地址:访问密钥 - 控制台 (tencent.com,或者拥有相关权限:
cam:QueryCollApiKey
和cam:CreateCollApiKey
-
Rancher 的域名
注意事项
Rancher 安装注意事项
-
- 安全组
-
安装后需要配置:
- LB
- Backup
通过 Helm Chart 进行高可用安装
安装步骤
Rancher
🚩 Important:
通过 Helm Chart 安装
Rancher 端口要求
Quote:
Rancher Server 节点的入站规则
协议 | 端口 | 来源 | 描述 |
---|---|---|---|
TCP | 80 | Load balancer/proxy,做外部 SSL 终端 | 使用外部 SSL 终止时的 Rancher UI/API |
TCP | 443 | server 节点 agent 节点托管/注册的 Kubernetes 任何需要能够使用 Rancher UI 或 API 的源 | Rancher agent, Rancher UI/API, kubectl |
TCP | 6443 | K3s server 节点 | Kubernetes API |
Rancher 高可用安装
helm repo add rancher-stable http://rancher-mirror.oss-cn-beijing.aliyuncs.com/server-charts/stable
kubectl create namespace cattle-system
SSL 选项为:已有的证书,通过 Helm 安装 Rancher:
Quote:
先添加证书到 k8s secret:
kubectl -n cattle-system create secret tls tls-rancher-ingress \
--cert=tls.crt \
--key=tls.key
helm install rancher rancher-stable/rancher \
--namespace cattle-system \
--set hostname=<your-rancher-domain> \
--set replicas=3 \
--set ingress.tls.source=secret \
--set systemDefaultRegistry=registry.cn-hangzhou.aliyuncs.com \
--set auditLog.level=1 \
运行后输出如下:
NAME: rancher
LAST DEPLOYED: Sat Feb 12 20:10:14 2022
NAMESPACE: cattle-system
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
Rancher Server has been installed.
NOTE: Rancher may take several minutes to fully initialize. Please standby while Certificates are being issued, Containers are started and the Ingress rule comes up.
Check out our docs at https://rancher.com/docs/
If you provided your own bootstrap password during installation, browse to https://<your-rancher-domain> to get started.
If this is the first time you installed Rancher, get started by running this command and clicking the URL it generates:
echo https://<your-rancher-domain>/dashboard/?setup=$(kubectl get secret --namespace cattle-system bootstrap-secret -o go-template='{{.data.bootstrapPassword|base64decode}}'
To get just the bootstrap password on its own, run:
kubectl get secret --namespace cattle-system bootstrap-secret -o go-template='{{.data.bootstrapPassword|base64decode}}{{ "\n" }}'
Happy Containering!
🔥 Notice:
ℹ️ Info:
要安装一个特定的 Rancher 版本,使用
--version
标志,例如:--version 2.3.6
。
🎉 至此,Rancher 高可用集群安装完成。
Rancher 中国区优化配置
- Rancher 中国区优化配置
收尾工作
调整安全组
入站规则:
- TCP:22(SSH 端口权限收紧
- TCP:6443(K8S API 端口权限收紧
- UDP:8472(K3s vxlan 只开放给内网
- TCP:10250(kube api-server 只开放给内网
配置 LB
Quote:
我们建议将负载均衡器配置为 4 层均衡器,将普通 80/tcp 和 443/tcp 转发到 Rancher 管理集群节点。集群上的 Ingress Controller 会将端口 80 上的 http 通信重定向到端口 443 上的 https。
配置 Rancher Backup
Quote:
备份 Rancher | Rancher 文档
通过 UI 安装:
apiVersion: v1
stringData:
accessKey: <your-ak>
secretKey: <your-sk>
kind: Secret
metadata:
name: cos-creds
namespace: cattle-resources-system
type: Opaque
然后在 应用市场 选择 Rancher Backup 安装:
helm upgrade --install=true --namespace=cattle-resources-system --timeout=10m0s --values=/home/shell/helm/values-rancher-backup-crd-2.1.0.yaml --version=2.1.0 --wait=true rancher-backup-crd /home/shell/helm/rancher-backup-crd-2.1.0.tgz
...
---------------------------------------------------------------------
SUCCESS: helm upgrade --install=true --namespace=cattle-resources-system --timeout=10m0s --values=/home/shell/helm/values-rancher-backup-crd-2.1.0.yaml --version=2.1.0 --wait=true rancher-backup-crd /home/shell/helm/rancher-backup-crd-2.1.0.tgz
---------------------------------------------------------------------
helm upgrade --install=true --namespace=cattle-resources-system --timeout=10m0s --values=/home/shell/helm/values-rancher-backup-2.1.0.yaml --version=2.1.0 --wait=true rancher-backup /home/shell/helm/rancher-backup-2.1.0.tgz
...
---------------------------------------------------------------------
SUCCESS: helm upgrade --install=true --namespace=cattle-resources-system --timeout=10m0s --values=/home/shell/helm/values-rancher-backup-2.1.0.yaml --version=2.1.0 --wait=true rancher-backup /home/shell/helm/rancher-backup-2.1.0.tgz
---------------------------------------------------------------------
配置 Backup, 如下:
总结
🎉🎉🎉 至此,完成腾讯云上 K3S 高可用集群 及 Rancher 高可用集群的搭建,并配置备份。
K3s
-
https://<3个master IP 地址任一个>:6443 (6443 端口目前没有配置 CLB
-
/etc/rancher/k3s/k3s.yaml 以及操作机的
/root/.autok3s/.kube/config
3 个 Master 和 Server 地址
Rancher
- 地址:
- 公网访问:
https://<your-rancher-domain>:<port>/
- 内网访问:
https://<your-rancher-domain>:443
(需要编辑自己电脑的hosts
, 将 3 个 master 任一内网 IP 映射到该域名) - 账号:
Admin
- 密码
安全组
CLB
监听器为:rancher(TCP:<port>
转到 3 台 master 的 443 端口。
备份 COS
- 桶:rancher-backup-
- 域名:
https://rancher-backup-<cos-id>.cos.ap-shanghai.myqcloud.com
- S3 Endpoint:
cos.ap-shanghai.myqcloud.com
- 文件夹为:
- k3s 为:
/rancher-1/rancher/rancher
(备份策略:每天 0 点备份,保留 5 份) - rancher 为:
/rancher-1/rancher/k3s
(备份策略,每天 0 点备份)
- k3s 为:
- COS 生命周期为:自动清理 1 个月前的文件。(配置 自动清理规则)
三人行, 必有我师; 知识共享, 天下为公. 本文由东风微鸣技术博客 EWhisper.cn 编写。