Back to 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.

View on GitHub

Policy Definition

apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: deployment-has-multiple-replicas
annotations:
policies.kyverno.io/title: Require Multiple Replicas in CEL expressions
policies.kyverno.io/category: Sample in CEL
policies.kyverno.io/severity: medium
policies.kyverno.io/subject: Deployment
policies.kyverno.io/minversion: 1.11.0
kyverno.io/kubernetes-version: 1.26-1.27
policies.kyverno.io/description: 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.
spec:
validationFailureAction: Audit
background: true
rules:
- name: deployment-has-multiple-replicas
match:
any:
- resources:
kinds:
- Deployment
operations:
- CREATE
- UPDATE
validate:
cel:
expressions:
- expression: object.spec.replicas > 1
message: Deployments should have more than one replica to ensure availability.

Related Policies