kubectl edit

概要

從預設編輯器編輯資源。

edit 命令可讓您直接編輯任何可透過命令列工具擷取的 API 資源。它會開啟由您的 KUBE_EDITOR 或 EDITOR 環境變數定義的編輯器,或在 Linux 上回退到 'vi',在 Windows 上回退到 'notepad'。嘗試開啟編輯器時,它會先嘗試使用在 'SHELL' 環境變數中定義的 Shell。如果未定義,則會使用預設 Shell,Linux 為 '/bin/bash',Windows 為 'cmd'。

您可以編輯多個物件,但變更一次套用一個。此命令接受檔案名稱以及命令列引數,但您指向的檔案必須是先前儲存的資源版本。

編輯是使用用於擷取資源的 API 版本完成的。若要使用特定 API 版本進行編輯,請完整限定資源、版本和群組。

預設格式為 YAML。若要以 JSON 格式編輯,請指定 "-o json"。

旗標 --windows-line-endings 可用於強制使用 Windows 行尾符,否則將使用您作業系統的預設值。

如果更新時發生錯誤,則會在磁碟上建立一個臨時檔案,其中包含您未套用的變更。更新資源時最常見的錯誤是另一個編輯器在伺服器上變更資源。發生這種情況時,您必須將變更套用至較新版本的資源,或更新臨時儲存的副本以包含最新的資源版本。

kubectl edit (RESOURCE/NAME | -f FILENAME)

範例

  # Edit the service named 'registry'
  kubectl edit svc/registry
  
  # Use an alternative editor
  KUBE_EDITOR="nano" kubectl edit svc/registry
  
  # Edit the job 'myjob' in JSON using the v1 API format
  kubectl edit job.v1.batch/myjob -o json
  
  # Edit the deployment 'mydeployment' in YAML and save the modified config in its annotation
  kubectl edit deployment/mydeployment -o yaml --save-config
  
  # Edit the 'status' subresource for the 'mydeployment' deployment
  kubectl edit deployment mydeployment --subresource='status'

選項

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

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

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

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

-f, --filename strings

檔案名稱、目錄或 URL,用於編輯資源

-h, --help

edit 的說明

-k, --kustomize string

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

-o, --output string

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

--output-patch

如果資源被編輯,則輸出修補程式。

-R, --recursive

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

--save-config

如果為 true,目前物件的組態將儲存在其註釋中。否則,註釋將保持不變。當您想要在未來對此物件執行 kubectl apply 時,此標flag很有用。

--show-managed-fields

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

--subresource string

如果指定,edit 將對請求物件的子資源進行操作。此標flag為 Beta 版,未來可能會變更。

--template string

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

--validate string[="strict"]     預設值: "strict"

必須是以下其中之一:strict (或 true)、warn、ignore (或 false)。 "true" 或 "strict" 將使用結構描述來驗證輸入,如果輸入無效則請求將失敗。如果 API 伺服器上啟用了 ServerSideFieldValidation,它將執行伺服器端驗證,但如果未啟用,則會退回到較不可靠的用戶端驗證。"warn" 將警告未知或重複的欄位,但如果 API 伺服器上啟用了伺服器端欄位驗證,則不會阻止請求,否則行為將如同 "ignore"。"false" 或 "ignore" 將不執行任何結構描述驗證,靜默地丟棄任何未知或重複的欄位。

--windows-line-endings

預設為您平台原生的行尾符號。

--as string

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

--as-group strings

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

--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 容忍度的容忍時間長度 (秒)。

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

指示預設新增到每個尚未具有此容忍度的 Pod 的 unreachable:NoExecute 容忍度的容忍時間長度 (秒)。

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

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

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