Automatically scale replicas with HorizontalPodAutoscaler

Is it possible to automatically scale replica set Percona for MongodDb operator (increase number of replicas) with HorizontalPodAutoscaler ? I found that this is possible for XtraDbCluster but not sure if it will work for Mongodb cluster.

apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
  name: cluster1
spec:
  minReplicas: 3
  maxReplicas: 5
  metrics:
  - resource:
      name: cpu
      targetAverageUtilization: 2
    type: Resource
  scaleTargetRef:
    apiVersion: http://psmdb.percona.com/v1-11-0 ????
    kind: PerconaServerMongoDB ????
    name: rs0 ???? (what if sharding is on with multiple replica sets ?)

Will this work ?

Thank you

1 Like

Hello @Darko ,

for now it is not possible to use HPA with our operator. The main blocker here is multiple replica sets that are in a nutshell are arrays in YAML syntax in the Custom Resource. Do to that fact it is not possible to state specifically which replica set you want to scale with HPA.

We will see about options here.

1 Like

@Sergey_Pronin Thank for the the information, I will keep in mind this.

Maybe after all, it is not good idea to have a HPA on replicaset. From this documentation

If you have a Deployment, don’t configure horizontal Pod autoscaling on the ReplicaSet or Replication Controller backing it. When you perform a rolling update on the Deployment or Replication Controller, it is effectively replaced by a new Replication Controller. Instead configure horizontal Pod autoscaling on the Deployment itself.

1 Like