๐Ÿ‘บ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค DaemonSet

๊น€์„ฑ์ธยท2023๋…„ 10์›” 19์ผ
0

[DevOps] ๐ŸณDocker & Kubernetes

๋ชฉ๋ก ๋ณด๊ธฐ
38/62

https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/

๋ฐ๋ชฌ์…‹์€ ๋ชจ๋“ (๋˜๋Š” ์ผ๋ถ€) ๋…ธ๋“œ๊ฐ€ ํŒŒ๋“œ์˜ ์‚ฌ๋ณธ์„ ์‹คํ–‰ํ•˜๋„๋ก ํ•œ๋‹ค. ๋…ธ๋“œ๊ฐ€ ํด๋Ÿฌ์Šคํ„ฐ์— ์ถ”๊ฐ€๋˜๋ฉด ํŒŒ๋“œ๋„ ์ถ”๊ฐ€๋œ๋‹ค. ๋…ธ๋“œ๊ฐ€ ํด๋Ÿฌ์Šคํ„ฐ์—์„œ ์ œ๊ฑฐ๋˜๋ฉด ํ•ด๋‹น ํŒŒ๋“œ๋Š” ๊ฐ€๋น„์ง€(garbage)๋กœ ์ˆ˜์ง‘๋œ๋‹ค. ๋ฐ๋ชฌ์…‹์„ ์‚ญ์ œํ•˜๋ฉด ๋ฐ๋ชฌ์…‹์ด ์ƒ์„ฑํ•œ ํŒŒ๋“œ๋“ค์ด ์ •๋ฆฌ๋œ๋‹ค.

  • ๋ชจ๋“  ๋…ธ๋“œ์—์„œ ํด๋Ÿฌ์Šคํ„ฐ ์Šคํ† ๋ฆฌ์ง€ ๋ฐ๋ชฌ ์‹คํ–‰
  • ๋ชจ๋“  ๋…ธ๋“œ์—์„œ ๋กœ๊ทธ ์ˆ˜์ง‘ ๋ฐ๋ชฌ ์‹คํ–‰
  • ๋ชจ๋“  ๋…ธ๋“œ์—์„œ ๋…ธ๋“œ ๋ชจ๋‹ˆํ„ฐ๋ง ๋ฐ๋ชฌ ์‹คํ–‰

๋…ธ๋“œ๋‹น ํฌ๋“œ๋ฅผ ํ•˜๋‚˜์”ฉ๋งŒ ๋ฐฐ์น˜ํ•จ -> ๋…ธ๋“œ ๊ด€๋ฆฌํ˜•์œผ๋กœ ์‚ฌ์šฉ๋˜๊ธฐ๋„ ํ•จ.

  • ๋ ˆํ”Œ๋ฆฌ์นด์…‹ ์ฒ˜๋Ÿผ ๊ฐœ์ˆ˜๋ฅผ ์ง€์ •ํ•ด์ฃผ์ง€ ์•Š์•„๋„ ๋จ.
  • kube-proxy, fluentd ๋“ฑ์— ์‚ฌ์šฉ
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: # ๋งˆ์Šคํ„ฐ ๋…ธ๋“œ์—์„œ๋„ ์‹คํ–‰ ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•˜๋Š” ์˜ต์…˜
      # these tolerations are to have the daemonset runnable on control plane nodes
      # remove them if your control plane nodes should not run pods
      - 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
      terminationGracePeriodSeconds: 30
      volumes:
      - name: varlog
        hostPath:
          path: /var/log

ํ™•์ธ

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/control-plane
        operator: Exists
        effect: NoSchedule
      - key: node-role.kubernetes.io/master
        operator: Exists
        effect: NoSchedule
      containers:
      - name: http-go
        image: gasbugs/http-go


Taints & Tolerations

ํ…Œ์ธํŠธ์™€ ํ†จ๋Ÿฌ๋ ˆ์ด์…˜

