Skip to main content

no-replicas-with-hpa

Rec
Enabled in recommended preset.
All
Disabled when components are given in CLI.

Disallow replicas field when a resource has a HPA.

This rule ensures that the spec.replicas field is not defined in a Deployment, StatefulSet, or any resources that can be scaled by HPA, when an associated HPA is defined.

If spec.replicas is defined, whenever a resource is updated, Kubernetes will scale the resource to the value defined in the manifest, instead of the value given by the HPA. You can see more details in the Kubernetes documentation.

Examples

Correct manifest for this rule:

new Deployment({
spec: {}
});

Incorrect manifest for this rule:

new Deployment({
spec: { replicas: 3 }
});

Configuration

allow

Allow scale target references that match the patterns to skip this rule.

Examples

Allow a Deployment with a specific namespace and name.

allow = [{ apiVersion = "apps/v1", kind = "Deployment", namespace = "foo", name = "bar" }]