how to use kubectl command with flag --selector?

4/20/2016

I have a question about kubectl command with flag --selector. In help menu it says,

-l, --selector="": Selector (label query) to filter on

how ever it does't work as i expect, for example, i want to get RC who have selector like

    "spec": {
    "replicas": 2,
    "selector": {
        "app": "tas-core"
    },

when i give command

kubectl get pod --selector="app:tas-core"

system report: the provided selector "app:tas-core" is not valid: unable to parse requirement: label key: invalid value 'app:tas-core', Details: must match regex [a-z0-9?(.a-z0-9?)* / ] a-z0-9?

after i check the regexp

[[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)* / ] [a-z0-9]([-a-z0-9]*[a-z0-9])?

i still can't find any string which can pass the regexp! i gave,

kubectl get rc -l app/tas-core

nothing has been returned. How could i use it?

I have also another question, how to filter all pods which with label like

"labels": {
  "app": "tas-core"
}

?

-- Zhi Yuan
kubernetes

2 Answers

10/27/2019
  • To use one selector with kubectl command,apply the follwing command: kubectl get po --selector name=value where name is the selector name and value is the selector value.
  • You can use rc, svc or deployments (any k8s resource) needed to be listed and also filtered with a selector.
  • There is also an option to list or filter k8s resources with multiple selectors, just use the following command: kubectl get all --selector name1=value1,name2=value2,name3=value3
-- Omar Khaled
Source: StackOverflow

4/20/2016

Try kubectl get pods --selector=app=tas-core

as in http://kubernetes.io/docs/user-guide/kubectl-cheatsheet/

-- Jane
Source: StackOverflow