-
틀린 문제 # Node Affinitykubernetes/CKA 2025. 12. 4. 14:00
문제1
Set Node Affinity to the blue deployment to place the pods on node01 only.
Ensure that node01 has the label color=blue.
Requirements:
- Use requiredDuringSchedulingIgnoredDuringExecution node affinity
- Key: color
- Value: blue
If the label is not already set, apply it to node01 before updating the deployment.
✅ 1. node01에 color=blue 라벨 적용
kubectl label node node01 color=blue --overwritekubectl get node node01 --show-labels→ color=blue 가 보이면 정상
✅ 2. blue Deployment에 Node Affinity 설정 추가
affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: color operator: In values: - blue완성본
apiVersion: apps/v1 kind: Deployment metadata: annotations: deployment.kubernetes.io/revision: "2" creationTimestamp: "2025-12-04T04:34:20Z" generation: 2 labels: app: blue name: blue namespace: default resourceVersion: "4160" uid: c832f99c-0adc-4770-b684-db63eae9653d spec: progressDeadlineSeconds: 600 replicas: 3 revisionHistoryLimit: 10 selector: matchLabels: app: blue strategy: rollingUpdate: maxSurge: 25% maxUnavailable: 25% type: RollingUpdate template: metadata: labels: app: blue spec: affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: color operator: In values: - blue containers: - image: nginx imagePullPolicy: Always name: nginx resources: {} terminationMessagePath: /dev/termination-log terminationMessagePolicy: File dnsPolicy: ClusterFirst restartPolicy: Always schedulerName: default-scheduler securityContext: {} terminationGracePeriodSeconds: 30 status: availableReplicas: 3 conditions: - lastTransitionTime: "2025-12-04T04:34:27Z" lastUpdateTime: "2025-12-04T04:34:27Z" message: Deployment has minimum availability. reason: MinimumReplicasAvailable status: "True" type: Available - lastTransitionTime: "2025-12-04T04:34:20Z" lastUpdateTime: "2025-12-04T04:51:59Z" message: ReplicaSet "blue-56f4cbb9f6" has successfully progressed. reason: NewReplicaSetAvailable status: "True" type: Progressing observedGeneration: 2 readyReplicas: 3 replicas: 3 updatedReplicas: 3문제 2
Create a new deployment named red with the nginx image and 2 replicas, and ensure it gets placed on the controlplane node only.
Use the label key - node-role.kubernetes.io/control-plane - which is already set on the controlplane node.
Name: red Replicas: 2 Image: nginx NodeAffinity: requiredDuringSchedulingIgnoredDuringExecution Key: node-role.kubernetes.io/control-plane Use the right operator
✅ 요구사항 정리
- Deployment 이름: red
- replica: 2
- 이미지: nginx
- 스케줄링 위치: controlplane 노드 ONLY
- 이미 controlplane 노드에는 다음 라벨이 있음:
node-role.kubernetes.io/control-plane=""
- NodeAffinity는 requiredDuringSchedulingIgnoredDuringExecution
- key는 node-role.kubernetes.io/control-plane
- value가 없으므로 operator는 Exists 사용해야 함
kubectl create deployment red --image=nginx --replicas=2kubectl edit deployment redapiVersion: apps/v1 kind: Deployment metadata: annotations: deployment.kubernetes.io/revision: "2" creationTimestamp: "2025-12-04T05:04:52Z" generation: 2 labels: app: red name: red namespace: default resourceVersion: "5637" uid: a36e8449-bc6c-4ecd-9f30-0abfa84f4c8d spec: progressDeadlineSeconds: 600 replicas: 2 revisionHistoryLimit: 10 selector: matchLabels: app: red strategy: rollingUpdate: maxSurge: 25% maxUnavailable: 25% type: RollingUpdate template: metadata: labels: app: red spec: affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - key: node-role.kubernetes.io/control-plane operator: Exists containers: - image: nginx imagePullPolicy: Always name: nginx resources: {} terminationMessagePath: /dev/termination-log terminationMessagePolicy: File dnsPolicy: ClusterFirst restartPolicy: Always schedulerName: default-scheduler securityContext: {} terminationGracePeriodSeconds: 30 status: availableReplicas: 2 conditions: - lastTransitionTime: "2025-12-04T05:04:54Z" lastUpdateTime: "2025-12-04T05:04:54Z" message: Deployment has minimum availability. reason: MinimumReplicasAvailable status: "True" type: Available - lastTransitionTime: "2025-12-04T05:04:52Z" lastUpdateTime: "2025-12-04T05:08:27Z" message: ReplicaSet "red-5557c78dc8" has successfully progressed. reason: NewReplicaSetAvailable status: "True" type: Progressing observedGeneration: 2 readyReplicas: 2 replicas: 2 updatedReplicas: 2'kubernetes > CKA' 카테고리의 다른 글
Priority Classes (0) 2025.12.05 틀린 문제 #4 Static Pod (0) 2025.12.05 Static pod (0) 2025.12.05 틀린 문제 # DaemonSet (0) 2025.12.05 Taints/Tolerations와 Node Affinity의 차이 (0) 2025.12.04