kubectl run
概要
在 Pod 中建立並執行特定的映像檔。
kubectl run NAME --image=image [--env="key=value"] [--port=port] [--dry-run=server|client] [--overrides=inline-json] [--command] -- [COMMAND] [args...]
範例
# Start a nginx pod
kubectl run nginx --image=nginx
# Start a hazelcast pod and let the container expose port 5701
kubectl run hazelcast --image=hazelcast/hazelcast --port=5701
# Start a hazelcast pod and set environment variables "DNS_DOMAIN=cluster" and "POD_NAMESPACE=default" in the container
kubectl run hazelcast --image=hazelcast/hazelcast --env="DNS_DOMAIN=cluster" --env="POD_NAMESPACE=default"
# Start a hazelcast pod and set labels "app=hazelcast" and "env=prod" in the container
kubectl run hazelcast --image=hazelcast/hazelcast --labels="app=hazelcast,env=prod"
# Dry run; print the corresponding API objects without creating them
kubectl run nginx --image=nginx --dry-run=client
# Start a nginx pod, but overload the spec with a partial set of values parsed from JSON
kubectl run nginx --image=nginx --overrides='{ "apiVersion": "v1", "spec": { ... } }'
# Start a busybox pod and keep it in the foreground, don't restart it if it exits
kubectl run -i -t busybox --image=busybox --restart=Never
# Start the nginx pod using the default command, but use custom arguments (arg1 .. argN) for that command
kubectl run nginx --image=nginx -- <arg1> <arg2> ... <argN>
# Start the nginx pod using a different command and custom arguments
kubectl run nginx --image=nginx --command -- <cmd> <arg1> ... <argN>
選項
--allow-missing-template-keys 預設值:true | |
如果為 true,則在範本中的欄位或對應鍵遺失時,忽略範本中的任何錯誤。僅適用於 golang 和 jsonpath 輸出格式。 | |
--annotations 字串 | |
要套用至 Pod 的註解。 | |
--attach | |
如果為 true,請等待 Pod 開始執行,然後連接到 Pod,就像呼叫 'kubectl attach ...' 一樣。預設值為 false,除非設定了 '-i/--stdin',在這種情況下,預設值為 true。使用 '--restart=Never' 時,會傳回容器程序的結束代碼。 | |
--cascade 字串[="background"] 預設值:"background" | |
必須為 "background"、"orphan" 或 "foreground"。選取從屬項(例如 ReplicationController 建立的 Pod)的刪除級聯策略。預設為 background。 | |
--command | |
如果為 true 且存在額外引數,請將它們用作容器中的 'command' 欄位,而不是預設的 'args' 欄位。 | |
--dry-run 字串[="unchanged"] 預設值:"none" | |
必須為 "none"、"server" 或 "client"。如果是 client 策略,則僅列印將傳送的物件,而不傳送它。如果是 server 策略,則提交伺服器端請求,但不持久化資源。 | |
--env 字串 | |
要在容器中設定的環境變數。 | |
--expose --port | |
如果為 true,則建立與 Pod 關聯的 ClusterIP 服務。需要 --port。 | |
--field-manager 字串 預設值:"kubectl-run" | |
用於追蹤欄位所有權的管理員名稱。 | |
-f, --filename 字串 | |
用於替換資源。 | |
--force | |
如果為 true,則立即從 API 移除資源並繞過正常刪除。請注意,立即刪除某些資源可能會導致不一致或資料遺失,並且需要確認。 | |
--grace-period 整數 預設值:-1 | |
給予資源正常終止的時間長度(秒)。如果為負數則忽略。設定為 1 以立即關閉。僅當 --force 為 true(強制刪除)時,才能設定為 0。 | |
-h, --help | |
run 的說明 | |
--image 字串 | |
要執行的容器映像檔。 | |
--image-pull-policy 字串 | |
容器的映像檔提取策略。如果留空,則此值將不會由用戶端指定,而是由伺服器預設設定。 | |
-k, --kustomize 字串 | |
處理 kustomization 目錄。此旗標不能與 -f 或 -R 一起使用。 | |
-l, --labels 字串 | |
要套用至 Pod 的逗號分隔標籤。將覆寫先前的值。 | |
--leave-stdin-open | |
如果 Pod 在互動模式下或使用 stdin 啟動,則在第一次連接完成後保持 stdin 開啟。預設情況下,stdin 將在第一次連接完成後關閉。 | |
-o, --output 字串 | |
輸出格式。選項之一:(json、yaml、name、go-template、go-template-file、template、templatefile、jsonpath、jsonpath-as-json、jsonpath-file)。 | |
--override-type 字串 預設值:"merge" | |
用於覆寫產生物件的方法:json、merge 或 strategic。 | |
--overrides 字串 | |
產生物件的內嵌 JSON 覆寫。如果此項為非空值,則用於覆寫產生的物件。要求物件提供有效的 apiVersion 欄位。 | |
--pod-running-timeout 持續時間 預設值:1m0s | |
等待至少一個 Pod 執行所需的時間長度 (例如 5 秒、2 分鐘或 3 小時,必須大於零) | |
--port string | |
此容器公開的埠號。 | |
--privileged | |
若為 true,則以特權模式執行容器。 | |
-q, --quiet | |
若為 true,則抑制提示訊息。 | |
-R, --recursive | |
遞迴處理 -f、--filename 中使用的目錄。當您想要管理組織在同一目錄中的相關 Manifest 時非常有用。 | |
--restart string 預設值: "Always" | |
此 Pod 的重新啟動策略。合法值為 [Always, OnFailure, Never]。 | |
--rm | |
若為 true,則在 Pod 結束後刪除它。僅在附加到容器時有效,例如使用 '--attach' 或 '-i/--stdin'。 | |
--save-config | |
若為 true,則目前物件的組態將儲存在其註解中。否則,註解將保持不變。當您想要在未來對此物件執行 kubectl apply 時,此標記非常有用。 | |
--show-managed-fields | |
若為 true,則在以 JSON 或 YAML 格式列印物件時,保留 managedFields。 | |
-i, --stdin | |
即使沒有任何附加,仍保持 Pod 中容器的 stdin 開啟。 | |
--template string | |
範本字串或範本檔案路徑,用於 -o=go-template, -o=go-template-file。範本格式為 golang 範本 [https://go.dev.org.tw/pkg/text/template/#pkg-overview]。 | |
--timeout duration | |
放棄刪除前等待的時間長度,零表示從物件大小判斷逾時時間 | |
-t, --tty | |
在 Pod 中為容器分配 TTY。 | |
--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 | |
表示 tolerationSeconds,對於 notReady:NoExecute 容忍度 (toleration),預設會新增到每個尚未具有此容忍度的 Pod。 | |
--default-unreachable-toleration-seconds int 預設值: 300 | |
表示 tolerationSeconds,對於 unreachable:NoExecute 容忍度 (toleration),預設會新增到每個尚未具有此容忍度的 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 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 Token | |
--user string | |
要使用的 kubeconfig 使用者名稱 | |
--username string | |
用於 API 伺服器的基本身份驗證使用者名稱 | |
--version version[=true] | |
--version, --version=raw 列印版本資訊並退出;--version=vX.Y.Z... 設定報告的版本 | |
--warnings-as-errors | |
將從伺服器收到的警告視為錯誤,並以非零退出代碼退出 |
參見
- kubectl - kubectl 控制 Kubernetes 叢集管理器
本頁面為自動產生。
如果您計劃回報此頁面的問題,請在您的問題描述中提及此頁面為自動產生。修復可能需要在 Kubernetes 專案的其他地方進行。