-
Kubernetes(K8S): DaemonSet & StatefulSet공부합시다!/Kubernetes 2023. 1. 4. 00:13728x90
간단하게 말하자면 DaemonSet은 모든 Node 또는 특정 label를 가진 node에 하나씩의 동일한 pod를 배포해주는 resource,
StatefulSet은 Pod(Pod내의 App)의 상태를 저장하고 관리하는 Resource 입니다.
1. DaemonSet
Daemonset: https://velog.io/@makeitcloud/Kubernetes-GKE-DaemonSet%EA%B3%BC-StatefulSet-%EC%82%AC%EC%9A%A9%ED%95%98%EA%B8%B0 1.1. Worker Node의 Resource Mornitoring용 App 이나 Log 수집기를 배포할 때 사용됨
1.2. Pod를 Node에 하나씩 배포 - 별도의 Replicas를 설정하지 않음.
1.3. DaemonSet이 구동중인 Cluster에 Node가 추가되면 해당 Node에도 DaemonSet Pod가 배포됨.
1.4. 삭제된 DaemonSet Pod가 다른 Node로 이동하지는 않음.
apiVersion: apps/v1 kind: DaemonSet metadata: name: fluentd-elasticsearch namespace: kube-system labels: k8s-app: fluentd-logging spec: selector: matchLabels: name: fluentd-elasticsearch template: metadata: labels: name: fluentd-elasticsearch spec: tolerations: # 이 톨러레이션(toleration)은 데몬셋이 컨트롤 플레인 노드에서 실행될 수 있도록 만든다. # 컨트롤 플레인 노드가 이 파드를 실행해서는 안 되는 경우, 이 톨러레이션을 제거한다. - key: node-role.kubernetes.io/control-plane operator: Exists effect: NoSchedule - key: node-role.kubernetes.io/master operator: Exists effect: NoSchedule containers: - name: fluentd-elasticsearch image: quay.io/fluentd_elasticsearch/fluentd:v2.5.2 resources: limits: memory: 200Mi requests: cpu: 100m memory: 200Mi volumeMounts: - name: varlog mountPath: /var/log - name: varlibdockercontainers mountPath: /var/lib/docker/containers readOnly: true terminationGracePeriodSeconds: 30 volumes: - name: varlog hostPath: path: /var/log - name: varlibdockercontainers hostPath: path: /var/lib/docker/containers
2. StatefulSet
2.1. Pod 구성, 유지, 스케일등에서 Daployment와 거의 동일한 특성
2.2. Deployment와는 다르게 각 Pod의 순서와 고유성을 보장하며 영구 스토리지 볼륨을 할당한다.
2.3. 필요성: MySQL과 같은 DB Cluster 구성을 생각해보세요!
2.3.0. K8S에서 실행되는 다수 서비스는 Stateless을 특징을 갖음(nginx는 어느 Pod에서나 역할이 동일,storage도 동일)
2.3.1. 데이터의 안정성, 무결성등을 유지하기 위한 설계 필요(어떤 pod는 crud가능, 어떤 pod는 read만, 어떤 pod는 감시)
2.3.2. Pod의 상태와는 무관하게 스토리지는 언제나 안전하게 유지되어야 한다.
2.3.3. 개별 Pod에 대한 안정적이고 고유한 네트워크 식별자 제공
2.3.4. 안정적이고 지속적인 Storage 제공
2.3.5. Pod와 Storage의 질서 정연한 배포 및 확장성
2.4. 주의사항
2.4.1. StatefulSet 생성시 각 pod마다 PV(Persistent Volume)도 함께 생성됨, 그러나 삭제 시 PV는 삭제되지 않음.
2.4.2. StatefulSet으로 생성하는 Pod에 사용할 Storage는 오직 PVC(Persistent Volume Claim)통해서만 가능. Pod가 증가할 수록 Volume이 동적으로 붙어줘야 함. 미리 PV를 생성하거나 StorageClass를 이용해 동적으로 프로비전닝 작업 필요
2.4.3 Headless Service 필요: 특정 POd에 요청을 전달하기 위한 용도, noclusterip 사용
2.4.4. Node에 장애가 발생하더라도 Pod를 다른 Node로 이동시키지 않음, Volume에 탑재된 Data보호 우선
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 # .spec.template.metadata.labels 와 일치해야 한다 serviceName: "nginx" replicas: 3 # 기본값은 1 minReadySeconds: 10 # 기본값은 0 template: metadata: labels: app: nginx # .spec.selector.matchLabels 와 일치해야 한다 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: "my-storage-class" resources: requests: storage: 1Gi
728x90'공부합시다! > Kubernetes' 카테고리의 다른 글
Kubernetes(K8S): kubeclt cp 와 tar 다중 파일 복사 (0) 2023.01.07 Kubernetes(K8S): Helm + Prometheus + Grafana (0) 2023.01.06 Kubernetes(K8S): Job & CronJob (0) 2023.01.03 Kubernetes(K8S): Multi Container POD (0) 2023.01.02 Kubernetes (K8S): Object - 2. POD (0) 2022.12.30