Statefulset이란?
- pod의 상태를 유지해주는 controller
- pod 이름
- pod의 볼륨(스토리지)
- daemonset처럼 node 당 pod 1개를 보장하지 않음
- definition
apiVersion: apps/v1
kind: StatefulSet # kind 종류 확인
metadata:
name: sf-nginx
spec:
replicas: 3
serviceName: sf-service # serviceName 존재
selector:
matchLabels:
app: webui
template:
metadata:
name: nginx-pod
labels:
app: webui
spec:
containers:
- name: nginx-container
image: nginx:1.14
[ Hands - on ]
- statefulset 생성
vi statefulset-exam.yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: sf-nginx
spec:
replicas: 3
serviceName: sf-service
# podManagementPolicy: OrderedReady
podManagementPolicy: Parallel
selector:
matchLabels:
app: webui
template:
metadata:
name: nginx-pod
labels:
app: webui
spec:
containers:
- name: nginx-container
image: nginx:1.14
kubectl create -f statefulset-exam.yaml
nana@master:~$ kubectl get pods -o wide --watch
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
sf-nginx-0 1/1 Running 0 20s 192.168.178.196 node3.example.com <none> <none>
sf-nginx-1 1/1 Running 0 20s 192.168.221.5 node2.example.com <none> <none>
sf-nginx-2 1/1 Running 0 20s 192.168.11.70 node1.example.com <none> <none>
- scale out
- 번호 순서대로 증가
kubectl scale statefulset sf-nginx --replicas=4
nana@master:~$ kubectl get pods -o wide --watch
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
sf-nginx-0 1/1 Running 0 3m13s 192.168.178.196 node3.example.com <none> <none>
sf-nginx-1 1/1 Running 0 3m13s 192.168.221.5 node2.example.com <none> <none>
sf-nginx-2 1/1 Running 0 3m13s 192.168.11.70 node1.example.com <none> <none>
sf-nginx-3 1/1 Running 0 6s 192.168.178.197 node3.example.com <none> <none>
- scale in
- 번호 역순서대로 감소
kubectl scale statefulset sf-nginx --replicas=2
nana@master:~$ kubectl get pods -o wide --watch
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
sf-nginx-0 1/1 Running 0 4m57s 192.168.178.196 node3.example.com <none> <none>
sf-nginx-1 1/1 Running 0 4m57s 192.168.221.5 node2.example.com <none> <none>
- rolling update
- 번호 역순서대로 update
kubectl edit statefulsets.apps sf-nginx
- rollback
kubectl rollout undo statefulset sf-nginx
참고 :
'INFRA > DevOps' 카테고리의 다른 글
[k8s] Cronjob (0) | 2022.11.01 |
---|---|
[K8s] Job Controller (0) | 2022.10.24 |
[NGINX] Reverse Proxy (0) | 2022.10.11 |
API Proxy (0) | 2022.10.11 |
[K8s] DaemonSet (0) | 2022.10.11 |
댓글