how to do filtering based on labels of pods

2,552 views
Skip to first unread message

Priyadarshini Anand

unread,
May 23, 2016, 2:16:18 AM5/23/16
to kubernetes-dev



I want to get list of pods with label ms=abc, when I use http://ip:8080/api/v1/namespaces/default/pods?fieldSelector=metadata.labels.ms%%3Dabc , it returns me list of all pods not filtered one based on pods with label ms=abc. Someone, please help how to get list of pods based on labels(I want rest api). I tried pods?watch=true&fieldSelector=metadata.labels.ms%%3Dabc&timeoutSeconds=5 but that is also showing same results as the previous one.

Madhusudan C.S.

unread,
May 23, 2016, 5:08:05 AM5/23/16
to Priyadarshini Anand, kubernetes-dev
If you want to filter on labels, you can just use the labelSelector. Your query looks something like:


On Mon, May 23, 2016 at 11:46 AM, Priyadarshini Anand <epriy...@gmail.com> wrote:



I want to get list of pods with label ms=abc, when I use http://ip:8080/api/v1/namespaces/default/pods?fieldSelector=metadata.labels.ms%%3Dabc , it returns me list of all pods not filtered one based on pods with label ms=abc. Someone, please help how to get list of pods based on labels(I want rest api). I tried pods?watch=true&fieldSelector=metadata.labels.ms%%3Dabc&timeoutSeconds=5 but that is also showing same results as the previous one.

--
You received this message because you are subscribed to the Google Groups "kubernetes-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-de...@googlegroups.com.
To post to this group, send email to kuberne...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kubernetes-dev/6123f31a-427e-405e-a3da-7ccc0498768e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Madhusudan C.S.

unread,
May 23, 2016, 5:12:32 AM5/23/16
to Priyadarshini Anand, kubernetes-dev
Also, you might find this documentation on label selectors useful - http://kubernetes.io/docs/user-guide/labels/#label-selectors
Message has been deleted

Madhusudan C.S.

unread,
May 23, 2016, 1:46:01 PM5/23/16
to Priyadarshini Anand, kubernetes-dev


On Mon, May 23, 2016 at 4:47 PM, Priyadarshini Anand <epriy...@gmail.com> wrote:
ok fine.

and If I want ms=abc or ms=xyz

The "OR" query looks something like:

ms in (abc,xyz)

Please see the set-based requirement section in the doc that I linked. It explains how to perform more advanced set-like selections.


The exact URL with query param looks something like:

 http://ip:8080/api/v1/namespaces/default/pods?labelSelector=ms in (abc,xyz) 
I haven't quoted/encoded the URL, you probably have to.
 
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages