K8S UI 之 Rancher

摘要

Rancher 简介

  • Rancher 是一个 开源的 Kubernetes 管理平台,用于帮助用户部署、管理和运维多个 Kubernetes 集群,具有易用的 Web UI、权限控制、集群监控、应用管理等功能,广泛应用于企业的云原生平台建设中。

部署 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# 添加 rancher 的 Helm 仓库
helm repo add rancher-latest https://releases.rancher.com/server-charts/latest
# 更新 rancher 的 Helm 仓库
helm repo update

# 查看 rancher 的版本
$ helm search repo rancher -l | head
NAME CHART VERSION APP VERSION DESCRIPTION
rancher-latest/rancher 2.11.3 v2.11.3 Install Rancher Server to manage Kubernetes clu...
rancher-latest/rancher 2.11.2 v2.11.2 Install Rancher Server to manage Kubernetes clu...
rancher-latest/rancher 2.11.1 v2.11.1 Install Rancher Server to manage Kubernetes clu...
rancher-latest/rancher 2.11.0 v2.11.0 Install Rancher Server to manage Kubernetes clu...
rancher-latest/rancher 2.10.3 v2.10.3 Install Rancher Server to manage Kubernetes clu...
rancher-latest/rancher 2.10.2 v2.10.2 Install Rancher Server to manage Kubernetes clu...
rancher-latest/rancher 2.10.1 v2.10.1 Install Rancher Server to manage Kubernetes clu...
rancher-latest/rancher 2.10.0 v2.10.0 Install Rancher Server to manage Kubernetes clu...
rancher-latest/rancher 2.9.3 v2.9.3 Install Rancher Server to manage Kubernetes clu...

# 创建命名空间
kubectl create namespace cattle-system

# 创建证书,证书是机构颁发的
kubectl create secret tls tls-rancher-ingress \
--key=nginx_ssl/nginx.hanqunfeng.com.key \
--cert=nginx_ssl/nginx.hanqunfeng.com.pem \
-n cattle-system

# 安装 Rancher --version v2.11.3 可以指定版本,默认最新版
helm install rancher rancher-latest/rancher \
--namespace cattle-system \
--create-namespace \
--set hostname=rancher.hanqunfeng.com \
--set ingress.tls.source=secret \
--set replicas=3 \
--set bootstrapPassword=rancher#2025

## 参数说明
# --set hostname=rancher.hanqunfeng.com 设置 rancher 的域名
# --set ingress.tls.source=secret 配置 rancher 的证书,名称为 tls-rancher-ingress
# --set replicas=3 设置 rancher 的副本数
# --set bootstrapPassword=rancher#2025 设置 rancher 的初始密码

## 不过执行上面的安装命令会报错,应该是当前的 rancher 版本不支持 Kubernetes v1.33.2
Error: INSTALLATION FAILED: chart requires kubeVersion: < 1.33.0-0 which is incompatible with Kubernetes v1.33.2

## 解决办法
# 下载并解压 rancher 安装包
helm pull rancher-latest/rancher --untar --untardir ./
# 修改其中的 Chart.yaml 文件
kubeVersion: < 1.33.0-0 ==> kubeVersion: < 1.34.0-0

# 安装 rancher
helm install rancher rancher \
--namespace cattle-system \
--create-namespace \
--set hostname=rancher.hanqunfeng.com \
--set ingress.tls.source=secret \
--set replicas=3 \
--set bootstrapPassword=rancher#2025
## 输出
NAME: rancher
LAST DEPLOYED: Thu Jul 24 23:55:24 2025
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://rancher.hanqunfeng.com 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://rancher.hanqunfeng.com/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!
  • 查看创建的资源

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
$ k get all,ing -n cattle-system
NAME READY STATUS RESTARTS AGE
pod/helm-operation-8257k 0/2 Completed 0 11m
pod/helm-operation-g8blp 0/2 Completed 0 12m
pod/helm-operation-hwpbp 0/2 Completed 0 10m
pod/helm-operation-qbs5n 0/2 Completed 0 10m
pod/helm-operation-wlptb 0/2 Completed 0 13m
pod/rancher-56689b7d8c-v7hpd 1/1 Running 0 21m
pod/rancher-56689b7d8c-xnrbf 1/1 Running 0 21m
pod/rancher-56689b7d8c-xvqgs 1/1 Running 0 21m
pod/rancher-webhook-5fd5fc44f9-8xwjk 1/1 Running 0 11m

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/imperative-api-extension ClusterIP 10.96.188.28 <none> 6666/TCP 15m
service/rancher ClusterIP 10.96.21.41 <none> 80/TCP,443/TCP 21m
service/rancher-webhook ClusterIP 10.96.85.153 <none> 443/TCP 11m

NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/rancher 3/3 3 3 21m
deployment.apps/rancher-webhook 1/1 1 1 11m

NAME DESIRED CURRENT READY AGE
replicaset.apps/rancher-56689b7d8c 3 3 3 21m
replicaset.apps/rancher-webhook-5fd5fc44f9 1 1 1 11m

NAME CLASS HOSTS ADDRESS PORTS AGE
ingress.networking.k8s.io/rancher nginx rancher.hanqunfeng.com 10.211.55.201 80, 443 21m
1
2
# 如果忘记初始密码可以通过如下命令查看密码
kubectl get secret --namespace cattle-system bootstrap-secret -o go-template='{{.data.bootstrapPassword|base64decode}}{{"\n"}}'

卸载 Rancher

1
2
3
4
# 卸载 Rancher
helm uninstall rancher -n cattle-system
# 删除 cattle-system 命名空间
kubectl delete namespace cattle-system