<p>I use Autopilot on GKE. I've created some log based metrics that I'd like to use to scale up pods.</p>
<p>To begin with - I'm not sure if it's great idea - the metric is just number of records in DB to process... I have a feeling using logs to scale app might bring in some weird infinite loop or something....</p>
<p>Anyhow - I've tried entering <code>logging.googleapis.com|user|celery-person-count</code> as an external metric and got <code>HPA cannot read metric value</code>. Installed Stackdriver adapter but not too sure how to use it either.</p>

dzh
<p>GKE Autopilot clusters have <a href="https://cloud.google.com/kubernetes-engine/docs/how-to/workload-identity" rel="nofollow noreferrer">Workload Identity</a> enabled for consuming other GCP services, including Cloud Monitoring.</p>
<p>You'll want to follow the steps <a href="https://cloud.google.com/kubernetes-engine/docs/tutorials/workload-metrics-autoscaling#step3" rel="nofollow noreferrer">here</a> in order to deploy the Custom Metrics Adapter on Autopilot clusters.</p>
<pre><code>kubectl create clusterrolebinding cluster-admin-binding \
    --clusterrole cluster-admin --user &quot;$(gcloud config get-value account)&quot;

kubectl create namespace custom-metrics

kubectl create serviceaccount --namespace custom-metrics \
custom-metrics-stackdriver-adapter

gcloud iam service-accounts create GSA_NAME

gcloud projects add-iam-policy-binding PROJECT_ID \
    --member &quot;serviceAccount:GSA_NAME@PROJECT_ID.iam.gserviceaccount.com&quot; \
    --role &quot;roles/monitoring.viewer&quot;

gcloud iam service-accounts add-iam-policy-binding \
  --role roles/iam.workloadIdentityUser \
  --member &quot;serviceAccount:PROJECT_ID.svc.id.goog[custom-metrics/custom-metrics-stackdriver-adapter]&quot; \
  GSA_NAME@PROJECT_ID.iam.gserviceaccount.com

kubectl annotate serviceaccount \
  --namespace custom-metrics custom-metrics-stackdriver-adapter \
  iam.gke.io/gcp-service-account=GSA_NAME@PROJECT_ID.iam.gserviceaccount.com

kubectl apply -f manifests/adapter_new_resource_model.yaml
</code></pre>
<p>Given that you've already deployed the adapter, you'll want to delete the deployment first, although you might just be able to run the steps starting at <code>gcloud iam ... </code></p>
<p>You'll need to replace GSA_NAME with a name of your choosing and PROJECT_ID with your Google Cloud project ID.</p>
