Node Affinity란?
파드를 특정 노드나 노드 그룹에 스케줄링하는 방법을 제공합니다.
이는 스케줄링 제약 조건을 정의하는 데 사용되며, Node Affinity는 nodeSelector, requiredDuringSchedulingIgnoredDuringExecution, 및 preferredDuringSchedulingIgnoredDuringExecution과 같은 다양한 방법을 통해 설정할 수 있습니다.
1. How many Labels exist on node node01?
$ controlplane ~ ✖ k describe nodes node01
Name: node01
Roles: <none>
Labels: beta.kubernetes.io/arch=amd64
beta.kubernetes.io/os=linux
kubernetes.io/arch=amd64
kubernetes.io/hostname=node01
kubernetes.io/os=linux
Annotations: flannel.alpha.coreos.com/backend-data: {"VNI":1,"VtepMAC":"2e:55:e7:36:8e:8a"}
flannel.alpha.coreos.com/backend-type: vxlan
flannel.alpha.coreos.com/kube-subnet-manager: true
flannel.alpha.coreos.com/public-ip: 192.24.223.3
kubeadm.alpha.kubernetes.io/cri-socket: unix:///var/run/containerd/containerd.sock
node.alpha.kubernetes.io/ttl: 0
volumes.kubernetes.io/controller-managed-attach-detach: true
answer : 5
2. What is the value set to the label key beta.kubernetes.io/arch on node01?
answer : amd64
3. Apply a label color=blue to node node01
$ controlplane ~ ➜ k label node node01 color=blue
node/node01 labeled
4. Create a new deployment named blue with the nginx image and 3 replicas.
$ controlplane ~ ➜ k create deployment blue --image nginx --replicas=3
deployment.apps/blue created
5. Which nodes can the pods for the blue deployment be placed on?
Make sure to check taints on both nodes!
$ controlplane ~ ➜ k get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
blue-747bd9c977-6gqdm 1/1 Running 0 43s 10.244.0.4 controlplane <none> <none>
blue-747bd9c977-jhfwz 1/1 Running 0 43s 10.244.1.2 node01 <none> <none>
blue-747bd9c977-p6gsx 1/1 Running 0 43s 10.244.1.3 node01 <none> <none>
answer : controlplane and node01
6. Set Node Affinity to the deployment to place the pods on node01 only.
https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#node-affinity
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: blue
name: blue
spec:
replicas: 3
selector:
matchLabels:
app: blue
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: blue
spec:
containers:
- image: nginx
name: nginx
resources: {}
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: color
operator: In
values:
- blue
7. Which nodes are the pods placed on now?
$ controlplane ~ ➜ k get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
blue-8b4fdbcb5-64f5g 1/1 Running 0 104s 10.244.1.5 node01 <none> <none>
blue-8b4fdbcb5-lxx5k 1/1 Running 0 102s 10.244.1.6 node01 <none> <none>
blue-8b4fdbcb5-pvzph 1/1 Running 0 106s 10.244.1.4 node01 <none> <none>
answer : node01
8. 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.
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: red
name: red
spec:
replicas: 2
selector:
matchLabels:
app: red
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: red
spec:
containers:
- image: nginx
name: nginx
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: node-role.kubernetes.io/control-plane
operator: Exists
status: {}
'IT 기술 > k8s' 카테고리의 다른 글
[cka] Multiple Schedulers (0) | 2024.06.23 |
---|---|
[cka] Resource Limits (0) | 2024.06.22 |
[cka] Taints and Tolerations (0) | 2024.06.08 |
[cka] Labels and Selectors (0) | 2024.06.08 |
[cka] Manual Scheduling (0) | 2024.06.08 |
댓글