apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
  name: enforce-replicas-for-scale-subresource
spec:
  background: false
  failurePolicy: Fail
  rules:
    - match:
        all:
          - resources:
              kinds:
                - Deployment/scale
              names:
                - nginx-test
              namespaces:
                - default
      name: validate-nginx-test
      validate:
        message: 'nginx-test needs to have 2 replicas'
        pattern:
          spec:
            replicas: 2
  validationFailureAction: Enforce
