Kubectl 常用命令

2022-07-06 01:45:08 字數 1450 閱讀 1951

以下指令都需要在 controller 節點執行

檢視各服務資訊

kubectl get service

檢視集群中所有 pod 資訊

kubectl get pod --all-namespaces

檢視服務中元件資訊

kubectl get service -n component

獲取各元件/pod 在各節點上的分布情況

kubectl get pod -n component -o wide

kubectl get pod -o wide

檢視節點資訊

kubectl get nodes

檢視某個 pod 服務日誌資訊

kubectl get pod 獲取服務對應的 pod_name

kubectl logs -f

kubectl logs -f -n component

檢視具體某個 pod 服務的詳細資訊

kubectl get pod 獲取服務對應的 pod_name

kubectl describe pod

檢視某個服務配置資訊

輸入 kubectl describe configmap 後雙擊 tab 後可顯示可檢視的服務配置

kubectl describe configmap engine-face-extract-service-config

進入某個 pod/元件服務

kubectl exec -it /bin/bash

kubectl exec -it -n component /bin/bash

kubectl get secrets password-secrets -o yaml

# kubectl get secrets password-secrets -o yaml|grep -i gr

grafana_admin_password: duzys0niznd1q1frs1hz

grafana_admin_username: ywrtaw4=

# echo duzys0niznd1q1frs1hz|base64 -d

ufxkcbfwucqkkxs

# echo ywrtaw4 |base64 -d

adminbase64: invalid input

在dashboard介面刪除容器,發現無法刪除。使用命令檢視發現該pod一直處於terminating的狀態

kubernetes強制刪除一直處於terminating狀態的pod。

1、使用命令獲取pod的名字

kubectl get po -n namespace |grep terminating

2、使用kubectl中的強制刪除命令

kubectl delete pod podname -n namespace --force --grace-period=0

kubectl常用命令

檢視所有namespace kubectl get namespace 檢視預設的配置 kubectl config view 獲取集群裡的各種資源資訊,某些資源未指定namespace時,預設指定default 常見用法 kubectl get pods rc svc deployment nam...

kubectl 常用命令總結

檢視所有 pod 列表,n 後跟 namespace,檢視指定的命名空間 kubectl get pod kubectl get pod n kube kubectl get pod o wide 檢視 rc 和 service 列表,o wide 檢視詳細資訊 kubectl get rc,svc...

kubectl常用命令總結

檢視集群和版本相關資訊kubectl version 顯示客戶端和伺服器側版本資訊 kubectl api versions 列出當前版本的kubernetes的伺服器端所支援的api版本資訊 kubectl cluster info 獲取k8s集群資訊 kubectl config view 獲取...