Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude some containers' metrics in Kubernetes Horizontal Pod Autoscaling

I have a pod running with two containers. The actual application is running in one of the containers (container-app) and the other one is the proxy container (container-proxy). I enabled the Horizontal Pod Autoscaler (HPA) for CPU usage percentage but as it states in HPA documentation, both of the container metrics are put in the calculation.

I want to exclude the CPU metrics of container-proxy from HPA calculation because I want only application container to be the scaling element for the pod.

Is there any way to exclude some containers metrics from HPA calculation for multi-container pods?

like image 937
mdtp Avatar asked Jan 21 '26 18:01

mdtp


1 Answers

Kubernetes 1.20+ supports container metrics, so as to target the utilisation per container, which would allow excluding a specific container of a pod from being considered.

https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#container-resource-metrics

type: ContainerResource
containerResource:
  name: cpu
  container: application
  target:
    type: Utilization
    averageUtilization: 60

Its an alpha feature though, so not available without turning on alpha features in Kubernetes.

like image 126
Andy Avatar answered Jan 24 '26 17:01

Andy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!