kubectl replace
概要
依據檔名或標準輸入取代資源。
接受 JSON 與 YAML 格式。若要取代現有資源,必須提供完整的資源規格。這可以透過以下方式取得:
$ kubectl get TYPE NAME -o yaml
kubectl replace -f FILENAME
範例
# Replace a pod using the data in pod.json
kubectl replace -f ./pod.json
# Replace a pod based on the JSON passed into stdin
cat pod.json | kubectl replace -f -
# Update a single-container pod's image version (tag) to v4
kubectl get pod mypod -o yaml | sed 's/\(image: myimage\):.*$/\1:v4/' | kubectl replace -f -
# Force replace, delete and then re-create the resource
kubectl replace --force -f ./pod.json
選項
--allow-missing-template-keys 預設值:true | |
若為 true,當範本中缺少欄位或對應鍵時,忽略範本中的任何錯誤。僅適用於 golang 和 jsonpath 輸出格式。 | |
--cascade string[="background"] 預設值:"background" | |
必須為 "background"、"orphan" 或 "foreground"。選取依賴項的刪除串聯策略 (例如 ReplicationController 建立的 Pods)。預設為 background。 | |
--dry-run string[="unchanged"] 預設值:"none" | |
必須為 "none"、"server" 或 "client"。若為 client 策略,僅列印將傳送的物件,而不傳送它。若為 server 策略,提交伺服器端請求,而不持久化資源。 | |
--field-manager string 預設值:"kubectl-replace" | |
用於追蹤欄位所有權的管理員名稱。 | |
-f, --filename strings | |
包含要取代之組態的檔案。 | |
--force | |
若為 true,立即從 API 移除資源並略過正常刪除。請注意,立即刪除某些資源可能會導致不一致或資料遺失,且需要確認。 | |
--grace-period int 預設值:-1 | |
給予資源正常終止的秒數時間。若為負數則忽略。設定為 1 以立即關閉。僅當 --force 為 true (強制刪除) 時才能設定為 0。 | |
-h, --help | |
replace 的說明 | |
-k, --kustomize string | |
處理 kustomization 目錄。此旗標不能與 -f 或 -R 一起使用。 | |
-o, --output string | |
輸出格式。選項之一:(json, yaml, name, go-template, go-template-file, template, templatefile, jsonpath, jsonpath-as-json, jsonpath-file)。 | |
--raw string | |
要 PUT 到伺服器的原始 URI。使用 kubeconfig 檔案指定的傳輸方式。 | |
-R, --recursive | |
遞迴處理 -f, --filename 中使用的目錄。當您想要管理在相同目錄中組織的相關 Manifest 時很有用。 | |
--save-config | |
若為 true,目前物件的組態將儲存在其註解中。否則,註解將保持不變。當您想要在未來對此物件執行 kubectl apply 時,此旗標很有用。 | |
--show-managed-fields | |
若為 true,在以 JSON 或 YAML 格式列印物件時,保留 managedFields。 | |
--subresource string | |
若有指定,replace 將對請求物件的子資源進行操作。此旗標為 Beta 版,未來可能會變更。 | |
--template string | |
範本字串或範本檔案路徑,當使用 -o=go-template, -o=go-template-file 時使用。範本格式為 golang 範本 [https://go.dev.org.tw/pkg/text/template/#pkg-overview]。 | |
--timeout duration | |
在放棄刪除之前等待的時間長度,零表示從物件大小判斷逾時時間 | |
--validate string[="strict"] 預設值:"strict" | |
必須為下列其中之一:strict (或 true)、warn、ignore (或 false)。 "true" 或 "strict" 將使用結構描述驗證輸入,若輸入無效則請求失敗。若 API 伺服器上啟用 ServerSideFieldValidation,則將執行伺服器端驗證,否則將回退至較不可靠的用戶端驗證。若 API 伺服器上啟用伺服器端欄位驗證,"warn" 將警告未知或重複欄位,而不會封鎖請求,否則行為如同 "ignore"。"false" 或 "ignore" 將不執行任何結構描述驗證,並靜默捨棄任何未知或重複欄位。 | |
--wait | |
若為 true,在傳回之前等待資源消失。這會等待 Finalizers。 |
--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 | |
指出預設新增至每個尚未擁有此容忍度的 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」 | |
要擷取的 Profile 名稱。選項之一 (none|cpu|heap|goroutine|threadcreate|block|mutex) | |
--profile-output string 預設值:「profile.pprof」 | |
要寫入 Profile 的檔案名稱 | |
--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 Token | |
--user string | |
要使用的 kubeconfig 使用者名稱 | |
--username string | |
用於 API 伺服器的基本身分驗證使用者名稱 | |
--version version[=true] | |
--version、--version=raw 列印版本資訊並結束;--version=vX.Y.Z... 設定回報的版本 | |
--warnings-as-errors | |
將從伺服器收到的警告視為錯誤,並以非零結束代碼結束 |
另請參閱
- kubectl - kubectl 控制 Kubernetes 叢集管理器
本頁面為自動產生。
如果您計劃回報此頁面的問題,請在您的問題描述中註明此頁面為自動產生。此修正可能需要在 Kubernetes 專案中的其他地方進行。