Kubernetes

[Kubernetes] daemonset 재기동, scale 0, shutdown 방법

정윤재 2023. 5. 17. 00:12

daemonset 이란 각 worker node 당 하나씩 pod 가 뜨는 방식의 k8s object 이다.

 

이 object 는 replica 같은 설정이 없으므로 delete 외에 잠깐 갯수를 0 으로 만들거나

shutdown 시키는게 불가능하다. 

그래도 daemonset 을 아예 삭제 하는게 힘든 상황일 경우 아래와 같이 생각해보자

 

1. daemonset 에 node 에 있지도 않은 label 의 nodeselector 를 patch 하자

    => 이렇게 되면 본인이 기동 될 곳이 없으므로 자연스럽게 갯수가 0으로 변한다.

 

2. 다시 기동이 필요할 때는 daemonset 에 해당 nodeseletor 를 삭제 해주자

 

위의 전략을 테스트 하기 위해 아래와 같은 fluentd 의 damonset 을 만들었다.

 

참고로 minikube 에서 해당 내용을 테스트 해보았다.

 

*  daemonset 생성

 

shell> kubectl apply -f fluentd.yaml

 

fluentd.yaml 파일

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: test-elasticsearch
  namespace: default
  labels:
    k8s-app: test-logging
spec:
  selector:
    matchLabels:
      name: test-elasticsearch
  updateStrategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        name: test-elasticsearch
    spec:
      containers:
      - name: container-elasticsearch
        image: quay.io/fluentd_elasticsearch/fluentd:v2.5.2
        resources:
          limits:
            memory: 200Mi
          requests:
            cpu: 100m
            memory: 200Mi
      terminationGracePeriodSeconds: 30

 

* nodeselector 추가

kubectl -n [namespace] patch daemonset [daemonset이름] -p '{"spec": {"template": {"spec": {"nodeSelector": {"non-existing": "true"}}}}}'

의 형식으로 생성

 

shell> kubectl -n default patch daemonset test-elasticsearch -p '{"spec": {"template": {"spec": {"nodeSelector": {"non-existing": "true"}}}}}'

 

 

* nodeselector 삭제

kubectl -n [namespace] patch daemonset [daemonset이름] --type json -p='[{"op": "remove", "path": "/spec/template/spec/nodeSelector/non-existing"}]'

의 형식으로 삭제

 

shell> kubectl -n default patch daemonset test-elasticsearch --type json -p='[{"op": "remove", "path": "/spec/template/spec/nodeSelector/non-existing"}]'

 

 

위의 내용을 확인 해 보면

 

전체 실행 화면
replica 가 0 이 되었다가 복구된 모습

위와 같다.

 

- 참고사이트

how to scale kubernetes daemonset to 0? - Stack Overflow