Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use kubectl command with flag --selector?

Tags:

kubernetes

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

?

like image 619
Zhi Yuan Avatar asked Apr 20 '16 11:04

Zhi Yuan


1 Answers

Try

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

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

like image 132
Jane Avatar answered Oct 05 '22 19:10

Jane