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

10/8/2019

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?

-- mdtp
autoscaling
google-kubernetes-engine
horizontal-scaling
kubernetes
kubernetes-pod

1 Answer

10/11/2019

The cluster autoscaler works on a per-node pool basis. Horizontal Pod Autoscaler monitors CPU utilization of the pods and scales the number of replicas automatically. It provides immediate efficiency and capacity when needed, operates within user-defined minimum/maximum bounds, and allows users to set it and forget it. The design of the horizontal autoscaler is for pods not for the individual container.

HPA calculates pod cpu utilization as total cpu usage of all containers in pod divided by total request. It does not exclude containers metrics from HPA calculation if multiple containers are inside the pod.

-- Aarti S
Source: StackOverflow