How to auto scale helm chart statefulsets

4/19/2019

I have installed the rabbitmq cluster using helm chart. Rabbitmq using statefulsets so is there any way to auto scale this ?

Also one more question how to auto scale (HPA) deployment having PVC ?

-- Harsh Manvar
docker
docker-compose
kubernetes
kubernetes-helm
kubernetes-pod

1 Answer

4/19/2019

StatefulSets can be autoscaled with HPA:

apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
  annotations:
  name: some-service
spec:
  maxReplicas: 4
  metrics:
  - resource:
      name: memory
      targetAverageUtilization: 80
    type: Resource
  - resource:
      name: cpu
      targetAverageUtilization: 80
    type: Resource
  minReplicas: 2
  scaleTargetRef:
    apiVersion: apps/v1
    kind: StatefulSet
    name: some-service

Regarding PVC and StatefulSets and HPA - I'm not sure but I think that depends on reclaimPolicy of StorageClass of your PVC. Just make sure you have reclaimPolicy: Retain in your StorageClass definition. Having that you should preserve data on scaling events.

If you mean Deployments with HPA and PVC - it should work, but always remember that if you have multiple replicas with one shared PVC - all replicas will try to mount it. If PVC is ReadWriteMany - there should be no issues. If it is ReadWriteOnce - then all replicas will be scheduled on one node. If there is not enough resources on node to fit all replicas - you will get some pods in Pending state forever.

-- Vasily Angapov
Source: StackOverflow