跳至主要内容

kubectl 工具

kubectl​

使用 kubectl 與 Rancher 互動。

kubectl 工具​

安裝 kubectl 工具。請參閱安裝 kubectl。

透過在 Rancher Web UI 中存取您的叢集來設定 kubectl,點選 Kubeconfig,複製內容,並將它們放入您的 ~/.kube/config 檔案中。

成功執行 kubectl cluster-info 或 kubectl get pods。

使用 kubectl 和具有 TTL 的 kubeconfig Token 進行身份驗證​

需求

如果管理員已關閉 kubeconfig token 生成,當您執行 kubectl 時,kubeconfig 檔案需要 Rancher CLI 存在於您的 PATH 中。否則,您會看到類似以下的錯誤: Unable to connect to the server: getting credentials: exec: exec: "rancher": executable file not found in $PATH。

此功能可讓 kubectl 與 Rancher 伺服器進行身份驗證,並在需要時取得新的 kubeconfig token。目前支援以下身份驗證提供者:

  1. Local
  2. Active Directory (LDAP only)
  3. FreeIPA
  4. OpenLDAP
  5. SAML providers: Ping, Okta, ADFS, Keycloak, Shibboleth
  6. Azure AD

當您第一次執行 kubectl 時(例如 kubectl get pods),系統會提示您選擇身份驗證提供者並登入 Rancher 伺服器。kubeconfig token 會快取在您執行 kubectl 的路徑下的 ./.cache/token 中。此 token 在過期或從 Rancher 伺服器刪除之前一直有效。過期後,您必須再次登入 Rancher 伺服器才能執行 kubectl get pods 指令。