All Policies
Require Multiple Replicas in CEL expressions
Deployments with a single replica cannot be highly available and thus the application may suffer downtime if that one replica goes down. This policy validates that Deployments have more than one replica.
Policy Definition
1apiVersion: kyverno.io/v1
2kind: ClusterPolicy
3metadata:
4 name: deployment-has-multiple-replicas
5 annotations:
6 policies.kyverno.io/title: Require Multiple Replicas in CEL expressions
7 policies.kyverno.io/category: Sample in CEL
8 policies.kyverno.io/severity: medium
9 policies.kyverno.io/subject: Deployment
10 policies.kyverno.io/minversion: 1.11.0
11 kyverno.io/kubernetes-version: "1.26-1.27"
12 policies.kyverno.io/description: >-
13 Deployments with a single replica cannot be highly available and thus the application
14 may suffer downtime if that one replica goes down. This policy validates that Deployments
15 have more than one replica.
16spec:
17 validationFailureAction: Audit
18 background: true
19 rules:
20 - name: deployment-has-multiple-replicas
21 match:
22 any:
23 - resources:
24 kinds:
25 - Deployment
26 operations:
27 - CREATE
28 - UPDATE
29 validate:
30 cel:
31 expressions:
32 - expression: "object.spec.replicas > 1"
33 message: "Deployments should have more than one replica to ensure availability."