-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathnode-affinity.yaml
54 lines (54 loc) · 1.57 KB
/
node-affinity.yaml
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# 1. Add the label role=web to one of the nodes
#
# kubectl label nodes <node-name> role=web
#
# 2. Deploy this manifest and check which nodes the pods are deployed.
#
# kubectl create -f node-affinity.yaml
#
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-node-affinity
labels:
run: nginx-node-affinity
spec:
replicas: 2
selector:
matchLabels:
run: nginx-node-affinity
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
template:
metadata:
labels:
run: nginx-node-affinity
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
#You can have multiple nodeSelectorTerms. The pod will be scheduled to a
#node if one of the nodeSelectorTerms are satisfied.
nodeSelectorTerms:
#you can have multiple matchExpressions
#The pod will be scheduled to a node only if ALL matchExpressions can be satisfied.
- matchExpressions:
- key: role
operator: In #valid values are: In, NotIn, Exists, DoesNotExist, Gt, Lt
values:
- web
#The node that is most preferred is the one with the greatest sum of weights
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 1
preference:
matchExpressions:
- key: role
operator: In
values:
- web
containers:
- name: nginx-node-affinity
image: nginx