Node Affinity
Provides us with capabilities to limit pod placement on specific nodes.
1apiVersion:
2kind: Pod
3metadata:
4 name: simple-webapp-color
5spec:
6 nodeSelector:
7 size: Large
8
9 containers:
10 - name: simple-webapp-color
11 image: simple-webapp-color
12 ports:
13 - containerPort: 8080
1
2apiVersion:
3kind: Pod
4metadata:
5 name: simple-webapp-color
6spec:
7 affinity:
8 nodeAffinity:
9 requiredDuringSchedulingIgnoredDuringExecution:
10 nodeSelectorTerms:
11 - matchExpressions:
12 - key: size
13 operator: In
14 values:
15 - Large
16 - Medium
17
18
19 containers:
20 - name: simple-webapp-color
21 image: simple-webapp-color
22 ports:
23 - containerPort: 8080
Affinity
1spec:
2 affinity:
3 nodeAffinity:
4 requiredDuringSchedulingIgnoredDuringExecution:
5 nodeSelectorTerms:
6 - matchExpressions:
7 - key: size
8 operator: In
9 values:
10 - Large
11 - Medium
12 - key: environment
13 operator: In
14 values:
15 - test-1
16 - prod-1
Match Expressions
1- matchExpressions:
2 - key: size
3 operator: In
4 values:
5 - Large
6 - Medium
7
8 - key: color
9 operator: Exists
Node Affinity
requiredDuringSchedulingIgnoredDuringExecution
prefferedDuringSchedulingIgnoredDuringExecution
requiredDuringSchedulingRequiredDuringExecution
required - If label not found, do not schedule
Preffered - If label not found, place anywhere
Ignored - Any changes in node affinity will not affect them
During Scheduling | During Execution | |
---|---|---|
Type 1 | Required | Ignored |
Type 2 | Preffered | Ignored |
Type 3 | Required | Required |
If post deplyment a label changes, RequiredDuringExecution will kill any existing pods that do not match the labels