데몬셋
- Replication Controller와 ReplicaSet은 무작위 노드에 포드를 생성
- 데몬셋은 각 노드마다 하나의 포드를 생성
- 대표적으로 kube-proxy가 데몬셋으로 구성됨
imkunyoung@cloudshell:~ (kubernetes-397511)$ kubectl get ds -A
NAMESPACE NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
gmp-system collector 3 3 3 3 3 <none> 12d
kube-system fluentbit-gke 3 3 3 3 3 kubernetes.io/os=linux 12d
kube-system fluentbit-gke-256pd 0 0 0 0 0 kubernetes.io/os=linux 12d
kube-system fluentbit-gke-max 0 0 0 0 0 kubernetes.io/os=linux 12d
kube-system gke-metrics-agent 3 3 3 3 3 <none> 12d
kube-system gke-metrics-agent-scaling-10 0 0 0 0 0 <none> 12d
kube-system gke-metrics-agent-scaling-100 0 0 0 0 0 <none> 12d
kube-system gke-metrics-agent-scaling-20 0 0 0 0 0 <none> 12d
kube-system gke-metrics-agent-scaling-200 0 0 0 0 0 <none> 12d
kube-system gke-metrics-agent-scaling-50 0 0 0 0 0 <none> 12d
kube-system gke-metrics-agent-scaling-500 0 0 0 0 0 <none> 12d
kube-system gke-metrics-agent-windows 0 0 0 0 0 kubernetes.io/os=windows 12d
kube-system kube-proxy 0 0 0 0 0 kubernetes.io/os=linux,node.kubernetes.io/kube-proxy-ds-ready=true 12d
kube-system metadata-proxy-v0.1 0 0 0 0 0 cloud.google.com/metadata-proxy-ready=true,kubernetes.io/os=linux 12d
kube-system nccl-fastsocket-installer 0 0 0 0 0 <none> 12d
kube-system nvidia-gpu-device-plugin-large-cos 0 0 0 0 0 <none> 12d
kube-system nvidia-gpu-device-plugin-large-ubuntu 0 0 0 0 0 <none> 12d
kube-system nvidia-gpu-device-plugin-medium-cos 0 0 0 0 0 <none> 12d
kube-system nvidia-gpu-device-plugin-medium-ubuntu 0 0 0 0 0 <none> 12d
kube-system nvidia-gpu-device-plugin-small-cos 0 0 0 0 0 <none> 12d
kube-system nvidia-gpu-device-plugin-small-ubuntu 0 0 0 0 0 <none> 12d
kube-system pdcsi-node 3 3 3 3 3 kubernetes.io/os=linux 12d
kube-system pdcsi-node-windows 0 0 0 0 0 kubernetes.io/os=windows 12d
kube-system runsc-metric-server 0 0 0 0 0 kubernetes.io/os=linux,sandbox.gke.io/runtime=gvisor 12d
kube-system tpu-device-plugin 0 0 0 0 0 <none> 12d
데몬셋 예제
- 사용 예시로, 로그를 수집할 때 사용할 수 있음 (파드에서 hostPath로 로그를 마운트 시키고 fluentd 등으로 elasticsearch에 보내주는 형태로..)
kubectl apply -f https://raw.githubusercontent.com/kubernetes/website/main/content/en/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:
- 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
연습문제
- 데몬셋으로 각 노드에 http-go 배치하기
- 이미지: gasbugs/http-go
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: http-go
namespace: default
labels:
k8s-app: http-go
spec:
selector:
matchLabels:
name: http-go
template:
metadata:
labels:
name: http-go
spec:
containers:
- name: http-go
image: gasbugs/http-go
imkunyoung@cloudshell:~ (kubernetes-397511)$ kubectl create -f http-go-daemonset.yaml
daemonset.apps/http-go created
imkunyoung@cloudshell:~ (kubernetes-397511)$ kubectl get ds
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
http-go 3 3 0 3 0 <none> 7s
imkunyoung@cloudshell:~ (kubernetes-397511)$ kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
http-go-4qxvt 1/1 Running 0 27s 10.40.0.170 gke-artbridge-default-pool-65403ed8-7zvx <none> <none>
http-go-qdt6p 1/1 Running 0 26s 10.40.2.21 gke-artbridge-default-pool-65403ed8-tdzz <none> <none>
http-go-w2vgq 1/1 Running 0 26s 10.40.1.17 gke-artbridge-default-pool-65403ed8-fz5f <none> <none>