Pod controllers such as Deployments which implement replicas and permit the scale action use a `/scale` subresource to control this behavior. In addition to checks for creations of such controllers that their replica is in a certain shape, the scale operation and subresource needs to be accounted for as well. This policy, operable beginning in Kyverno 1.9, is a collection of rules which can be used to limit the replica count both upon creation of a Deployment and when a scale operation is performed.
apiVersion: kyverno.io/v2beta1kind: ClusterPolicymetadata:name: restrict-scaleannotations:policies.kyverno.io/title: Restrict Scalepolicies.kyverno.io/category: Otherpolicies.kyverno.io/severity: mediumkyverno.io/kyverno-version: 1.9.0policies.kyverno.io/minversion: 1.9.0kyverno.io/kubernetes-version: "1.24"policies.kyverno.io/subject: Deploymentpolicies.kyverno.io/description: Pod controllers such as Deployments which implement replicas and permit the scale action use a `/scale` subresource to control this behavior. In addition to checks for creations of such controllers that their replica is in a certain shape, the scale operation and subresource needs to be accounted for as well. This policy, operable beginning in Kyverno 1.9, is a collection of rules which can be used to limit the replica count both upon creation of a Deployment and when a scale operation is performed.spec:validationFailureAction: Auditbackground: falserules:- name: scale-max-eightmatch:any:- resources:kinds:- Deployment/scalevalidate:message: The replica count for this Deployment may not exceed 8.pattern:(status):(selector): "*type=monitoring*"spec:replicas: <9- name: scale-max-eight-annotationsmatch:any:- resources:kinds:- Deployment/scalecontext:- name: parentdeployapiCall:urlPath: /apis/apps/v1/namespaces/{{request.namespace}}/deployments?fieldSelector=metadata.name={{request.name}}jmesPath: items[0]- name: deptvariable:jmesPath: parentdeploy.metadata.annotations."corp.org/dept"default: emptyvalidate:message: The replica count for this Deployment may not exceed 8.deny:conditions:all:- key: "{{dept}}"operator: Equalsvalue: engineering- key: "{{request.object.spec.replicas}}"operator: GreaterThanvalue: 8- name: create-max-fourmatch:any:- resources:kinds:- Deploymentselector:matchLabels:type: monitoringvalidate:message: The replica count for this Deployment may not exceed 4.pattern:spec:replicas: <5
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.