<p>I'm currently navigating the intricacies of Horizontal Pod Autoscaler (HPA) behavior in the context of pods housing a sidecar container. Here's the context:</p>
<p>I've set up a pod serving images, paired with a sidecar container running nginx for caching. Both containers have their own resource requests defined. While the system is performing well, I'm seeking clarity on the HPA's scaling decision-making process.</p>
<p>Currently, the HPA triggers scaling when CPU request usage hits 80%. However, I'm unsure whether the HPA evaluates metrics for each container independently or if it considers both containers' metrics collectively.</p>
<p>In essence, does the HPA analyze metrics for individual containers separately? If so, how does it prioritize their evaluation? Alternatively, does it treat both containers as a single unit when assessing CPU request consumption?</p>
<p>I'd appreciate any insights into the HPA's metric evaluation approach in this specific setup. Thank you for your help!</p>

pwoltschk
<p>Per Kubernetes official <a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/" rel="nofollow noreferrer">documentation</a>.</p>
<blockquote>
<p>The HorizontalPodAutoscaler API also supports a container metric source
where the HPA can track the resource usage of individual containers
across a set of Pods, in order to scale the target resource. This lets
you configure scaling thresholds for the containers that matter most
in a particular Pod. For example, if you have a web application and a
logging sidecar, you can scale based on the resource use of the web
application, ignoring the sidecar container and its resource use.</p>
</blockquote>
<blockquote>
<p>If you revise the target resource to have a new Pod specification with
a different set of containers, you should revise the HPA spec if that
newly added container should also be used for scaling. If the
specified container in the metric source is not present or only
present in a subset of the pods then those pods are ignored and the
recommendation is recalculated.</p>
</blockquote>
<p>To use container resources for autoscaling define a metric source as follows, an example where the HPA controller scales the target such that the average utilization of the cpu in the <strong>application container</strong> of all the pods is 60%.:</p>
<pre><code>type: ContainerResource
containerResource:
  name: cpu
  container: application
  target:
    type: Utilization
    averageUtilization: 60
</code></pre>
<p><a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#algorithm-details" rel="nofollow noreferrer">Additional info with algorithm used by HPA</a></p>
