HorizontalPodAutoscaler | Set/Update Variable Value

7/2/2020

Is there a way to use HorizontalPodAutoscaler and achieve scaling up/down and along with that update a value (either Helm Variable like .Values.foo or an environemnt variable inside the running pod)?

Backround: I am looking for a Open Source Postgres installation that has the ability to Scale. I found a good once here https://github.com/bitnami/charts/tree/master/bitnami/postgresql-ha

This package has documentated manual way to scale, with a command like helm install/upgrade test . --set postgresql.replicaCount=1

I am trying to put a HorizontalPodAutoscaler to this package.

Also read: https://github.com/bitnami/charts/issues/2931


Summary of Research:

  • There is a environment variable called REPMGR_PARTNER_NODES
  • This maintains a list of known replicas in format APP_NAME-postgresql-ha-postgresql-REPLICA_NUM.APP_NAME-postgresql-ha-postgresql-headless.default.svc.cluster.local
  • This is populated by templates/postgresql/statefulset.yaml in its env section
  • The replication is to be set on the StatefulSet
  • The statefulset auto create PVC
  • We can check replicate via kubectl describe statefulset test-postgresql-ha-postgresql | grep Replicas:

Problem:

  • With a normal HPA like the code below, each Pod's environement variable REPMGR_PARTNER_NODES has a older value.
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
  name: "test-hpa"
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: StatefulSet
    name: "test-postgresql-ha-postgresql"
  minReplicas: 4
  maxReplicas: 5
  metrics:
  - type: Resource
    resource:
      name: cpu
      targetAverageUtilization: 40
-- Srinath Ganesh
horizontal-scaling
kubernetes
kubernetes-helm
postgresql

0 Answers