Container & Orchestration/Kubenetes
[Practice Test] Node Affinity
YongE
2025. 5. 7. 13:47
1
How many labels on node node01
?
kubectl describe node node01
2
What is the value set to the label key beta.kubernetes.io/arch on node01?
kubectl describe node node01 | grep beta.kubernetes.io/arch
3
Apply a label color=blue to node node01.
kubectl label node node01 color=blue
node/node01 labeled
4
Create a new deployment named blue with the nginx image and 3 replicas.
kubectl 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!
kubectl describe node node01 | grep Taints
kubectl describe node controlplane | grep Taints
6
Set Node Affinity to the deployment to place the pods on node01 only.
kubectl edit deployment blue
# then, edit yaml file. if you command ':wq', eployment.apps/blue edited.
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: blue
name: blue
namespace: default
spec:
template:
metadata:
creationTimestamp: null
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
7
which nodes are the pods placed on?
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.
반응형