
app=frontend, tier=backend, env=prodkubectl get pods -l app=myapp → app=myapp 라벨을 가진 포드 조회.=, !=, in, notin 등으로 조건 세밀하게 설정 가능.kubectl get pods -l app=myapp → 라벨 app=myapp 가진 포드를 선택.app, tier, env 등description, contact, buildVersion 등apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: myapp-replicaset
labels:
component: replicaset
env: dev
spec:
replicas: 3
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
tier: frontend
env: dev
spec:
containers:
- name: myapp-container
image: nginx:1.27-alpine
ReplicaSet 자체 라벨 (metadata.labels)
ReplicaSet 리소스를 식별하기 위한 라벨
다른 오브젝트가 ReplicaSet을 찾을 때 사용
Selector.matchLabels
ReplicaSet이 관리할 Pod을 찾는 기준이 되는 라벨
Pod 템플릿에 동일 라벨이 정의되어야 함
Pod 템플릿 라벨 (template.metadata.labels)
ReplicaSet이 생성하는 Pod에 붙는 라벨
ReplicaSet의 selector.matchLabels와 일치해야만 관리 가능
동작 시나리오 예시
replicas: 3, selector.matchLabels=app:myapp
클러스터에 app=myapp 라벨을 가진 Pod이 1개 있을 때, ReplicaSet은 2개를 더 만들고, 총 3개의 Pod를 관리하게 됨.
apiVersion: v1
kind: Service
metadata:
name: myapp-service
labels:
component: service
env: dev
spec:
type: ClusterIP
selector:
app: myapp
ports:
- port: 80
targetPort: 8080
Service 자체 라벨 (metadata.labels)
- Service 리소스를 식별하기 위한 라벨
- 다른 오브젝트에서 Service를 참조하거나 관리할 때 사용
Service Selector (spec.selector)
- Service가 연결할 Pod을 찾기 위한 기준
- Pod에 동일한 라벨이 있어야만 Service가 Pod로 트래픽을 전달
Pod ↔ Service 연결
- Pod의 라벨 app=myapp → Service selector app=myapp 일치시, 트래픽 전달.
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
labels:
app: myapp
annotations:
description: "This pod runs the myapp frontend"
contact: "team-frontend@example.com"
buildVersion: "1.2.3"
spec:
containers:
- name: myapp-container
image: nginx:1.27-alpine
Key-Value 쌍으로 메타데이터 기록
선택/필터링에는 사용되지 않음
description: Pod에 대한 설명
contact: 관리자의 연락처
buildVersion: 버전 정보