PodDisruptionBudget resources are useful to ensuring minimum availability is maintained at all times. This policy checks all incoming Deployments and StatefulSets to ensure they have a matching, preexisting PodDisruptionBudget. Note: This policy must be run in `enforce` mode to ensure accuracy.
apiVersion: kyverno.io/v1kind: ClusterPolicymetadata:name: require-pdbannotations:policies.kyverno.io/title: Require PodDisruptionBudgetpolicies.kyverno.io/category: Sample, EKS Best Practicespolicies.kyverno.io/minversion: 1.6.0kyverno.io/kyverno-version: 1.6.2kyverno.io/kubernetes-version: "1.23"policies.kyverno.io/subject: Deployment, PodDisruptionBudgetpolicies.kyverno.io/description: "PodDisruptionBudget resources are useful to ensuring minimum availability is maintained at all times. This policy checks all incoming Deployments and StatefulSets to ensure they have a matching, preexisting PodDisruptionBudget. Note: This policy must be run in `enforce` mode to ensure accuracy."spec:validationFailureAction: Auditbackground: falserules:- name: require-pdbmatch:any:- resources:kinds:- Deployment- StatefulSetpreconditions:all:- key: "{{request.operation || 'BACKGROUND'}}"operator: Equalsvalue: CREATE- key: "{{ request.object.spec.replicas }}"operator: GreaterThanOrEqualsvalue: 3context:- name: pdb_countapiCall:urlPath: /apis/policy/v1/namespaces/{{request.namespace}}/poddisruptionbudgetsjmesPath: items[?label_match(spec.selector.matchLabels, `{{request.object.spec.template.metadata.labels}}`)] | length(@)validate:message: There is no corresponding PodDisruptionBudget found for this Deployment.deny:conditions:any:- key: "{{pdb_count}}"operator: LessThanvalue: 1
This policy performs some best practices validation on Application fields. Path or chart must be specified but never both. And destination.name or destination.server must be specified but never both.
This policy prevents the use of the default project in an Application.
This policy prevents updates to the project field after an Application is created.