[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-03。"],[],[],null,["# About autoscaling workloads based on metrics\n\n[Autopilot](/kubernetes-engine/docs/concepts/autopilot-overview) [Standard](/kubernetes-engine/docs/concepts/choose-cluster-mode)\n\n*** ** * ** ***\n\nThis page describes the ways that you can automatically increase or decrease\nthe number of replicas of a given workload using custom, external, or Prometheus\nmetrics.\n\nWhy autoscale based on metrics\n------------------------------\n\nConsider an application that pulls tasks from a queue and completes them. The\napplication might have a Service-Level objective (SLO) for time to process a\ntask, or for the number of tasks pending. If the queue is increasing, more\nreplicas of the workload might meet the workloads SLO. If the queue is empty or\nis decreasing more quickly than expected, you could save money by running fewer\nreplicas, while still meeting the workloads SLO.\n\nAbout custom, Prometheus, and external metrics\n----------------------------------------------\n\nYou can scale workloads based on custom, Prometheus, or external metrics.\n\nA *custom metric* is reported from your application running in Kubernetes. To\nlearn more, see\n[Custom and Prometheus metrics](#custom-prometheus-metrics).\n\nMetrics coming from\n[Managed Service for Prometheus](/stackdriver/docs/managed-prometheus) are\nconsidered a type of custom metric.\n\nAn *external metric* is reported from an application or service not running on\nyour cluster, but whose performance impacts your Kubernetes application. For\nexample, you can autoscale on any metric in Cloud Monitoring, including\nPub/Sub or Dataflow. Prometheus metrics contain data emitted\nfrom your cluster that you can use to autoscale on. To learn more, see\n[External metrics](#external-metrics).\n\n### Custom and Prometheus metrics\n\nWe recommend that you use Managed Service for Prometheus to create and manage\ncustom metrics. You can use Prometheus Query Language (PromQL) to query all\nmetrics in Monitoring. For more information, see\n[Horizontal Pod autoscaling for Managed Service for Prometheus](/stackdriver/docs/managed-prometheus/hpa).\n\nYour application can report a custom metric to Monitoring. You\ncan configure Kubernetes to respond to these metrics and scale your workload\nautomatically. For example, you can scale your application based on metrics such\nas queries per second, writes per second, network performance, latency when\ncommunicating with a different application, or other metrics that make sense for\nyour workload. For more information, see\n[Optimize Pod autoscaling based on metrics](/kubernetes-engine/docs/tutorials/autoscaling-metrics).\n\n### External metrics\n\nIf you need to scale your workload based on the performance of an application\nor service outside of Kubernetes, you can configure an external metric. For\nexample, you might need to increase the capacity of your application to ingest\nmessages from Pub/Sub if the number of undelivered messages is\ntrending upward. The external application needs to export the metric to a\nMonitoring instance that the cluster can access. The trend of\neach metric over time causes Horizontal Pod Autoscaler to change the number of\nreplicas in the workload automatically. For more information, see\n[Optimize Pod autoscaling based on metrics](/kubernetes-engine/docs/tutorials/autoscaling-metrics).\n\nImport metrics to Monitoring\n----------------------------\n\nTo import metrics to Monitoring, you can either:\n\n- Configure [Managed Service for Prometheus](/stackdriver/docs/managed-prometheus) (recommended), **or**\n- Export metrics from the application using the [Cloud Monitoring API](/monitoring/custom-metrics/creating-metrics).\n\nWhat's next\n-----------\n\n- Learn how to [enable horizontal Pod autoscaling for Managed Service for Prometheus](/stackdriver/docs/managed-prometheus/hpa).\n- Learn more about [Horizontal Pod Autoscaling](https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/).\n- Learn more about [Vertical Pod autoscaling](/kubernetes-engine/docs/concepts/verticalpodautoscaler)."]]