All Policies
Add Node Affinity
Node affinity, similar to node selection, is a way to specify which node(s) on which Pods will be scheduled but based on more complex conditions. This policy will add node affinity to a Deployment and if one already exists an expression will be added to it.
Policy Definition
/other/add-node-affinity/add-node-affinity.yaml
1apiVersion: kyverno.io/v1
2kind: ClusterPolicy
3metadata:
4 name: add-node-affinity
5 annotations:
6 policies.kyverno.io/title: Add Node Affinity
7 policies.kyverno.io/category: Other
8 policies.kyverno.io/severity: medium
9 policies.kyverno.io/subject: Deployment
10 kyverno.io/kyverno-version: 1.6.0
11 kyverno.io/kubernetes-version: "1.21"
12 policies.kyverno.io/description: >-
13 Node affinity, similar to node selection, is a way to specify which node(s) on which Pods will be scheduled
14 but based on more complex conditions. This policy will add node affinity to a Deployment and if one already
15 exists an expression will be added to it.
16spec:
17 background: false
18 rules:
19 - name: add-node-affinity-deployment
20 match:
21 any:
22 - resources:
23 kinds:
24 - Deployment
25 mutate:
26 patchesJson6902: |-
27 - path: "/spec/template/spec/affinity/nodeAffinity/requiredDuringSchedulingIgnoredDuringExecution/nodeSelectorTerms/-1/matchExpressions/-1"
28 op: add
29 value:
30 key: zone_weight
31 operator: Lt
32 values:
33 - "400"