Notice
Recent Posts
Recent Comments
Link
«   2025/07   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Archives
Today
Total
관리 메뉴

전공공부

Labels, Selectors 본문

Study/K8S

Labels, Selectors

monitor 2023. 3. 27. 23:22

 

Labels

사용자가 필터로 사용해서 Label에 따라서 사용 할 수 있게 끔 key value 쌍을 제공해줍니다.

 

pod-defination.yaml

apiVersion: v1
kind: Pod
metadata: 
  name: myapp-pod
  lables:
    app: app1
    function: Front-end
spec:
  containers:
    - name: data-processor
      image: data-processor
      ports:
        - containerPort: 8080
    - name: log-agent
      image: log-agent

 

Selectors

kubectl get pods --selector app=app1

여러 Label 검색

kubectl get pod  --selector <key>=<value>,<key>=<value>,<key>=<value> #여러 Labels 검색

여러개의 selector 갯수를 파악 할 때

kubectl get pod --selector <key>=<value> | wc -l #word count 값을 이용하여 counting된 갯수를 가질 수 있다

 

위 Label의 app 키의 app1 value를 가져올 수 있습니다.

 

replicaset을 Label로 묶을 수 있는가?

 

replicaset-defination.yaml

apiVersion: v1
kind: ReplicaSet
metadata: 
  name: myapp-pod
  labels:
    app: app1
    function: Front-end
spec:
  replicas: 3
  selector:
    matchLabels:
      app: app1
  template:
    metadata:
      labels:
        app: app1
        function: Front-end
    spec:
      containers:
        - name: simple-webapp
        - image: simple-webapp

 

위와 같이 만들 수 있다. 다만 위 예제에서 헷갈릴 수 있는 부분은 template 하부의 pod defination은 다른 Pod를 참조하는 것이고 ReplicaSet의 labels는 ReplicaSet 그 자체의 label이다.

 

그리고, selector field의 matchLabels의 app: app1은 template의 pod 연결부를 말한다. (to matched under line pod)      

 

 

'Study > K8S' 카테고리의 다른 글

Jobs & Cronjob  (1) 2023.03.28
Rollout Update  (0) 2023.03.27
Logging  (0) 2023.03.26
Readiness & Liveness Probe  (0) 2023.03.26
Multi-Container PODs  (0) 2023.03.26