- ReplicaSet, Pod의 배포를 관리하는 리소스
- ReplicaSet의 상위 오브젝트이며, Deployment를 생성하면 ReplicaSet과 Pod, 컨테이너까지 다 생성해준다, 그래서 보통 ReplicaSet보단 Deployment를 많이 사용하고 YAML 파일에도 적용한다고 함
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-nginx-deployment
spec:
replicas: 3
selector:
matchLabels:
app: my-nginx
template:
metadata:
name: my-nginx-pod
labels:
app: my-nginx
spec:
containers:
- name: nginx
image: nginx:1.10
ports:
- containerPort: 80
- YAML 파일도 ReplicaSet 생성하는 예시와 거의 동일하다, kind만 다를뿐
그럼 왜 쓰는가?
- 어플리케이션의 배포, 업데이트와 관리를 위함
- ReplicaSet을 생성하는 YAML을 수정하여 배포하고 관리하여 업데이트도 할 순 있겠지만, Deployment를 배포함으로써 ReplicaSet으로 버전 관리를 한다
- 그래서 첫 배포 후 업데이트를 하여 별도 배포를 하고 나면 Pod는 알맞은 갯수로 생성되지만, ReplicaSet은 첫 배포, 별도 배포에 대하여 모두 남아있게 된다
- 따로 삭제를 해주지 않는데 왜냐면 롤백을 할때, 이 리비전 넘버가 있는 ReplicaSet을 통해 바로 롤백을 수행할 수 있기 때문
- 위 캡쳐 예시로도 버전별로 ReplicaSet이 나눠져있고, 실행하는 Set에 맞게 Pod를 생성하고 어플리케이션을 유지할수 있게 된다