kubectl wait

概要

實驗性:等待一個或多個資源上的特定條件。

此命令會取得多個資源,並等待直到在每個給定資源的 Status 欄位中看到指定的條件。

或者,此命令可以等待給定的一組資源被建立或刪除,方法是將 "create" 或 "delete" 關鍵字作為 --for 標誌的值提供。

當滿足指定的條件時,將會列印一則成功訊息到標準輸出。您可以使用 -o 選項來變更輸出目的地。

kubectl wait ([-f FILENAME] | resource.group/resource.name | resource.group [(-l label | --all)]) [--for=create|--for=delete|--for condition=available|--for=jsonpath='{}'[=value]]

範例

  # Wait for the pod "busybox1" to contain the status condition of type "Ready"
  kubectl wait --for=condition=Ready pod/busybox1
  
  # The default value of status condition is true; you can wait for other targets after an equal delimiter (compared after Unicode simple case folding, which is a more general form of case-insensitivity)
  kubectl wait --for=condition=Ready=false pod/busybox1
  
  # Wait for the pod "busybox1" to contain the status phase to be "Running"
  kubectl wait --for=jsonpath='{.status.phase}'=Running pod/busybox1
  
  # Wait for pod "busybox1" to be Ready
  kubectl wait --for='jsonpath={.status.conditions[?(@.type=="Ready")].status}=True' pod/busybox1
  
  # Wait for the service "loadbalancer" to have ingress
  kubectl wait --for=jsonpath='{.status.loadBalancer.ingress}' service/loadbalancer
  
  # Wait for the secret "busybox1" to be created, with a timeout of 30s
  kubectl create secret generic busybox1
  kubectl wait --for=create secret/busybox1 --timeout=30s
  
  # Wait for the pod "busybox1" to be deleted, with a timeout of 60s, after having issued the "delete" command
  kubectl delete pod/busybox1
  kubectl wait --for=delete pod/busybox1 --timeout=60s

選項

--all

選取指定資源類型之命名空間中的所有資源

-A, --all-namespaces

如果存在,則列出跨所有命名空間的請求物件。即使使用 --namespace 指定,也會忽略目前環境定義中的命名空間。

--allow-missing-template-keys     預設值:true

如果為 true,當範本中缺少欄位或地圖索引鍵時,忽略範本中的任何錯誤。僅適用於 golang 和 jsonpath 輸出格式。

--field-selector string

要篩選的選取器(欄位查詢),支援 '='、'==' 和 '!='。(例如,--field-selector key1=value1,key2=value2)。伺服器僅支援每種類型有限數量的欄位查詢。

-f, --filename strings

識別資源。

--for string

要等待的條件:[create|delete|condition=condition-name[=condition-value]|jsonpath='{JSONPath expression}'=[JSONPath value]]。預設條件值為 true。條件值在 Unicode 簡單的大小寫摺疊後進行比較,這是一種更常見的不區分大小寫的形式。

-h, --help

wait 的說明

--local

如果為 true,則註解將不會聯絡 api-server,而是在本機執行。

-o, --output string

輸出格式。其中之一:(json、yaml、name、go-template、go-template-file、template、templatefile、jsonpath、jsonpath-as-json、jsonpath-file)。

-R, --recursive     預設值:true

以遞迴方式處理 -f、--filename 中使用的目錄。當您想要管理在同一個目錄中組織的相關資訊清單時很有用。

-l, --selector string

要篩選的選取器(標籤查詢),支援 '='、'==' 和 '!='。(例如,-l key1=value1,key2=value2)

--show-managed-fields

如果為 true,則在 JSON 或 YAML 格式中列印物件時,保留 managedFields。

--template string

當 -o=go-template、-o=go-template-file 時要使用的範本字串或範本檔案路徑。範本格式為 golang 範本 [https://go.dev.org.tw/pkg/text/template/#pkg-overview]。

--timeout duration     預設值:30 秒

在放棄之前要等待的時間長度。零表示檢查一次且不等待,負數表示等待一週。

--as string

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

--as-group strings

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

--as-uid string

要模擬操作的 UID。

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

預設快取目錄

--certificate-authority string

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

--client-certificate string

TLS 用戶端憑證檔案路徑

--client-key string

TLS 用戶端金鑰檔案路徑

--cluster string

要使用的 kubeconfig 叢集名稱

--context string

要使用的 kubeconfig 環境定義名稱

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

表示預設新增至每個尚未具有此容忍度的 Pod 的 notReady:NoExecute 容忍度的 tolerationSeconds。

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

指示預設新增至每個尚未具備此容忍度的 Pod 的 unreachable:NoExecute 容忍度的 tolerationSeconds。

--disable-compression

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

--insecure-skip-tls-verify

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

--kubeconfig string

用於 CLI 請求的 kubeconfig 檔案路徑。

--match-server-version

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

-n, --namespace string

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

--password string

用於 API 伺服器的基本身份驗證密碼

--profile string     預設值:"none"

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

--profile-output string     預設值:"profile.pprof"

要將設定檔寫入的檔案名稱

--request-timeout string     預設值:"0"

在放棄單一伺服器請求之前等待的時間長度。非零值應包含對應的時間單位(例如 1 秒、2 分鐘、3 小時)。值為零表示請求永不逾時。

-s, --server string

Kubernetes API 伺服器的位址和連接埠

--storage-driver-buffer-duration duration     預設值:1m0s

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

--storage-driver-db string     預設值:"cadvisor"

資料庫名稱

--storage-driver-host string     預設值:"localhost:8086"

資料庫主機:連接埠

--storage-driver-password string     預設值:"root"

資料庫密碼

--storage-driver-secure

使用與資料庫的安全連線

--storage-driver-table string     預設值:"stats"

表格名稱

--storage-driver-user string     預設值:"root"

資料庫使用者名稱

--tls-server-name string

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

--token string

用於 API 伺服器身份驗證的 Bearer 權杖

--user string

要使用的 kubeconfig 使用者名稱

--username string

用於 API 伺服器的基本身份驗證使用者名稱

--version version[=true]

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

--warnings-as-errors

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

參見

  • kubectl - kubectl 控制 Kubernetes 叢集管理員

此頁面為自動產生。

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

上次修改時間為 2024 年 12 月 12 日下午 2:44 PST:更新 v1.32 的 kubectl 參考 (5c2cfa02af)