Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

254
Views
How to make k8s cpu and memory HPA work together?

I'm using a k8s HPA template for CPU and memory like below:

---
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
  name: {{.Chart.Name}}-cpu
  labels:
    app: {{.Chart.Name}}
    chart: {{.Chart.Name}}
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: {{.Chart.Name}}
  minReplicas: {{.Values.hpa.min}}
  maxReplicas: {{.Values.hpa.max}}
  targetCPUUtilizationPercentage: {{.Values.hpa.cpu}}
---
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: {{.Chart.Name}}-mem
  labels:
    app: {{.Chart.Name}}
    chart: {{.Chart.Name}}
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: {{.Chart.Name}}
  minReplicas: {{.Values.hpa.min}}
  maxReplicas: {{.Values.hpa.max}}
  metrics:
    - type: Resource
      resource:
        name: memory
        target:
          type: Utilization
          averageValue: {{.Values.hpa.mem}}

Having two different HPA is causing any new pods spun up for triggering memory HPA limit to be immediately terminated by CPU HPA as the pods' CPU usage is below the scale down trigger for CPU. It always terminates the newest pod spun up, which keeps the older pods around and triggers the memory HPA again, causing an infinite loop. Is there a way to instruct CPU HPA to terminate pods with higher usage rather than nascent pods every time?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

As per the suggestion in comments, using a single HPA solved my issue. I just had to move CPU HPA to same apiVersion as memory HPA.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!