kubectl config set-credentials

摘要

在 kubeconfig 中設定使用者項目。

指定已存在的名稱將會把新欄位合併到現有值之上。

    Client-certificate flags:
    --client-certificate=certfile --client-key=keyfile
    
    Bearer token flags:
    --token=bearer_token
    
    Basic auth flags:
    --username=basic_user --password=basic_password

Bearer Token 和基本驗證是互斥的。

kubectl config set-credentials NAME [--client-certificate=path/to/certfile] [--client-key=path/to/keyfile] [--token=bearer_token] [--username=basic_user] [--password=basic_password] [--auth-provider=provider_name] [--auth-provider-arg=key=value] [--exec-command=exec_command] [--exec-api-version=exec_api_version] [--exec-arg=arg] [--exec-env=key=value]

範例

  # Set only the "client-key" field on the "cluster-admin"
  # entry, without touching other values
  kubectl config set-credentials cluster-admin --client-key=~/.kube/admin.key
  
  # Set basic auth for the "cluster-admin" entry
  kubectl config set-credentials cluster-admin --username=admin --password=uXFGweU9l35qcif
  
  # Embed client certificate data in the "cluster-admin" entry
  kubectl config set-credentials cluster-admin --client-certificate=~/.kube/admin.crt --embed-certs=true
  
  # Enable the Google Compute Platform auth provider for the "cluster-admin" entry
  kubectl config set-credentials cluster-admin --auth-provider=gcp
  
  # Enable the OpenID Connect auth provider for the "cluster-admin" entry with additional arguments
  kubectl config set-credentials cluster-admin --auth-provider=oidc --auth-provider-arg=client-id=foo --auth-provider-arg=client-secret=bar
  
  # Remove the "client-secret" config value for the OpenID Connect auth provider for the "cluster-admin" entry
  kubectl config set-credentials cluster-admin --auth-provider=oidc --auth-provider-arg=client-secret-
  
  # Enable new exec auth plugin for the "cluster-admin" entry
  kubectl config set-credentials cluster-admin --exec-command=/path/to/the/executable --exec-api-version=client.authentication.k8s.io/v1beta1
  
  # Enable new exec auth plugin for the "cluster-admin" entry with interactive mode
  kubectl config set-credentials cluster-admin --exec-command=/path/to/the/executable --exec-api-version=client.authentication.k8s.io/v1beta1 --exec-interactive-mode=Never
  
  # Define new exec auth plugin arguments for the "cluster-admin" entry
  kubectl config set-credentials cluster-admin --exec-arg=arg1 --exec-arg=arg2
  
  # Create or update exec auth plugin environment variables for the "cluster-admin" entry
  kubectl config set-credentials cluster-admin --exec-env=key1=val1 --exec-env=key2=val2
  
  # Remove exec auth plugin environment variables for the "cluster-admin" entry
  kubectl config set-credentials cluster-admin --exec-env=var-to-remove-

選項

--auth-provider string

kubeconfig 中使用者項目的驗證提供者

--auth-provider-arg strings

驗證提供者的 'key=value' 引數

--client-certificate string

kubeconfig 中使用者項目的用戶端憑證檔案路徑

--client-key string

kubeconfig 中使用者項目的用戶端金鑰檔案路徑

--embed-certs tristate[=true]

嵌入 kubeconfig 中使用者項目的用戶端憑證/金鑰

--exec-api-version string

kubeconfig 中使用者項目的 exec 憑證外掛程式 API 版本

--exec-arg strings

kubeconfig 中使用者項目的 exec 憑證外掛程式命令的新引數

--exec-command string

kubeconfig 中使用者項目的 exec 憑證外掛程式命令

--exec-env strings

exec 憑證外掛程式的 'key=value' 環境值

--exec-interactive-mode string

kubeconfig 中使用者項目的 exec 憑證外掛程式 InteractiveMode

--exec-provide-cluster-info tristate[=true]

kubeconfig 中使用者項目的 exec 憑證外掛程式 ProvideClusterInfo

-h, --help

set-credentials 的說明

--password string

kubeconfig 中使用者項目的密碼

--token string

kubeconfig 中使用者項目的 Token

--username string

kubeconfig 中使用者項目的使用者名稱

--as string

要模擬操作的使用者名稱。使用者可以是命名空間中的一般使用者或服務帳戶。

--as-group strings

要模擬操作的群組,可以重複此旗標以指定多個群組。

--as-uid string

要模擬操作的 UID。

--cache-dir string     預設值: "$HOME/.kube/cache"

預設快取目錄

--certificate-authority string

憑證授權單位的憑證檔案路徑

--cluster string

要使用的 kubeconfig 叢集名稱

--context string

要使用的 kubeconfig 環境定義名稱

--default-not-ready-toleration-seconds int     預設值: 300

指示 tolerationSeconds 用於 notReady:NoExecute 容忍度,預設會新增至每個尚未具有此容忍度的 Pod。

--default-unreachable-toleration-seconds int     預設值: 300

指示 tolerationSeconds 用於 unreachable:NoExecute 容忍度,預設會新增至每個尚未具有此容忍度的 Pod。

--disable-compression

如果為 true,則退出所有伺服器請求的回應壓縮

--insecure-skip-tls-verify

如果為 true,則不會檢查伺服器憑證的有效性。這會使您的 HTTPS 連線不安全

--kubeconfig string

使用特定的 kubeconfig 檔案

--match-server-version

要求伺服器版本與用戶端版本相符

-n, --namespace string

如果存在,則此 CLI 請求的命名空間範圍

--profile 字串     預設值: "none"

要擷取的設定檔名稱。選項之一 (none|cpu|heap|goroutine|threadcreate|block|mutex)

--profile-output 字串     預設值: "profile.pprof"

要寫入設定檔的檔案名稱

--request-timeout 字串     預設值: "0"

放棄單個伺服器請求前等待的時間長度。非零值應包含對應的時間單位 (例如 1s、2m、3h)。值為零表示請求永不逾時。

-s, --server 字串

Kubernetes API 伺服器的位址和埠

--storage-driver-buffer-duration 持續時間     預設值: 1m0s

儲存驅動程式中的寫入操作將在此持續時間內緩衝,並作為單個交易提交到非記憶體後端

--storage-driver-db 字串     預設值: "cadvisor"

資料庫名稱

--storage-driver-host 字串     預設值: "localhost:8086"

資料庫主機:埠

--storage-driver-password 字串     預設值: "root"

資料庫密碼

--storage-driver-secure

使用安全連線到資料庫

--storage-driver-table 字串     預設值: "stats"

資料表名稱

--storage-driver-user 字串     預設值: "root"

資料庫使用者名稱

--tls-server-name 字串

用於伺服器憑證驗證的伺服器名稱。如果未提供,則使用用於聯絡伺服器的主機名稱

--user 字串

要使用的 kubeconfig 使用者名稱

--version 版本[=true]

--version, --version=raw 列印版本資訊並退出;--version=vX.Y.Z... 設定回報的版本

--warnings-as-errors

將從伺服器收到的警告視為錯誤,並以非零的結束代碼退出

參見

此頁面為自動產生。

如果您計劃回報此頁面的問題,請在您的問題描述中提及此頁面為自動產生。修復可能需要在 Kubernetes 專案的其他地方進行。

上次修改時間:2024 年 8 月 19 日下午 5:14 PST:更新 v1.31 的 kubectl 參考文件 (59df28c340)