
두가지 비슷한 용어가 있다.
ReplicationControllerReplicaSet둘다 Pod의 고가용성, 로드밸런싱&스케일링을 도와준다.
둘다 비슷한 기능을 수행하지만, 주요한 차이점이 존재한다.
(ReplicaSet이 ReplicationController를 대체하고 있는 중이라고 알고있음)
apiVersion: v1
kind: ReplicationController
metadata:
name: myapp-rc
labels:
app: myapp
type: front-end
spec:
template:
# pod ===================
metadata:
name: myapp-pod
labels:
app: myapp
type: front-end
spec:
containers:
- name: nginx-container
image: nginx
replicas: 3
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: myapp-replicaSet
labels:
app: myapp
type: front-end
spec:
template:
# pod ===================
metadata:
name: myapp-pod
labels:
app: myapp
type: front-end
spec:
containers:
- name: nginx-container
image: nginx
replicas: 3
selector:
matchLabels:
type: front-end
주요 차이점 1 : apiVersion이 다르다.
v1과 다르게 apps/v1 버전은 다양한 기능을 포함하고 있다.
주요 차이점 2 : ReplicaSet은 selector 정의가 필요하다.
ReplicaSet은 ReplicationController와 다르게 template으로 생성하지 않은 Pod도 관리할 수 있다.
예를 들어, ReplicaSet을 적용했을 때 Label 필터링을 통해 replicas 수에 맞는 Pod이 존재한다면(기존에 배포한 Pod), 새롭게 Pod을 배포하지 않는다.
ReplicaSet은 Pod을 지속적으로 모니터링한다.
그리고 모니터링을 수행할 때 Label 필터링을 통해 선별한다.
# pod-definition.yml
metadata:
name: myapp-pod
labels:
tier: front-end
# replicaset-definition.yml
selector:
matchLabels:
tier: front-end
고가용성을 보장하는 ReplicaSet 장점과 동작과정은 배웠다.
그러면 ReplicaSet을 어떻게 조작해서 Pod의 개수를 변경할 수 있을까?
방법은 여러가지다.
방법1. YAML 파일을 수정(replicas: 6) -> kubectl replace -f [YAML]
방법2. kubectl scale --replicas=6 -f [YAML]
방법3. kubectl scale --replicas=6 [TYPE] [NAME]
참고 자료