K8S常用命令


查询集群拥有的Node

1kubectl get nodes

查询集群运行的Service

1kubectl get services --all-namespaces
2kubectl get services -n test

查询节点上运行的Pod

1kubectl get pods --all-namespaces -o wide --field-selector spec.nodeName=youshu-tke1

默认按照default namespace排序,可按照节点排序展示Pod

1kubectl get pods -o wide --sort-by="{.spec.nodeName}"

复制Pod实例文件到主机节点

1kubectl cp bi-advert-new-77f4b9b574-rlmk6:/usr/local/app/bi-advert/dump.hropf  /usr/local/dump-20221115.hprof -n formal

删除对应名称或状态的Pod实例

1kubectl get pods  -n prod | grep 'data-nexus-external-gateway-59f767bdd6-wkjl5' | awk '{print $1}' | xargs kubectl delete pod  -n prod  --force --grace-period=0
1kubectl get pods  -n prod | grep 'Pending' | awk '{print $1}' | xargs kubectl delete pod  -n prod  --force --grace-period=0

查询Service详细信息

1kubectl get svc -o wide -n prod | grep 31422

查询某个Service信息

1kubectl get svc -o wide | grep service-name