kubectl get
概要
顯示一個或多個資源。
列印關於指定資源最重要資訊的表格。您可以使用標籤選擇器和 --selector 標記來篩選清單。如果所需的資源類型具有命名空間,如果您未指定任何命名空間,您將只會看到目前命名空間中的結果。
透過將輸出指定為 'template' 並提供 Go 範本作為 --template 標記的值,您可以篩選所提取資源的屬性。
使用 "kubectl api-resources" 取得完整支援資源清單。
kubectl get [(-o|--output=)json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-as-json|jsonpath-file|custom-columns|custom-columns-file|wide] (TYPE[.VERSION][.GROUP] [NAME | -l label] | TYPE[.VERSION][.GROUP]/NAME ...) [flags]
範例
# List all pods in ps output format
kubectl get pods
# List all pods in ps output format with more information (such as node name)
kubectl get pods -o wide
# List a single replication controller with specified NAME in ps output format
kubectl get replicationcontroller web
# List deployments in JSON output format, in the "v1" version of the "apps" API group
kubectl get deployments.v1.apps -o json
# List a single pod in JSON output format
kubectl get -o json pod web-pod-13je7
# List a pod identified by type and name specified in "pod.yaml" in JSON output format
kubectl get -f pod.yaml -o json
# List resources from a directory with kustomization.yaml - e.g. dir/kustomization.yaml
kubectl get -k dir/
# Return only the phase value of the specified pod
kubectl get -o template pod/web-pod-13je7 --template={{.status.phase}}
# List resource information in custom columns
kubectl get pod test-pod -o custom-columns=CONTAINER:.spec.containers[0].name,IMAGE:.spec.containers[0].image
# List all replication controllers and services together in ps output format
kubectl get rc,services
# List one or more resources by their type and names
kubectl get rc/web service/frontend pods/web-pod-13je7
# List the 'status' subresource for a single pod
kubectl get pod web-pod-13je7 --subresource status
# List all deployments in namespace 'backend'
kubectl get deployments.apps --namespace backend
# List all pods existing in all namespaces
kubectl get pods --all-namespaces
選項
-A, --all-namespaces | |
如果存在,則列出所有命名空間中請求的物件。即使使用 --namespace 指定,也會忽略目前內容中的命名空間。 | |
--allow-missing-template-keys 預設值:true | |
如果為 true,則在範本中遺失欄位或地圖鍵時,忽略範本中的任何錯誤。僅適用於 golang 和 jsonpath 輸出格式。 | |
--chunk-size int 預設值:500 | |
以區塊而非一次全部傳回大型清單。傳遞 0 以停用。此標記為 Beta 版,未來可能會變更。 | |
--field-selector string | |
要篩選的選擇器 (欄位查詢),支援 '=', '==' 和 '!='。(例如 --field-selector key1=value1,key2=value2)。伺服器僅支援每種類型有限數量的欄位查詢。 | |
-f, --filename strings | |
檔案名稱、目錄或 URL,用於識別要從伺服器取得的資源。 | |
-h, --help | |
get 的說明 | |
--ignore-not-found | |
如果請求的物件不存在,命令將傳回結束代碼 0。 | |
-k, --kustomize string | |
處理 kustomization 目錄。此標記不能與 -f 或 -R 一起使用。 | |
-L, --label-columns strings | |
接受以逗號分隔的標籤清單,這些標籤將呈現為欄。名稱區分大小寫。您也可以使用多個標記選項,例如 -L label1 -L label2... | |
--no-headers | |
使用預設或自訂欄輸出格式時,請勿列印標頭 (預設為列印標頭)。 | |
-o, --output string | |
輸出格式。選項之一:(json, yaml, name, go-template, go-template-file, template, templatefile, jsonpath, jsonpath-as-json, jsonpath-file, custom-columns, custom-columns-file, wide)。請參閱自訂欄 [https://kubernetes.dev.org.tw/docs/reference/kubectl/#custom-columns]、golang 範本 [https://go.dev.org.tw/pkg/text/template/#pkg-overview] 和 jsonpath 範本 [https://kubernetes.dev.org.tw/docs/reference/kubectl/jsonpath/]。 | |
--output-watch-events | |
在使用 --watch 或 --watch-only 時輸出監看事件物件。現有物件會輸出為初始 ADDED 事件。 | |
--raw string | |
要從伺服器請求的原始 URI。使用 kubeconfig 檔案指定的傳輸。 | |
-R, --recursive | |
以遞迴方式處理 -f, --filename 中使用的目錄。當您想要管理在相同目錄中組織的相關資訊清單時很有用。 | |
-l, --selector string | |
要篩選的選擇器 (標籤查詢),支援 '=', '==' 和 '!='。(例如 -l key1=value1,key2=value2)。符合的物件必須滿足所有指定的標籤約束。 | |
--server-print 預設值:true | |
如果為 true,則讓伺服器傳回適當的表格輸出。支援擴展 API 和 CRD。 | |
--show-kind | |
如果存在,則列出請求物件的資源類型。 | |
--show-labels | |
列印時,顯示所有標籤作為最後一欄 (預設為隱藏標籤欄) | |
--show-managed-fields | |
如果為 true,則在以 JSON 或 YAML 格式列印物件時保留 managedFields。 | |
--sort-by string | |
如果為非空值,則使用此欄位規格排序清單類型。欄位規格表示為 JSONPath 表達式 (例如 '{.metadata.name}')。此 JSONPath 表達式指定的 API 資源中的欄位必須是整數或字串。 | |
--subresource string | |
如果指定,則取得請求物件的子資源。此標記為 Beta 版,未來可能會變更。 | |
--template string | |
範本字串或範本檔案路徑,在 -o=go-template, -o=go-template-file 時使用。範本格式為 golang 範本 [https://go.dev.org.tw/pkg/text/template/#pkg-overview]。 | |
-w, --watch | |
在列出/取得請求的物件後,監看變更。 | |
--watch-only | |
監看請求物件的變更,而無需先列出/取得。 |
--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 字串 | |
要使用的 kubeconfig context 名稱 | |
--default-not-ready-toleration-seconds int 預設值:300 | |
指出針對 notReady:NoExecute 容忍度的 tolerationSeconds,此容忍度預設會新增至每個尚未具有此容忍度的 Pod。 | |
--default-unreachable-toleration-seconds int 預設值:300 | |
指出針對 unreachable:NoExecute 容忍度的 tolerationSeconds,此容忍度預設會新增至每個尚未具有此容忍度的 Pod。 | |
--disable-compression | |
如果為 true,則針對所有對伺服器的請求選擇退出回應壓縮 | |
--insecure-skip-tls-verify | |
如果為 true,則伺服器的憑證將不會檢查有效性。這會使您的 HTTPS 連線變得不安全 | |
--kubeconfig 字串 | |
用於 CLI 請求的 kubeconfig 檔案路徑。 | |
--match-server-version | |
要求伺服器版本與用戶端版本相符 | |
-n, --namespace 字串 | |
如果存在,則此 CLI 請求的命名空間範圍 | |
--password 字串 | |
用於 API 伺服器的基本身分驗證密碼 | |
--profile 字串 預設值:"none" | |
要擷取的設定檔名稱。選項之一 (none|cpu|heap|goroutine|threadcreate|block|mutex) | |
--profile-output 字串 預設值:"profile.pprof" | |
要將設定檔寫入的檔案名稱 | |
--request-timeout 字串 預設值:"0" | |
在放棄單一伺服器請求之前等待的時間長度。非零值應包含對應的時間單位 (例如 1 秒、2 分鐘、3 小時)。值為零表示請求不會逾時。 | |
-s, --server 字串 | |
Kubernetes API 伺服器的位址和埠 | |
--storage-driver-buffer-duration 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 version[=true] | |
--version、--version=raw 列印版本資訊並結束;--version=vX.Y.Z... 設定回報的版本 | |
--warnings-as-errors | |
將從伺服器收到的警告視為錯誤,並以非零結束代碼結束 |
另請參閱
- kubectl - kubectl 控制 Kubernetes 叢集管理器
本頁面為自動產生。
如果您計劃回報此頁面的問題,請在您的問題描述中提及此頁面為自動產生。修正可能需要在 Kubernetes 專案的其他地方進行。