StatefulSet

dongbin_Shin·2022년 11월 15일
0

kubernetes

목록 보기
13/16

Stateless Application VS Stateful Application

Stateless ApplicationStateful Application
역할단순 복제각자 역할을 가짐
재생성같은 서비스의 역할을 하는 앱을 생성
앱 이름 달라도 상관 없음Down된 앱과 같은 앱을 생성
앱 이름 같아야 함
Volume하나의 Volume을 공유하여 사용 가능앱 각자의 Volume을 사용해야 함
네트워크앱들이 트래픽을 균등하게 나누어 가짐각 앱의 특징에 맞게 트래픽을 가짐
예시Apache, NginxMariaDB, Redis, MongoDB
ControllerReplicaSetStatefulSet
ServiceServiceHeadless Service

StatefulSet Controller

ReplicaSetStatefulSet
pod 이름{Pod 이름}-{랜덤 값}{Pod 이름}-{index}
동시 생성replicas만큼 동시에 Pod 생성replicas만큼 순서대로 Pod 생성
동시 삭제replicas만큼 동시에 Pod 삭제replicas만큼 순서대로 Pod 삭제
PVC 생성PVC 직접 생성 해야 함volumeClaimTemplate을 통해 PVC 동적 생성
단일 PVC 여부Pod들이 하나의 PV와 PVC를 공유하여 사용Pod마다 PVC와 PV가 생성
ServicePod의 이름을 예측하기 어렵기 때문에 HeadlessService 연결하기 힘듬Pod의 이름을 예측할 수 있기 때문에 HeadlessService로 Pod에 접근 가능
# StatefulSet
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: stateful-db
spec:
  replicas: 1
  selector:
    matchLabels:
      type: db
  template:
    metadata:
      labels:
        type: db
    spec:
      containers:
      - name: container
        image: something
# StatefulSet with PVC
apiVersion: apps/v1
kind: statefulSet
metadata:
  name: stateful-pvc
spec:
  replicas: 1
  selector:
    matchLabels:
      type: db2
  serviceName: "stateful-headless"
  template:
    metadata:
      labels:
        type: db2
    spec:
      containers:
      - name: container
        image: something
        volumeMounts:
        - name: volume # 이름이 아래와 동일해야함
          mountPath: /applog
  volumeClaimTemplate:
  - metadata:
      name: volume # 이름이 위와 동일해야함
    spec:
      accessModes:
      - ReadWriteOnce
      resources:
        requests:
          storage: 1G
      storageClassName: "fast"
apiVersion: v1
kind: Service
metadata:
  name: stateful-headless
spec:
  selector:
    type: db2
  ports:
    - port: 80
      targetPort: 8080
  clusterIP: None
profile
멋있는 백엔드 개발자

0개의 댓글