How to set min and max replicas for deployment level?

Viewed 556

Can we set min and max limit for deployments at deployment level, not at cluster or replica set level in kubernetes ?

2 Answers

On deployment level it is not possible, but there is an option to do this indirectly. You should use a HorizontalPodAutoscaler (HPA for short):

HPA automatically updates a workload resource (such as a Deployment or StatefulSet), with the aim of automatically scaling the workload to match demand.

Example code for HPA:

apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: php-apache
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: php-apache
  minReplicas: 1
  maxReplicas: 10

More information can be found in Kubernetes documentation.

At deployment level only replicas attribute is there. When you define hpa there is an option for min and max

Related