[k8s] daemonset
daemonset์ daemon ์์คํ
์ ๋์ฐ๋๋ฐ ์ต์ ํ๋ ํ๋ ์ปจํธ๋กค๋ฌ ๋จ์๋ค.
๋ฐ๋ชฌ์ด๋ ๊ทธ๋ฅ 365์ผ 24์๊ฐ ๋ฅ๋ฅ ๋ ์ ๋ฃจํ ๋๋ฉด์ ๊ณ์ ๋ญ๊ฐ๋ฅผ ์ฒ๋ฆฌํ๋ ํ๋ก๊ทธ๋จ์ ๋งํ๋ค.
๋ฐ๋ชฌ์ ๋ชฉ๋ก์ ์๋ ๋ช ๋ น์ด๋ก ์กฐํํ ์ ์๋ค.
kubectl get daemonsets --all-namespaces
๋คํธ์ํฌ ์ธํฐํ์ด์ค ๊ด๋ฆฌ ๋๊ตฌ calico์ ๋ด๋ถ ํ๋ก์๊ฐ ๋ฐ๋ชฌ์ผ๋ก ๋์๊ฐ๋ ๊ฒ์ ๋ณผ ์ ์๋ค.
์ด๊ฑธ ์ง๊ธ ๊ฑด๋ค ์ผ์ ์๊ณ , ํ๋ ๋ง๋ค์ด๋ณด๊ฒ ๋ค.
daemonset ๋ง๋ค์ด๋ณด๊ธฐ
๋ง์ฐฌ๊ฐ์ง๋ก yaml๋ก ๋ง์์ฃผ๋ฉด ๋๋ค.
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: test-daemon
namespace: kube-system
labels:
k8s-app: fluentd-logging
spec:
selector:
matchLabels:
name: test-daemon
template:
metadata:
labels:
name: test-daemon
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: test-daemon
image: myyrakle/node-daemon-for-test # ๋์ปค ์ด๋ฏธ์ง
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
์ฌ๊ธฐ์ myyrakle/node-daemon-for-test๋ ๋ด๊ฐ ๋ง์๋์ ์ด๋ฏธ์ง์ธ๋ฐ, ๊ทธ ๊ตฌ์ฑ์ด ๊ถ๊ธํ๋ค๋ฉด
https://github.com/myyrakle/infrastructures/tree/master/Dockerfiles/examples/node-daemon-for-test
์ฌ๊ธฐ์ ๋ณด๋ฉด ๋๋ค.
1์ด๋ง๋ค ์ฌ์คํ๋๋ฉด์ ํ์ฌ ๋ด๋ถ IP์ ์๊ฐ๋ง ์ฝ์๋ก ์ฐ์ด์ฃผ๋ ๊ธฐ๋ฅ์ ๊ฐ๊ณ ์๋ค.
์ ๊ฑธ ์์ฑํ๋ฉด

์ด์ ๋ฐ๋ชฌ ๋ชฉ๋ก์ ๋จ๊ฒ ๋๋ค.

ํ๋ ๋ก๊ทธ๋ฅผ ๋ฝ์๋ณด๋ฉด
์ ์์ ์ผ๋ก ์ฐํ๋ ๊ฒ์ ํ์ธํ ์ ์๋ค.
ํน์ daemonset์ผ๋ก ๋ฌถ์ธ ํ๋๋ฅผ ์ ์ฒด์กฐํํ๊ณ ์ถ๋ค๋ฉด, ๋ ์ด๋ธ๋ช ์ ํตํด ๋ณด๋๊ฒ ํธํ๋ค.
kubectl logs -l name=์ด๋ฆ ...
kubectl logs -l name=test-daemon --namespace=kube-system

๋กค๋ง ์ ๋ฐ์ดํธ๋ก ์ฌ๋ฐฐํฌํ๊ธฐ
๋ญ๊ฐ ์ฝ๋์ ๋ณ๊ฒฝ์ด ์๋ค๋ฉด ์ด๋ฏธ์ง๋ฅผ ๋ค์ ๋ฐ๊ณ ์ธ์คํด์ค๋ฅผ ์๋ก ๋์ฐ๋๊ฒ ์ผ๋ฐ์ ์ด๋ค.
๊ทธ ์์ ์ ํ๊ธฐ ์ํด์ updateStrategy๋ก ์ ๋ฐ์ดํธ ์ ๋ต์ ๋ช ์ํด์ฃผ๊ณ
updateStrategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
๋ฐฐํฌ๋ฅผ ๋์ธ๋๋ง๋ค ์ด๋ฏธ์ง๋ฅผ ์๋ก ๋ฐ์์ค๋๋ก ์๋ ์ต์ ์ ์ถ๊ฐํด์ค๋ค.
imagePullPolicy: Always
์๊ทธ๋ฌ๋ฉด ์ด๋ฏธ์ง ๋ฒ์ ์ :latest๋ก ๋ฐ๋๋ผ๋, ์ด์ ์ ๋ฐ์๋๊ฑธ ๊ณ์ ์ฌํํ๋ค.
๊ทธ๋์ yaml์ ์ด๋ ๊ฒ ๋ฐ๊ฟ์
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: test-daemon
namespace: kube-system
labels:
k8s-app: fluentd-logging
spec:
selector:
matchLabels:
name: test-daemon
updateStrategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
template:
metadata:
labels:
name: test-daemon
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: test-daemon
image: myyrakle/node-daemon-for-test
imagePullPolicy: Always
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
apply๋ฅผ ํ๋ค.

๊ทธ๋ฆฌ๊ณ rollout ๋ช ๋ น์ ์ฌ์ฉํด์ ์ฌ๋ฐฐํฌ ํธ๋ฆฌ๊ฑฐ๋ฅผ ๊ฑธ๋ฉด ๋๋ค.
kubectl rollout restart daemonset/test-daemon --namespace=kube-system

์ฌ๋ฐฐํฌ ์ํ๋ ์๋ ๋ช ๋ น์ผ๋ก ํ์ธํ ์ ์๋ค.
kubectl rollout status daemonset/test-daemon -n kube-system
์ด๋ ๊ฒ ์ฑ๊ณต์ด ๋จ๋ฉด ์ด์
๋ฐฐํฌํ๋๋ก ๋ฐ์์ด ์ ๋์์ ๊ฒ์ด๋ค.
์ด์ ๋ฒ์ ์๋ ๋ก๊ทธ์ ์คํ๊ฐ ๋ค์ด๊ฐ์ ")}"์ด ๋ถํธํ๊ฒ ๋ถ์์๋๋ฐ, ์ด์ ๋ ๋จ์ง ์๋๋ค.
daemonset ์ญ์
๋ค๋ฅธ ๋ฆฌ์์ค๋ค๊ณผ ๋งคํ๊ฐ์ง๋ก, delete daemonsets ๋ช ๋ น์ ์ฌ์ฉํ๋ฉด ๋ฐ๋ก ์ ๊ฑฐํ ์ ์๋ค.

์ฐธ์กฐ
https://kubernetes.io/ko/docs/concepts/workloads/controllers/daemonset/
https://kubernetes.io/ko/docs/reference/kubectl/cheatsheet/
https://stackoverflow.com/questions/33112789/how-do-i-force-kubernetes-to-re-pull-an-image