跳至主要内容

Rancher HA

本頁面列出的命令/步驟可用於檢查你的 Rancher Kubernetes 安裝。

確保你配置了正確的 kubeconfig(例如,export KUBECONFIG=$PWD/kube_config_cluster.yml)。

檢查 Rancher Pod​

Rancher Pod 在 cattle-system 命名空間中部署為 Deployment。

檢查 Pod 是否在所有節點上執行:

kubectl -n cattle-system get pods -l app=rancher -o wide

範例輸出:

NAME                       READY   STATUS    RESTARTS   AGE   IP          NODE
rancher-7dbd7875f7-n6t5t 1/1 Running 0 8m x.x.x.x x.x.x.x
rancher-7dbd7875f7-qbj5k 1/1 Running 0 8m x.x.x.x x.x.x.x
rancher-7dbd7875f7-qw7wb 1/1 Running 0 8m x.x.x.x x.x.x.x

如果 Pod 無法執行(狀態不是 Running,Ready 狀態未顯示 1/1,或你看到大量的重新啟動),請檢查 Pod 詳細資訊、日誌和命名空間事件。

Pod 詳細資訊​

kubectl -n cattle-system describe pods -l app=rancher

Pod 容器日誌​

kubectl -n cattle-system logs -l app=rancher

命名空間事件​

kubectl -n cattle-system get events

檢查 Ingress​

Ingress 應該具有正確的 HOSTS(顯示配置的 FQDN)和 ADDRESS(它將路由到的主機地址)。

kubectl -n cattle-system get ingress

範例輸出:

NAME      HOSTS                    ADDRESS                   PORTS     AGE
rancher rancher.yourdomain.com x.x.x.x,x.x.x.x,x.x.x.x 80, 443 2m

檢查 Ingress Controller 日誌​

當存取你配置的 Rancher FQDN 未顯示 UI 時,檢查 ingress controller 日誌記錄以查看當你嘗試存取 Rancher 時發生了什麼:

kubectl -n ingress-nginx logs -l app=ingress-nginx

領導者選舉​

領導者由領導者選舉流程確定。在確定領導者後,領導者(holderIdentity)儲存在 kube-system 命名空間的 cattle-controllers Lease 中(在此範例中為 rancher-dbc7ff869-gvg6k)。

kubectl -n kube-system get lease cattle-controllers

範例輸出:

NAME                 HOLDER                    AGE
cattle-controllers rancher-dbc7ff869-gvg6k 6h10m

配置​

自 Rancher 2.8.3 起可用

如果 Kubernetes API 遇到延遲,持有領導者鎖定的 Rancher 副本可能無法在租約失效之前更新租約,這可以在 Rancher 日誌中觀察到:

E0629 04:13:07.293461      34 leaderelection.go:364] Failed to update lock: Put "https://172.17.0.1:443/apis/coordination.k8s.io/v1/namespaces/kube-system/leases/cattle-controllers?timeout=15m0s": context deadline exceeded
I0629 04:13:07.293594 34 leaderelection.go:280] failed to renew lease kube-system/cattle-controllers: timed out waiting for the condition
...
2024/06/29 04:13:10 [FATAL] leaderelection lost for cattle-controllers

為了減輕這種情況,你可以在 rancher Deployment 中設定環境變數以修改領導者選舉的預設參數:

範例:

kubectl -n cattle-system set env deploy/rancher CATTLE_ELECTION_LEASE_DURATION=2m CATTLE_ELECTION_RENEW_DEADLINE=90s CATTLE_ELECTION_RETRY_PERIOD=10s

這將暫時將租約持續時間、更新期限和重試週期分別增加到 120、90 和 10 秒。 或者,為了使這些變更永久生效,可以改為透過使用 Helm 值來設定這些環境變數。