Rancher 系列文章-在腾讯云的 K3S 上安装高可用 Rancher 集群 - 东风微鸣
source link: https://www.cnblogs.com/east4ming/p/17254758.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Rancher 系列文章-在腾讯云的 K3S 上安装高可用 Rancher 集群
📜 引言:
- 三人行必有我师焉
- 知识共享,天下为公
在腾讯云的 K3S 上安装 Rancher
- 高可用
- 3 台 master 的 k3s 集群
- 高可用模式的 rancher
- 数据备份
- rancher 数据备份到 腾讯云对象存储 cos
- 安全加密
- 不能存在 http,全部是 https
- 面向客户
- 公网可访问;
- 域名可访问;
- 尽量复用公有云的能力
- Tencent Cloud Controller Manager (❌ 因为腾讯云已经放弃维护相关源码,所以无法复用)
- SVC LoadBalancer 调用 CLB (❌ 因为腾讯云已经放弃维护相关源码,所以无法复用)
- CLB - 使用 4 层 CLB
- 备份 - 使用腾讯云 COS
-
有腾讯云账户,账户至少拥有如下权限:auto k3s 安装 - 设置 CAM 以及这些权限:
QcloudTAGFullAccess
-
该腾讯云账号有对应的 API 密钥,地址:访问密钥 - 控制台 (tencent.com) ,或者拥有相关权限:
cam:QueryCollApiKey
和cam:CreateCollApiKey
-
一个对象存储通 cos,用于备份
-
Rancher 的域名
-
Rancher 的域名对应的证书(如果没有,会尝试通过 cert-manager 和 let’s encrypt 自动生成免费的证书)
Rancher 安装注意事项
-
安装前需要调整:
-
安装后需要配置:
- Backup
-
⚠️付费模式,COS 按需调整付费模式。
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 chart 并创建 ns:
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:
注意 Rancher 域名的 443 权限要开通。
ℹ️ Info:
- 要安装一个特定的 Rancher 版本,使用
--version
标志,例如:--version 2.3.6
。
之后访问 UI 进行初始密码设置等工作。
🎉 至此,Rancher 高可用集群安装完成。
Rancher 中国区优化配置
参考这里:
调整安全组
入站规则:
- TCP:22(SSH) 端口权限收紧
- TCP:6443(K8S API) 端口权限收紧
- UDP:8472(K3s vxlan) 只开放给内网
- TCP:10250(kube api-server) 只开放给内网
最终效果如下:(应该可以进一步收紧)
📚️ Quote:
我们建议将负载均衡器配置为 4 层均衡器,将普通 80/tcp 和 443/tcp 转发到 Rancher 管理集群节点。集群上的 Ingress Controller 会将端口 80 上的 http 通信重定向到端口 443 上的 https。
如上面所述,所以通过 4 层 LB, 将 443/tcp 转到后端。如下图:
配置 Rancher Backup
📚️ Quote:
通过 UI 安装:
先创建 cos 存储的认证信息 Secret:
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, 如下:
🎉 登录 COS 发现已经成功备份。
🎉🎉🎉 至此,完成腾讯云上 K3S 高可用集群 及 Rancher 高可用集群的搭建,并配置备份。
以下是安装的相关信息:
-
3 个 Master 和 Server 地址
-
K3S API Server 地址:
https://<3个master IP 地址任一个>:6443
(6443 端口目前没有配置 CLB) -
K3S kubeconfig 配置:位于 k3s 的
/etc/rancher/k3s/k3s.yaml
以及操作机的/root/.autok3s/.kube/config
Rancher
- 地址:
- 公网访问:
https://<your-rancher-domain>:<port>/
- 内网访问:
https://<your-rancher-domain>:443
(需要编辑自己电脑的hosts
, 将 3 个 master 任一内网 IP 映射到该域名)
- 公网访问:
- 账号:
Admin
使用的安全组,最终配置如下:(应该可以进一步收紧)
使用的 CLB
监听器为:rancher(TCP:<port>)
转到 3 台 master 的 443 端口。
备份 COS
K3S 和 Rancher 都配置了备份,备份到对象存储 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 编写.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK