<p>I am currently trying to set up a GKE cluster and to configure an <code>HorizontalPodAutoscaler</code> based on a custom metric (GPU consumption).
I have two node-pools and I want to horizontally scale them based on the average GPU consumption of <strong>each</strong> <code>node_pool</code>. I have configured two identical HPA like this:</p>
<pre><code>apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: ner
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: ner
  minReplicas: 1
  maxReplicas: 10
  metrics:
    - type: External
      external:
        metric:
          name: kubernetes.io|container|accelerator|duty_cycle
        target:
          type: AverageValue
          averageValue: 60
</code></pre>
<p>where I only replace the <code>scaleTargetRef</code> but it turns out that this metric seems to be aggregated at a cluster level. I have double checked that the <code>scaleTargetRef</code> are properly defined.</p>
<p>Is there a way to filter the metrics by <code>container_name</code> or <code>node_pool</code>? Any other suggestion would be awesome !</p>

<p>So I think you are looking for metrics for your k8 cluster especially by <code>container_name</code> or <code>node_pool</code>.</p>
<p>You have five types of metrics you can use in an HPA object(autoscaling/v2beta2)</p>
<pre><code>k explain HorizontalPodAutoscaler.spec.metrics.type  --api-version=autoscaling/v2beta2
</code></pre>
<p><em>Edit update</em></p>
<ul>
<li><a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/" rel="nofollow noreferrer">ContainerResource</a></li>
<li>External # Use this if <a href="https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/#autoscaling-on-metrics-not-related-to-kubernetes-objects" rel="nofollow noreferrer">the metrics not related to Kubernetes objects</a>.</li>
<li>Object</li>
<li>Pods</li>
<li>Resource</li>
</ul>
<hr />
<pre><code>apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: ner
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: ner
  minReplicas: 1
  maxReplicas: 10
  metrics:
    - type: ContainerResource
      containerResource:
        name: gpu
        container: your-application-container
        target:
          type: Utilization
          averageUtilization: 60
</code></pre>
<hr />
<p><em>Edit Update</em></p>
<p>For GKP <a href="http://Cluster:%20https://cloud.google.com/kubernetes-engine/docs/tutorials/autoscaling-metrics#custom-metric_4" rel="nofollow noreferrer">Autoscaling Deployments with Cloud Monitoring metrics</a></p>
