简体   繁体   中英

Kubectl get pods - How to filter pods by partial name

The command kubectl get pods <POD NAME> will return the specific pod with that name. I wonder if there is a way that I can use part of the name, for instance, a command that returns all pods that start with j .

Filter without grep (unfortunately requires full name):

kubectl get pods --field-selector metadata.name=<your_pod_name>

this works for me. Of course you have to precise the namespace if not set in the current-context

Found it. in PS:

kubectl get pods | Select-String '^j'

in bash:

kubectl get pods | grep ^j

If you have crictl installed in your node:

 crictl pods --name '^j'

here the way how we get and delete the pod by the name

kubectl get pods -o=name -n namespace-name | grep initial-podname

kubectl delete $(kubectl get pods -o=name -n namespace-name | grep initial-podname) -n namespace-name

Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM