Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


Info

Table of Contents

...

StatefulSet개요

Info
  • 애플리케이션의 상태를 저장하고 관리하는 데 사용되는 쿠버네티스 객체
  • 기존의 포드를 삭제하고 생성할 때 상태를 유지해 줍니다.


Info
  • 안정된, 고유한 네트워크 식별자
  • 안정된, 지속성을 갖는 스토리지
  • 순차적인, 정상배포와 스케일링
  • 순차적인, 자동 롤링 업데이트


Info
  • Statefullset Statefulset 관련 Volume이 삭제되지 않으므로 관리가 필요
  • Pod의 Storage는 PV나 StorageClass로 Provisioning이 필요
  • RollingUpdate를 수행하는 경우 수동으로 복구해야 할 수 있음 (기존의 스토리지와 충돌)
  • Pod 네트워크ID를 유지하기 위해 Headless서비스 필요



Info


Info

Headless 서비스 작성 방법

Code Block
apiVersion: v1
kind: Service
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  ports:
  - port: 80
    name: web
  clusterIP: None
  selector:
    app: nginx
StatefullSet

StatefulSet 작성 방법

Info

Deployment와 전반적인 설정은 유사합니다. Deployment와 다른 속성들만 설명 합니다.

  •  serviceName
    • serviceName으로 고유한 네트워크ID를 생성합니다.
  • terminationGracePeriodSeconds
    • 종료 요청(SIGTERM)후 Pod가 삭제되기까지 Delay시간을 줍니다.
  • volumeClaimTemplates
    • 안정적인 스토리지 제공을 위해 PVC를 작성합니다.
  • volumeMounts
    • 영구 스토리지를 연결하고자 하는 위치


StorageClass확인

Code Block
titleStorageClass
linenumberstrue
collapsetrue
sansae@sansaeAir15m2 k8s-lab-workspace % k get storageclass
NAME                    PROVISIONER          RECLAIMPOLICY   VOLUMEBINDINGMODE      ALLOWVOLUMEEXPANSION   AGE
azurefile               file.csi.azure.com   Delete          Immediate              true                   34h
azurefile-csi           file.csi.azure.com   Delete          Immediate              true                   34h
azurefile-csi-premium   file.csi.azure.com   Delete          Immediate              true                   34h
azurefile-premium       file.csi.azure.com   Delete          Immediate              true                   34h
default (default)       disk.csi.azure.com   Delete          WaitForFirstConsumer   true                   34h
managed                 disk.csi.azure.com   Delete          WaitForFirstConsumer   true                   34h
managed-csi             disk.csi.azure.com   Delete          WaitForFirstConsumer   true                   34h
managed-csi-premium     disk.csi.azure.com   Delete          WaitForFirstConsumer   true                   34h
managed-premium         disk.csi.azure.com   Delete          WaitForFirstConsumer   true                   34h
sansae@sansaeAir15m2 k8s-lab-workspace % 
StatefullSet

StatefulSet Manifest

Code Block
titlestatefullsetstatefulset.yaml
linenumberstrue
apiVersion: v1
kind: Service
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  ports:
  - port: 80
    name: web
  clusterIP: None
  selector:
    app: nginx
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: web
spec:
  selector:
    matchLabels:
      app: nginx
  serviceName: "nginx"
  replicas: 3 # 기본값은 1
  minReadySeconds: 10 # 기본값은 0
  template:
    metadata:
      labels:
        app: nginx
    spec:
      terminationGracePeriodSeconds: 10
      containers:
      - name: nginx
        image: registry.k8s.io/nginx-slim:0.8
        ports:
        - containerPort: 80
          name: web
        volumeMounts:
        - name: www
          mountPath: /usr/share/nginx/html
  volumeClaimTemplates:
  - metadata:
      name: www
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: azurefile
      resources:
        requests:
          storage: 1Gi
Code Block
linenumberstrue
sansae@sansaeAir15m2 k8s-lab-workspace % k apply -f statefulset.yaml 
service/nginx created
statefulset.apps/web created
sansae@sansaeAir15m2 k8s-lab-workspace % k get all
NAME        READY   STATUS    RESTARTS   AGE
pod/web-0   0/1     Pending   0          3s

NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   10.0.0.1     <none>        443/TCP   29s
service/nginx        ClusterIP   None         <none>        80/TCP    3s

NAME                   READY   AGE
statefulset.apps/web   0/3     3s

sansae@sansaeAir15m2 k8s-lab-workspace % k get all         
NAME        READY   STATUS    RESTARTS   AGE
pod/web-0   1/1     Running   0          2m47s
pod/web-1   1/1     Running   0          117s
pod/web-2   1/1     Running   0          97s

NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   10.0.0.1     <none>        443/TCP   3m13s
service/nginx        ClusterIP   None         <none>        80/TCP    2m47s

NAME                   READY   AGE
statefulset.apps/web   3/3     2m47s


...