
CKA Scheduling 섹션 퀴즈 Q1, Q2를 kind 클러스터에서 직접 실습했다. Q1은 DaemonSet을 monitoring 네임스페이스에 배포하면서 control-plane 노드도 포함시키는 문제였고, Q2는 Taint와 Node Affinity를 조합해서 Deployment를 특정 노드에만 배포하는 문제였다. 두 문제 모두 YAML을 dry-run으로 뽑아서 직접 편집하는 방식으로 풀었고, DaemonSet에서 apiVersion 실수가 있었는데 kubectl explain으로 빠르게 확인하는 방법도 알게 됐다.
클러스터 구성 확인
kind 클러스터는 control-plane 1개 + worker 2개로 구성되어 있다.
kubectl get nodes
NAME STATUS ROLES AGE VERSION
kind-control-plane Ready control-plane 28s v1.35.0
kind-worker Ready <none> 14s v1.35.0
kind-worker2 Ready <none> 14s v1.35.0
네임스페이스 생성
kubectl create ns monitoring
YAML 기반 만들기
DaemonSet은 imperative 명령으로 바로 생성이 안 되서, Deployment dry-run으로 기본 구조를 뽑은 다음 편집했다.
kubectl create deploy log-collector --image=fluentd:latest --dry-run=client -n monitoring -o yaml
control-plane taint 확인
DaemonSet이 control-plane에도 배포되려면 toleration이 필요하다. taint 값을 확인했다.
kubectl describe nodes kind-control-plane
Taints: node-role.kubernetes.io/control-plane:NoSchedule
apiVersion 에러
YAML을 편집하면서 apiVersion: v1로 잘못 입력했다.
error: resource mapping not found for name: "log-collector" namespace: "monitoring"
from "./Desktop/code/kind/ds.yaml": no matches for kind "DaemonSet" in version "v1"
DaemonSet은 core API가 아니라 apps 그룹에 속해 있어서 v1만으로는 찾을 수 없다. kubectl explain ds로 정확한 그룹과 버전을 확인했다.
kubectl explain ds
GROUP: apps
KIND: DaemonSet
VERSION: v1
GROUP이 apps이므로 apiVersion은 apps/v1이다. 수정 후 재적용.
최종 DaemonSet YAML
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: log-collector
namespace: monitoring
spec:
selector:
matchLabels:
app: log-collector
template:
metadata:
labels:
app: log-collector
spec:
tolerations:
- key: node-role.kubernetes.io/control-plane
operator: Exists
effect: NoSchedule
containers:
- name: fluentd
image: fluentd:latest
배포 확인
kubectl get ds -n monitoring
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
log-collector 1 1 0 1 0 <none> 12s
kubectl get pods -n monitoring -o wide
NAME READY STATUS RESTARTS AGE IP NODE
log-collector-r7krv 1/1 Running 0 71s 10.244.0.5 kind-control-plane
처음에 toleration과 함께 Node Affinity도 추가했더니 DESIRED: 1이 됐다. Affinity를 control-plane 노드만 지정하도록 쓰면 오히려 그 노드에만 배포가 제한된다. "모든 노드에 배포하되 control-plane도 포함"이 목표라면 Affinity는 필요 없고 toleration만 있으면 된다.
노드 레이블 적용
kubectl label nodes kind-worker tier=backend
kubectl label nodes kind-worker2 tier=frontend
kind-worker2에 Taint 추가
kubectl taint node kind-worker2 env=prod:NoSchedule
kubectl describe nodes kind-worker2
Taints: env=prod:NoSchedule
YAML 기반 만들기
kubectl create deploy api --image=nginx -r 3 --dry-run=client -o yaml
Node Affinity와 Toleration을 추가해서 편집했다.
최종 Deployment YAML
apiVersion: apps/v1
kind: Deployment
metadata:
name: api
spec:
replicas: 3
selector:
matchLabels:
app: api
template:
metadata:
labels:
app: api
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: tier
operator: In
values:
- backend
tolerations:
- key: env
operator: Equal
value: prod
effect: NoSchedule
containers:
- image: nginx
name: nginx
배포 확인
kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE
api-59456d6fb7-7wf77 1/1 Running 0 76s 10.244.1.2 kind-worker
api-59456d6fb7-ksbkr 1/1 Running 0 76s 10.244.1.3 kind-worker
api-59456d6fb7-ptc2c 1/1 Running 0 76s 10.244.1.4 kind-worker
3개 pod 모두 kind-worker(tier=backend)에서만 실행됐다. kind-worker2는 taint가 있고 affinity 조건에도 맞지 않아 아무것도 배포되지 않았다.
| 구분 | Taint/Toleration | Node Affinity |
|---|---|---|
| 역할 | 노드가 toleration 없는 pod를 차단 | pod가 특정 노드를 선택 |
| 방향 | 노드 → pod (밀어냄) | pod → 노드 (선택) |
| 기본 동작 | taint 없으면 어디든 배포 | affinity 없으면 모든 노드 가능 |
| 함께 쓸 때 | "이 노드에만 배포 + taint된 노드도 허용" 조합 |
Q. Create a DaemonSet named log-collector with image fluentd:latest in namespace monitoring. It must run on all nodes including the control-plane.
→ apps/v1, toleration for node-role.kubernetes.io/control-plane:NoSchedule. Affinity 추가하면 오히려 범위가 제한됨.
Q. Deploy api (image: nginx, 3 replicas) so it only runs on nodes labeled tier=backend. Node kind-worker2 has taint env=prod:NoSchedule and label tier=frontend.
→ requiredDuringSchedulingIgnoredDuringExecution + tolerations[key: env, effect: NoSchedule] 조합