kubectl annotate

概要

更新一個或多個資源上的註解。

所有 Kubernetes 物件都支援將額外資料作為註解與物件一起儲存的功能。註解是鍵/值對,可以比標籤更大,並且包含任意字串值,例如結構化的 JSON。工具和系統擴充功能可以使用註解來儲存它們自己的資料。

嘗試設定已存在的註解將會失敗,除非設定了 --overwrite。如果指定了 --resource-version 並且與伺服器上目前的資源版本不符,則指令將會失敗。

使用 "kubectl api-resources" 取得完整支援資源列表。

kubectl annotate [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]

範例

  # Update pod 'foo' with the annotation 'description' and the value 'my frontend'
  # If the same annotation is set multiple times, only the last value will be applied
  kubectl annotate pods foo description='my frontend'
  
  # Update a pod identified by type and name in "pod.json"
  kubectl annotate -f pod.json description='my frontend'
  
  # Update pod 'foo' with the annotation 'description' and the value 'my frontend running nginx', overwriting any existing value
  kubectl annotate --overwrite pods foo description='my frontend running nginx'
  
  # Update all pods in the namespace
  kubectl annotate pods --all description='my frontend running nginx'
  
  # Update pod 'foo' only if the resource is unchanged from version 1
  kubectl annotate pods foo description='my frontend running nginx' --resource-version=1
  
  # Update pod 'foo' by removing an annotation named 'description' if it exists
  # Does not require the --overwrite flag
  kubectl annotate pods foo description-

選項

--all

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

-A, --all-namespaces

如果為 true,則檢查所有命名空間中指定的動作。

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

如果為 true,當範本中的欄位或映射鍵遺失時,忽略範本中的任何錯誤。僅適用於 golang 和 jsonpath 輸出格式。

--dry-run string[="unchanged"]     預設值:"none"

必須為 "none"、"server" 或 "client"。如果為 client 策略,僅列印將被傳送的物件,而不傳送它。如果為 server 策略,提交伺服器端請求而不持久化資源。

--field-manager string     預設值:"kubectl-annotate"

用於追蹤欄位所有權的管理員名稱。

--field-selector string

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

-f, --filename strings

檔案名稱、目錄或 URL,用於識別要更新註解的資源

-h, --help

annotate 的說明

-k, --kustomize string

處理 kustomization 目錄。此標誌不能與 -f 或 -R 一起使用。

--list

如果為 true,則顯示給定資源的註解。

--local

如果為 true,註解將不會連線到 api-server,而是在本地執行。

-o, --output string

輸出格式。選項包括:(json、yaml、name、go-template、go-template-file、template、templatefile、jsonpath、jsonpath-as-json、jsonpath-file)。

--overwrite

如果為 true,允許覆寫註解,否則拒絕覆寫現有註解的註解更新。

-R, --recursive

遞迴處理 -f, --filename 中使用的目錄。當您想要管理組織在同一目錄中的相關 Manifest 時很有用。

--resource-version string

如果為非空值,則僅當此值是物件的當前 resource-version 時,註解更新才會成功。僅在指定單個資源時有效。

-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]。

--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 context 名稱

--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

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

--match-server-version

要求伺服器版本與用戶端版本匹配

-n, --namespace string

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

--password string

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

--profile string     預設值:"none"

要捕獲的 Profile 名稱。選項包括 (none|cpu|heap|goroutine|threadcreate|block|mutex)

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

要將 Profile 寫入的檔案名稱

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

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

-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 字串

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

--token 字串

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

--user 字串

要使用的 kubeconfig 使用者名稱

--username 字串

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

--version 版本[=true]

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

--warnings-as-errors

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

參見

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

此頁面為自動產生。

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

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