개발강의정리/DevOps

[데브옵스를 위한 쿠버네티스 마스터] 애플리케이션 스케줄링과 라이프사이클 관리 - 데몬셋

nineDeveloper 2021. 1. 19.
728x90

데몬셋, 노드당 포드 하나씩


데몬셋

  • 레플리케이션컨트롤러와 레플리카셋은 무작위 노드에 포드를 생성
  • 데몬셋은 각 하나의 노드에 하나의 포드만을 구성
  • kube-proxy가 데몬셋으로 만든 쿠버네티스에서 기본적으로 활동중인 포드


데몬셋 예제

https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/#writing-a-daemonset-spec

  • kubectl apply -f https://k8s.io/examples/controllers/daemonset.yaml
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:
      # this toleration is to have the daemonset runnable on master nodes
      # remove it if your masters can't run pods
      - key: node-role.kubernetes.io/master
        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

연습문제

  • 데몬셋으로 각 노드에 http-go 배치하기
  • 이미지: gasbugs/http-go

http-go-ds.yaml

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: http-go
spec:
  selector:
    matchLabels:
      app: http-go
  template:
    metadata:
      labels:
        app: http-go
    spec:
      tolerations:
      - key: node-role.kubernetes.io/master
        effect: NoSchedule
      containers:
      - name: http-go
        image: gasbugs/http-go

kubectl로 생성 및 확인

$ kubectl create -f http-go-ds.yaml
daemonset.apps/http-go created

$ kubectl get pod
NAME            READY   STATUS    RESTARTS   AGE
http-go-4s9rl   1/1     Running   0          46s
http-go-ghr59   1/1     Running   0          46s
http-go-hplqm   1/1     Running   0          46s

$ kubectl get ds
NAME      DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR   AGE
http-go   3         3         3       3            3           <none>          72s

노드마다 1개씩 가지는 것을 확인

$ kubectl get pod -o wide
NAME            READY   STATUS    RESTARTS   AGE   IP          NODE     NOMINATED NODE   READINESS GATES
http-go-4s9rl   1/1     Running   0          85s   10.32.0.4   work1    <none>           <none>
http-go-ghr59   1/1     Running   0          85s   10.40.0.1   master   <none>           <none>
http-go-hplqm   1/1     Running   0          85s   10.46.0.2   work2    <none>           <none>
728x90

댓글

💲 추천 글