티스토리 뷰

쿠버네티스

CKA 기출 문제 데몬셋

jws199 2025. 1. 1. 21:32

1. 문제#1 

1) 문제시나리오

(1) 데몬셋 생성 

- 클러스터의 모든 노드에서 실행되는 데몬셋을 생성 

- 각 노드에서 로그 수집 에이전트(busybox)를 실행하도록 구성

- 로그 수집 에이전트는 /var/log 디렉토리의 파일 목록을 10초마다 출력

(2) 특정 노드 제외

- 데몬셋이 특정 조건(노드 레이블)을 만족하지 않는 노드에서는 실행되지 않도록 설정 

- exclude=true 레이블을 가진 노드는 DaemonSet의 대상에서 제외

2) 해결 과정 

(1) 특정 노드에 레이블 추가 

- 클러스터의 모든 노드 확인 

kubectl get nodes

NAME       STATUS   ROLES    AGE     VERSION
node-a     Ready    <none>   5d      v1.28.0
node-b     Ready    <none>   5d      v1.28.0
node-c     Ready    <none>   5d      v1.28.0

- 특정 노드에 레이블 추가

kubectl label nodes node-c exclude=true

 

- 노드 레이블 확인

kubectl get nodes --show-labels

NAME       STATUS   ROLES    AGE     VERSION   LABELS
node-a     Ready    <none>   5d      v1.28.0   ...
node-b     Ready    <none>   5d      v1.28.0   ...
node-c     Ready    <none>   5d      v1.28.0   ...,exclude=true

(2) YAML 작성

apiVersion: apps/v1
kind: DaemonSet
metadata:
 name: log-collector
spec:
 selector:
  matchLabels:
   app: log-collector # DaemonSet의 Pod를 식별하는 레이블 
 template:
  metadata:
   labels:
   	app:log-collector # Pod에 적용될 레이블 
  spec: 
   tolerations: #모든 노드에서 실행되도록 기본 toleration 설정(마스터 노드 포함)
   - key: "node-role.kubernetes.io/master"
     operator: "Exists"
     effect: "NoSchedule"
   affinity: # exclude=true 레이블을 가진 노드를 제외하는 Affinity
    nodeAffinity:
     requiredDuringSchedulingIgnoredDuringExecution:
      nodeSelectorTerms:
      - matchExpressions:
        - key: exclude #esclude=true레이블을 가진 노드는 제외
          operator: NotIn
          values:
          - "true"
  containers:
  - name: log-collector
    image: busybox
    command;
    - sh
    args:
    - -c
    - "while true; do ls /var/log; sleep 10; done" #/var/log 디렉토리 파일 목록 출력 후 대기 
    volumeMounts:
    - name: varlog
      mountPath: /var/log
  volumes:
  - name: varlog
    hostPath:
     path: /var/log
     type: DirectoryOrCreate

(3) DaemonSet 생성 

kubectl apply -f daemonset.yaml

(4) DaemonSet 상태 확인 

kubectl get daemonsets log-collector

NAME             DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR   AGE
log-collector    2         2         2       2            2           <none>          30s

kubectl get pods --selector=app=log-collector --output=wide

NAME                   READY   STATUS    NODE     AGE
log-collector-node-a   1/1     Running   node-a   30s
log-collector-node-b   1/1     Running   node-b   30s
# node-c에 배치되지 않음
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
글 보관함