
| 구분 | ReplicationController (RC) | ReplicaSet (RS) |
|---|---|---|
| 상태 | 구식(Deprecated), 유지 보수 X | 최신 권장 리소스 |
| API 버전 | apiVersion: v1 | apiVersion: apps/v1 |
| 목적 | 지정된 수의 Pod 유지, 자동 복구 | 동일 (Pod 복제본 관리 및 자동 복구) |
| Selector | 선택기(selector) 선택 사항 (생략 가능) | Selector 필수 (matchLabels 등으로 Pod 매칭) |
| 라벨 관리 | 단순 라벨 매칭 | 고급 라벨 매칭 지원 (matchLabels, matchExpressions) |
| 실무 사용 | 거의 사용 안 함 | Deployment, StatefulSet의 기반으로 적극 사용 |
| 주요 활용 | 학습용, 과거 문서 | 현대 쿠버네티스 환경에서 표준 |
apiVersion: v1
kind: ReplicationController
metadata:
name: myapp-rc
labels:
app: myapp
type: front-end
spec:
replicas: 3 # 유지할 Pod 개수 지정
template: # Pod 템플릿
metadata:
name: myapp-pod
labels:
app: myapp
type: front-end
spec:
containers:
- name: nginx-container
image: nginx
kubectl create -f rc-definition.yml # RC 생성
kubectl get replicationcontroller # RC 상태 확인
kubectl get pods # RC가 관리하는 Pod 목록 확인
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: myapp-replicaset
labels:
app: myapp
type: front-end
spec:
replicas: 3
selector:
matchLabels:
type: front-end
template: # Pod 템플릿
metadata:
name: myapp-pod
labels:
app: myapp
type: front-end
spec:
containers:
- name: nginx-container
image: nginx
kubectl create -f replicaset-definition.yml # ReplicaSet 생성
kubectl get replicaset # RS 상태 확인
kubectl get pods # RS가 관리하는 Pod 확인
kubectl replace -f replicaset-definition.yml # 정의 파일 수정 후 적용
kubectl delete replicaset <이름> # RS 및 관련 Pod 삭제
| 구분 | Label (라벨) | Selector (셀렉터) |
|---|---|---|
| 정의 | 리소스에 붙이는 key:value 태그 | 특정 라벨 조건에 맞는 리소스 선택 필터 |
| 형태 | app: myapp, tier: frontend | matchLabels: app=myapp |
| 역할 | 리소스 분류, 그룹화, 식별 | 라벨 기준으로 Pod/리소스 선택 |
| 사용 위치 | Pod, Service, ReplicaSet, Deployment 등 | ReplicaSet, Deployment, Service 등 |
| 예시 | Pod → labels: app=myapp | RS → selector: matchLabels: app=myapp |
| 비유 | "이 Pod은 app=myapp이야" (태그 붙이기) | "app=myapp인 Pod만 관리할게" (필터링) |
# replicas: 3 → 6 으로 수정 후 적용
kubectl replace -f replicaset-definition.yml
kubectl scale --replicas=6 -f replicaset-definition.yml
# 또는
kubectl scale --replicas=6 replicaset myapp-replicaset
주의: 이 경우 YAML 파일 안의 replicas 값은 업데이트되지 않음.