데몬셋과 동일하게 OnDelete, RollingUpdate 를 지정할 수 있지만 몇가지 차이점이 있다.
1. RollingUpdate 시 데몬셋과 다른 점
OnDelete 는 데몬셋의 그것과 동일하게 동작하지만, RollingUpdate 의 경우에는 좀 다르다. 스테이트풀셋은 영속성 데이터를 다루는 리소스 컨트롤러 이므로, 추가 파드를 생성해서 롤링 업데이트를 할 수 없으며, 마찬가지로 maxUnavailable 를 지정하여 업데이트 중 동시에 여러 파드를 중지시킬 수도 없다. 파드마다 ready 상태 여부를 확인하고 순차적으로 업데이트하게 된다.(spec.podManagementPolicy: Parallel 이어도 마찬가지)
2. RollingUpdate 시 파티션을 나누어 업데이트
스테이트풀셋의 경우 spec.updateStrategy.rollingUpdate.partition 필드에 RollingUpdate 를 적용할 파티션을 지정할 수 있다.(아래 참고) partition 을 설정하면, 해당 값 이상의 인덱스 값을 가진 파드들만 업데이트 대상이 된다. 수동으로 재기동한 경우에도 partition 의 영향을 받는다.
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: statefulset-rollingupdate
spec:
updateStrategy:
type: RollingUpdate
rollingUpdate:
partition: 3
serviceName: statefulset-rollingupdate
replicas: 5
selector:
matchLabels:
app: sample-app
template:
metadata:
labels:
app: sample-app
spec:
containers:
- name: nginx-container
image: nginx:1.16

위 매니페스트를 사용하여 스테이트풀셋을 만들고, 파드를 업데이트하면서 관찰해보면, 실제로 partition 에 해당하는 인덱스 이상의 파드만 업데이트 되는 것을 볼 수 있다.
$ kubectl apply -f statefulset-rollingupdate.yaml
# statefulset-rollingupdate-0 ~ 4 까지 5개의 파드가 순차적으로 생성됨
# nginx:1.16 -> nginx:1.17 로 이미지 수정 후 다시 apply 를 진행
# watch 를 이용하여 파드 상태를 관찰하면 아래와 같이 출력됨
$ kubectl get pods -l app=sample-app -o wide --watch
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
statefulset-rollingupdate-4 1/1 Terminating 0 83s 10.244.2.11 desktop-worker2 <none> <none>
statefulset-rollingupdate-4 0/1 Completed 0 83s 10.244.2.11 desktop-worker2 <none> <none>
statefulset-rollingupdate-4 0/1 Completed 0 84s 10.244.2.11 desktop-worker2 <none> <none>
statefulset-rollingupdate-4 0/1 Completed 0 84s 10.244.2.11 desktop-worker2 <none> <none>
statefulset-rollingupdate-4 0/1 Pending 0 0s <none> <none> <none> <none>
statefulset-rollingupdate-4 0/1 Pending 0 0s <none> desktop-worker2 <none> <none>
statefulset-rollingupdate-4 0/1 ContainerCreating 0 0s <none> desktop-worker2 <none> <none>
statefulset-rollingupdate-4 1/1 Running 0 1s 10.244.2.12 desktop-worker2 <none> <none>
statefulset-rollingupdate-3 1/1 Terminating 0 86s 10.244.2.10 desktop-worker2 <none> <none>
statefulset-rollingupdate-3 1/1 Terminating 0 86s 10.244.2.10 desktop-worker2 <none> <none>
statefulset-rollingupdate-3 0/1 Completed 0 86s 10.244.2.10 desktop-worker2 <none> <none>
statefulset-rollingupdate-3 0/1 Completed 0 87s 10.244.2.10 desktop-worker2 <none> <none>
statefulset-rollingupdate-3 0/1 Completed 0 87s 10.244.2.10 desktop-worker2 <none> <none>
statefulset-rollingupdate-3 0/1 Pending 0 0s <none> <none> <none> <none>
statefulset-rollingupdate-3 0/1 Pending 0 0s <none> desktop-worker2 <none> <none>
statefulset-rollingupdate-3 0/1 ContainerCreating 0 0s <none> desktop-worker2 <none> <none>
statefulset-rollingupdate-3 1/1 Running 0 1s 10.244.2.13 desktop-worker2 <none> <none>
즉, 0번~2번 인덱스의 파드는 영향을 받지 않고, 3~4번 인덱스의 파드가 하나씩 순차적으로 Termination -> Completed 로 종료된 후, Pending -> ContainerCreating -> Running 으로 새로 실행된 것을 알 수 있다. 여기서 이번에는 partition 을 1로 변경 후 apply 하게 되면 1~2번 파드만 추가로 업데이트를 하게 된다.(기존 업데이트 완료되었던 3~4번 파드는 업데이트되지 않음)
'Kubernetes' 카테고리의 다른 글
| [Kubernetes] 잡 (0) | 2025.10.04 |
|---|---|
| [Kubernetes] 스테이트풀셋 삭제와 영구 볼륨 정리 (0) | 2025.09.07 |
| [Kubernetes] 스테이트풀셋 (1) | 2025.09.07 |
| [Kubernetes] 데몬셋(DaemonSet) (0) | 2025.09.02 |
| [Kubernetes] 디플로이먼트 업데이트 상세 설정 (0) | 2025.08.31 |