- app: 애플리케이션 구성요소, 마이크로서비스 유형 지정
- rel: 애플리케이션의 버전 지정
canary는 임시버전
apiVersion: v1
kind: Pod
metadata:
name: label-demo
labels:
environment: production
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
environment: production
app: nginx
$ kubectl label pod http-go-v2 test=foo
pod/http-go-v2 labeled
$ kubectl label pod http-go-v2 rel=beta
error: 'rel' already has a value (canary), and --overwrite is false
$ kubectl label pod http-go-v2 rel=beta --overwrite
pod/http-go-v2 labeled
$ kubectl label pod http-go-v2 rel-
kubectl get pod --show-labels
$ kubectl get pod --show-labels
NAME READY STATUS RESTARTS AGE LABELS
http-go 1/1 Running 0 53m <none>
http-go-v2 1/1 Running 0 2m5s app=http-go,foo=bar,rel=beta,test=foo
kubectl get pod -L app,rel
$ kubectl get pod -L app,rel
NAME READY STATUS RESTARTS AGE APP REL
http-go 1/1 Running 0 62m
http-go-v2 1/1 Running 0 11m http-go beta
env 있는 것만
kubectl get pod --show-labels -l 'env'
$ kubectl get pod --show-labels -l 'env'
NAME READY STATUS RESTARTS AGE LABELS
http-go-v2 1/1 Running 0 3m10s creation_method=manual,env=prod,rel=beta,test=foo
env 없는 것만
kubectl get pod --show-labels -l '!env'
$ kubectl get pod --show-labels -l '!env'
NAME READY STATUS RESTARTS AGE LABELS
http-go 1/1 Running 0 2m <none>
env가 test 아닌 것
kubectl get pod --show-labels -l 'env!=test'
$ kubectl get pod --show-labels -l 'env!=test'
NAME READY STATUS RESTARTS AGE LABELS
http-go 1/1 Running 0 4m <none>
http-go-v2 1/1 Running 0 5m14s creation_method=manual,env=prod,rel=beta,test=foo
env가 test 아니면서 rel은 beta인거
kubectl get pod --show-labels -l 'env!=test,rel=beta'
$ kubectl get pod --show-labels -l 'env!=test,rel=beta'
NAME READY STATUS RESTARTS AGE LABELS
http-go-v2 1/1 Running 0 5m58s creation_method=manual,env=prod,rel=beta,test=foo