3. 安裝 Rancher
現在您已經有一個執行中的 RKE2/K3s 叢集,您可以在其中安裝 Rancher。出於安全考量,所有到 Rancher 的流量都必須使用 TLS 加密。在本教學中,您將透過 cert-manager 自動簽發自簽憑證。在實際使用案例中,您可能會使用 Let's Encrypt 或提供您自己的憑證。
安裝 Helm CLI
Helm 2 已被棄用
Helm 2 不再受支援。請改用 Helm 3。
在可以使用 kubeconfig 存取您的 Kubernetes 叢集的主機上安裝 Helm CLI:
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
chmod +x get_helm.sh
sudo ./get_helm.sh
安裝 cert-manager
新增 cert-manager Helm 儲存庫:
helm repo add jetstack https://charts.jetstack.io
為 cert-manager 建立命名空間:
kubectl create namespace cert-manager
安裝 cert-manager 的 CustomResourceDefinitions:
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/<VERSION>/cert-manager.crds.yaml
然後使用 Helm 安裝它。請注意,cert-manager 也需要設定您的代理,以防它需要與 Let's Encrypt 或其他外部憑證簽發者通訊:
備註
若要查看如何自訂 cert-manager 安裝的選項(包括您的叢集使用 PodSecurityPolicies 的情況),請參閱 cert-manager 文件。
helm upgrade --install cert-manager jetstack/cert-manager \
--namespace cert-manager \
--set http_proxy=http://${proxy_host} \
--set https_proxy=http://${proxy_host} \
--set no_proxy=127.0.0.0/8\\,10.0.0.0/8\\,cattle-system.svc\\,172.16.0.0/12\\,192.168.0.0/16\\,.svc\\,.cluster.local
現在您應該等待 cert-manager 完成啟動:
kubectl rollout status deployment -n cert-manager cert-manager
kubectl rollout status deployment -n cert-manager cert-manager-webhook
安裝 Rancher
接下來您可以安裝 Rancher 本身。首先,新增 Helm 儲存庫:
helm repo add rancher-latest https://releases.rancher.com/server-charts/latest
建立命名空間:
kubectl create namespace cattle-system
然後使用 Helm 安裝 Rancher。Rancher 也需要代理設定,以便它可以與外部應用程式目錄通訊或擷取 Kubernetes 版本更新後設資料:
helm upgrade --install rancher rancher-latest/rancher \
--namespace cattle-system \
--set hostname=rancher.example.com \
--set proxy=http://${proxy_host} \
--set noProxy=127.0.0.0/8\\,10.0.0.0/8\\,cattle-system.svc\\,172.16.0.0/12\\,192.168.0.0/16\\,.svc\\,.cluster.local
等待部署完成後:
kubectl rollout status deployment -n cattle-system rancher
您現在可以導覽至 https://rancher.example.com 並開始使用 Rancher。
其他資源
這些資源在安裝 Rancher 時可能會有所幫助: