[root@k8s-master ~]# kubectl get service -n rkw-ezc-test -o wide NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR chinapopin-apply-vsitregist-application-test NodePort 10.96.235.105 <none> 8092:32208/TCP 434d app=chinapopin-apply-vsitregist-application-test chinapopin-platform-address-application-test NodePort 10.96.99.208 <none> 8071:31583/TCP 434d app=chinapopin-platform-address-application-test2、根据app name获取pod
[root@k8s-master ~]# kubectl get service -n rkw-ezc-test -l app=notice-shortmsg-test NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE notice-shortmsg-test NodePort 10.96.96.221 <none> 8078:30631/TCP 6d22h [root@k8s-master ~]# kubectl get pod -n rkw-ezc-test -l app=notice-shortmsg-test NAME READY STATUS RESTARTS AGE notice-shortmsg-test-gb2w91-5f55794f9b-8zb44 1/1 Running 0 6d4h3、使用json方式获取pod的name (如果多个需要修改item的指针)
[root@k8s-master ~]# kubectl get pod -n rkw-ezc-test -l app=notice-shortmsg-test -o jsonpath='{.items[0].metadata.name}' notice-shortmsg-test-gb2w91-5f55794f9b-8zb444、如果要显示全部的pod名称 使用* 代替角标
[root@k8s-master ~]# kubectl get pod -n kubesphere-monitoring-system -l app=node-exporter -o jsonpath='{.items[*].metadata.name}' node-exporter-b5pvs node-exporter-bxk2h node-exporter-h9kmd node-exporter-l4cb25、直接删除某个名称的所有pod
# 删除所有带有lable name=myLabel的pod和service $ kubectl delete pods,services -l name=myLabel [root@k8s-master ~]# kubectl delete pod -n zhxq3-test -l app=community-manager-login pod "community-manager-login-gucvi3-6f8bd995f8-l6vtm" deleted [root@k8s-master ~]# kubectl get pod -n zhxq3-test -l app=community-manager-login NAME READY STATUS RESTARTS AGE community-manager-login-gucvi3-6f8bd995f8-6srfx 1/1 Running 0 9s6、查询事件 (常用命令)
kubectl get events --all-namespaces7、多个pod如何查询全部日志
kubectl logs -f --tail=100 -n chinapopin-system-prod -l app=chinapopin-biz-student