kubernetes

how to use kubectl command with flag --selector?


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"
}

?


Solution

  • Try

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

    as in https://kubernetes.io/docs/reference/kubectl/quick-reference