kubectl debug
Synopsis
使用互動式除錯容器除錯叢集資源。
'debug' 命令為叢集物件提供常用除錯任務的自動化,透過資源型別和名稱進行標識。如果沒有指定資源,預設使用 Pod。
'debug' 命令執行的操作因指定資源的不同而異。支援的操作包括:
- 工作負載:建立現有 Pod 的副本,並更改某些屬性,例如將映象標籤更改為新版本。
- 工作負載:向已執行的 Pod 新增一個臨時容器,例如新增除錯工具而不重新啟動 Pod。
- 節點:建立一個新的 Pod,該 Pod 在節點的宿主名稱空間中執行,並且可以訪問節點的根檔案系統。
注意:當目標 Pod 配置了非 root 使用者時,除錯配置檔案授予的某些功能可能無法正常工作。
kubectl debug (POD | TYPE[[.VERSION].GROUP]/NAME) [ -- COMMAND [args...] ]
示例
# Create an interactive debugging session in pod mypod and immediately attach to it.
kubectl debug mypod -it --image=busybox
# Create an interactive debugging session for the pod in the file pod.yaml and immediately attach to it.
# (requires the EphemeralContainers feature to be enabled in the cluster)
kubectl debug -f pod.yaml -it --image=busybox
# Create a debug container named debugger using a custom automated debugging image.
kubectl debug --image=myproj/debug-tools -c debugger mypod
# Create a copy of mypod adding a debug container and attach to it
kubectl debug mypod -it --image=busybox --copy-to=my-debugger
# Create a copy of mypod changing the command of mycontainer
kubectl debug mypod -it --copy-to=my-debugger --container=mycontainer -- sh
# Create a copy of mypod changing all container images to busybox
kubectl debug mypod --copy-to=my-debugger --set-image=*=busybox
# Create a copy of mypod adding a debug container and changing container images
kubectl debug mypod -it --copy-to=my-debugger --image=debian --set-image=app=app:debug,sidecar=sidecar:debug
# Create an interactive debugging session on a node and immediately attach to it.
# The container will run in the host namespaces and the host's filesystem will be mounted at /host
kubectl debug node/mynode -it --image=busybox
Options
--arguments-only | |
如果指定,-- 後面的所有內容將作為 Args 傳遞給新容器,而不是 Command。 | |
--attach | |
如果為 true,則等待容器開始執行,然後將其附加,如同呼叫了 'kubectl attach ...'。預設為 false,除非設定了 '-i/--stdin',在這種情況下預設為 true。 | |
-c, --container string | |
用於除錯容器的容器名稱。 | |
--copy-to string | |
建立一個具有此名稱的目標 Pod 的副本。 | |
--custom string | |
指向包含用於自定義內建除錯配置檔案的部分容器規格的 JSON 或 YAML 檔案的路徑。 | |
--env stringToString 預設值:[] | |
要在容器中設定的環境變數。 | |
-f, --filename strings | |
標識要除錯的資源 | |
-h, --help | |
debug 命令的幫助 | |
--image string | |
用於除錯容器的容器映象。 | |
--image-pull-policy string | |
容器的映象拉取策略。如果留空,此值將不會由客戶端指定,而是由伺服器預設。 | |
--keep-annotations | |
如果為 true,則保留原始 Pod 的註解。(此標誌僅在與 '--copy-to' 一起使用時生效) | |
--keep-init-containers 預設值:true | |
執行 Pod 的 init 容器。預設為 true。(此標誌僅在與 '--copy-to' 一起使用時生效) | |
--keep-labels | |
如果為 true,則保留原始 Pod 的標籤。(此標誌僅在與 '--copy-to' 一起使用時生效) | |
--keep-liveness | |
如果為 true,則保留原始 Pod 的存活探針。(此標誌僅在與 '--copy-to' 一起使用時生效) | |
--keep-readiness | |
如果為 true,則保留原始 Pod 的就緒探針。(此標誌僅在與 '--copy-to' 一起使用時生效) | |
--keep-startup | |
如果為 true,則保留原始 Pod 的啟動探針。(此標誌僅在與 '--copy-to' 一起使用時生效) | |
--profile string 預設值:"legacy" | |
選項包括 "legacy"、"general"、"baseline"、"netadmin"、"restricted" 或 "sysadmin"。 | |
-q, --quiet | |
如果為 true,則抑制資訊性訊息。 | |
--replace | |
與 '--copy-to' 一起使用時,刪除原始 Pod。 | |
--same-node | |
與 '--copy-to' 一起使用時,將目標 Pod 的副本排程到同一節點。 | |
--set-image stringToString 預設值:[] | |
與 '--copy-to' 一起使用時,用於更改容器映象的 name=image 對列表,類似於 'kubectl set image' 的工作方式。 | |
--share-processes 預設值:true | |
與 '--copy-to' 一起使用時,在副本中啟用程序名稱空間共享。 | |
-i, --stdin | |
即使沒有任何附加程序,也保持 Pod 中容器的標準輸入開啟。 | |
--target string | |
使用臨時容器時,將程序定位在此容器名稱中。 | |
-t, --tty | |
為除錯容器分配一個 TTY。 |
繼承的父選項
--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 上下文名稱 | |
--disable-compression | |
如果為 true,則選擇退出所有到伺服器的請求的響應壓縮 | |
--insecure-skip-tls-verify | |
如果為 true,則不會檢查伺服器證書的有效性。這將使您的 HTTPS 連線不安全。 | |
--kubeconfig string | |
用於 CLI 請求的 kubeconfig 檔案路徑。 | |
--kuberc string | |
用於首選項的 kuberc 檔案路徑。可以透過匯出 KUBECTL_KUBERC=false 功能標誌或關閉 KUBERC=off 功能來停用此功能。 | |
--match-server-version | |
要求伺服器版本與客戶端版本匹配 | |
-n, --namespace string | |
如果存在,則為本次 CLI 請求的名稱空間範圍 | |
--password string | |
API 伺服器基本身份驗證的密碼 | |
--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 token | |
--user string | |
要使用的 kubeconfig 使用者名稱 | |
--username string | |
API 伺服器基本身份驗證的使用者名稱 | |
--version version[=true] | |
--version, --version=raw 列印版本資訊並退出;--version=vX.Y.Z... 設定報告的版本 | |
--warnings-as-errors | |
將從伺服器收到的警告視為錯誤,並以非零退出程式碼退出。 |
另請參閱
- kubectl - kubectl 控制 Kubernetes 叢集管理器
本頁面是自動生成的。
如果你打算報告此頁面存在的問題,請在問題描述中提及此頁面是自動生成的。修復可能需要在 Kubernetes 專案的其他地方進行。