https://kubernetes.io/ko/docs/concepts/scheduling-eviction/taint-and-toleration/

Taint ์„ค์ • ์‹œ Toleration์ด ์ผ์น˜ํ•ด์•ผ ๋…ธ๋“œ์— ํŒŒ๋“œ๊ฐ€ ์‹คํ–‰๋  ์ˆ˜ ์žˆ๋‹ค.
Taint๊ฐ€ ์„ค์ •๋˜์–ด์žˆ์ง€ ์•Š์œผ๋ฉด ๊ทธ๋ƒฅ ์‹คํ–‰๋จ
Taint ์„ค์ • ๋˜์–ด์žˆ๋Š”๋ฐ Toleration์ด ์ผ์น˜ํ•˜์ง€ ์•Š์œผ๋ฉด ํŒŒ๋“œ๊ฐ€ ์‹คํ–‰ ๋ถˆ๊ฐ€๋Šฅํ•จ.

Taints

  • ๋…ธ๋“œ๊ฐ€ ํŒŒ๋“œ ์…‹์„ ์ œ์™ธ์‹œํ‚ฌ ์ˆ˜ ์žˆ๋‹ค.

Tolerations

  • ํ†จ๋Ÿฌ๋ ˆ์ด์…˜์€ ํŒŒ๋“œ์— ์ ์šฉ๋œ๋‹ค. ํ†จ๋Ÿฌ๋ ˆ์ด์…˜์„ ํ†ตํ•ด ์Šค์ผ€์ค„๋Ÿฌ๋Š” ๊ทธ์™€ ์ผ์น˜ํ•˜๋Š” ํ…Œ์ธํŠธ๊ฐ€ ์žˆ๋Š” ํŒŒ๋“œ๋ฅผ ์Šค์ผ€์ค„ํ•  ์ˆ˜ ์žˆ๋‹ค.
  • ํ†จ๋Ÿฌ๋ ˆ์ด์…˜์€ ์Šค์ผ€์ค„์„ ํ—ˆ์šฉํ•˜์ง€๋งŒ ๋ณด์žฅํ•˜์ง€๋Š” ์•Š๋Š”๋‹ค. ์Šค์ผ€์ค„๋Ÿฌ๋Š” ๊ทธ ๊ธฐ๋Šฅ์˜ ์ผ๋ถ€๋กœ์„œ ๋‹ค๋ฅธ ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ๊ณ ๋ คํ•œ๋‹ค.

ํ…Œ์ธํŠธ์™€ ํ†จ๋Ÿฌ๋ ˆ์ด์…˜์€ ํ•จ๊ป˜ ์ž‘๋™ํ•˜์—ฌ ํŒŒ๋“œ๊ฐ€ ๋ถ€์ ์ ˆํ•œ ๋…ธ๋“œ์— ์Šค์ผ€์ค„๋˜์ง€ ์•Š๊ฒŒ ํ•œ๋‹ค. ํ•˜๋‚˜ ์ด์ƒ์˜ ํ…Œ์ธํŠธ๊ฐ€ ๋…ธ๋“œ์— ์ ์šฉ๋˜๋Š”๋ฐ, ์ด๊ฒƒ์€ ๋…ธ๋“œ๊ฐ€ ํ…Œ์ธํŠธ๋ฅผ ์šฉ์ธํ•˜์ง€ ์•Š๋Š” ํŒŒ๋“œ๋ฅผ ์ˆ˜์šฉํ•ด์„œ๋Š” ์•ˆ ๋œ๋‹ค๋Š” ๊ฒƒ์„ ๋‚˜ํƒ€๋‚ธ๋‹ค

ํ™œ์šฉ

