HorizontalPodAutoscaler (HPA) is useful to automatically adjust the number of pods in a deployment or replication controller. It requires defining a specific target resource by kind and name. There are no built-in validation checks by the HPA controller to prevent the creation of multiple HPAs which target the same resource. This policy has two rules, the first of which ensures that the only targetRef kinds accepted are one of either Deployment, StatefulSet, ReplicaSet, or DaemonSet. The second prevents the creation of duplicate HPAs by validating that any new HPA targets a unique resource.
apiVersion: kyverno.io/v1kind: ClusterPolicymetadata:name: prevent-duplicate-hpaannotations:policies.kyverno.io/title: Prevent Duplicate HorizontalPodAutoscalerspolicies.kyverno.io/category: Otherpolicies.kyverno.io/severity: mediumkyverno.io/kyverno-version: 1.11.4kyverno.io/kubernetes-version: "1.27"policies.kyverno.io/subject: HorizontalPodAutoscalerpolicies.kyverno.io/description: HorizontalPodAutoscaler (HPA) is useful to automatically adjust the number of pods in a deployment or replication controller. It requires defining a specific target resource by kind and name. There are no built-in validation checks by the HPA controller to prevent the creation of multiple HPAs which target the same resource. This policy has two rules, the first of which ensures that the only targetRef kinds accepted are one of either Deployment, StatefulSet, ReplicaSet, or DaemonSet. The second prevents the creation of duplicate HPAs by validating that any new HPA targets a unique resource.spec:validationFailureAction: Auditbackground: falserules:- name: verify-kind-name-duplicatesmatch:any:- resources:kinds:- HorizontalPodAutoscaleroperations:- CREATEvalidate:message: "The target kind must be specified exactly as Deployment, StatefulSet, ReplicaSet, or DaemonSet. "pattern:spec:scaleTargetRef:kind: Deployment | StatefulSet | ReplicaSet | DaemonSet- name: check-targetref-duplicatesmatch:any:- resources:kinds:- HorizontalPodAutoscaleroperations:- CREATEpreconditions:all:- key:- Deployment- StatefulSet- ReplicaSet- DaemonSetoperator: AnyInvalue: "{{ request.object.spec.scaleTargetRef.kind }}"context:- name: targetsapiCall:urlPath: /apis/autoscaling/v1/namespaces/{{ request.namespace }}/horizontalpodautoscalersjmesPath: items[?spec.scaleTargetRef.kind=='{{ request.object.spec.scaleTargetRef.kind }}'].spec.scaleTargetRef.namevalidate:message: "The target {{ request.object.spec.scaleTargetRef.kind }} named {{ request.object.spec.scaleTargetRef.name }} already has an existing HPA configured for it. Duplicate HPAs are not allowed. "deny:conditions:all:- key: "{{ request.object.spec.scaleTargetRef.name }}"operator: AnyInvalue: "{{ targets }}"
This policy prevents the use of the default project in an Application.
Services of type LoadBalancer when deployed inside AWS have support for transport encryption if it is enabled via an annotation. This policy requires that Services of type LoadBalancer contain the annotation service.beta.kubernetes.io/aws-load-balancer-ssl-cert with some value.
This policy prevents updates to the project field after an Application is created.