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.5.1
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 resources:
22 kinds:
23 - Deployment
24 mutate:
25 patchesJson6902: |-
26 - path: "/spec/template/spec/affinity/nodeAffinity/requiredDuringSchedulingIgnoredDuringExecution/nodeSelectorTerms/-1/matchExpressions/-1"
27 op: add
28 value: {"key":"zone_weight","operator":"Lt","values":["400"]}