kubectl taint nodes node1 key1=value1:NoSchedule : ๋…ธ๋“œ์— ํ…Œ์ธํŠธ ์ถ”๊ฐ€

  • ํ…Œ์ธํŠธ์—๋Š” ํ‚ค key1, ๊ฐ’ value1 ๋ฐ ํ…Œ์ธํŠธ ์ดํŽ™ํŠธ(effect) NoSchedule ์ด ์žˆ๋‹ค. ์ด๋Š” ์ผ์น˜ํ•˜๋Š” ํ†จ๋Ÿฌ๋ ˆ์ด์…˜์ด ์—†์œผ๋ฉด ํŒŒ๋“œ๋ฅผ node1 ์— ์Šค์ผ€์ค„ํ•  ์ˆ˜ ์—†์Œ์„ ์˜๋ฏธํ•œ๋‹ค.

kubectl taint nodes node1 key1=value1:NoSchedule- : ๋…ธ๋“œ์— ํ…Œ์ธํŠธ ์ œ๊ฑฐ

PodSpec์— Toleration ์ ์šฉ

tolerations:
- key: "key1"
  operator: "Equal"
  value: "value1"
  effect: "NoSchedule"
# kubectl taint nodes node1 key1=value1:NoSchedule ํ•ด๋‹น Taint์™€ ์ผ์น˜
apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
    env: test
spec:
  containers:
  - name: nginx
    image: nginx
    imagePullPolicy: IfNotPresent
  tolerations:
  - key: "example-key"
    operator: "Exists"
    effect: "NoSchedule"
  • operator: ๊ธฐ๋ณธ๊ฐ’ Equal
  • effect:
    • NoSchedule : ์Šค์ผ€์ค„๋ง X,
    • PreferNoSchedule: ํฌ๋“œ๋ฅผ ๋‹ค๋ฅธ๊ณณ์— ๋ฐฐ์น˜ํ•  ๋…ธ๋“œ๊ฐ€ ์—†์œผ๋ฉด ๋ณธ์ธ์ด ๊ณ„์† ์‹คํ–‰
    • NoExecute: ์‹คํ–‰ X (์ด๋ฏธ์‹คํ–‰์ค‘์ธ ํฌ๋“œ๋ฅผ ๋…ธ๋“œ์—์„œ ๋นผ๋ฒ„๋ฆผ)

Toleration, Taint ์ผ์น˜

  • Toleration๋Š” ํ‚ค์™€ ์ดํŽ™ํŠธ๊ฐ€ ๋™์ผํ•œ ๊ฒฝ์šฐ์— Taint์™€ ์ผ์น˜
    • operator๊ฐ€ Exists ์ธ ๊ฒฝ์šฐ(์ด ๊ฒฝ์šฐ value ๋ฅผ ์ง€์ •ํ•˜์ง€ ์•Š์•„์•ผ ํ•จ)
    • operator๋Š” Equal ์ด๊ณ  value๊ฐ€ ๊ฐ™์€ ๊ฒฝ์šฐ
    • operator์— Exists์ด๊ณ  ์žˆ๋Š” key๊ฐ€ ๋น„์–ด์žˆ์„ ๊ฒฝ์šฐ: ๋ชจ๋“  ํ‚ค, ๊ฐ’ ๋ฐ ์ดํŽ™ํŠธ์™€ ์ผ์น˜ํ•˜๋ฏ€๋กœ ๋ชจ๋“  ๊ฒƒ์ด ํ†จ๋Ÿฌ๋ ˆ์ด์…˜ ๋œ๋‹ค.
    • effect๊ฐ€ ๋น„์–ด์žˆ๋Š” ๊ฒฝ์šฐ: ๋ชจ๋“  ์ดํŽ™ํŠธ๋ฅผ ํ‚ค key1์™€ ์ผ์น˜์‹œํ‚จ๋‹ค.

Taint ์กฐํšŒ

kubectl get nodes -o json | jq '.items[].spec.taints'

์‚ฌ์šฉ ํ™•์ธ

profile
๊ฐœ๋ฐœ์ž๊ฐ€ ๊ฟˆ์ธ 25์‚ด ๋Œ€ํ•™์ƒ์ž…๋‹ˆ๋‹ค.

0๊ฐœ์˜ ๋Œ“๊ธ€