A DevOps team manages a web application hosted on a Google Kubernetes Engine (GKE) Standard cluster. The team has configured a Horizontal Pod Autoscaler (HPA) to dynamically scale pod replicas based on CPU utilization. However, during a high-traffic test event, the HPA fails to scale the workload, and running `kubectl describe hpa web-app-hpa` outputs the warning: `unable to get metrics for resource cpu: no metrics returned from resource metrics API`. What action should the Cloud Engineer take to resolve this issue and allow the Horizontal Pod Autoscaler to collect resource metrics?
- Ensure the Metrics Server addon is enabled on the GKE cluster and that container resource requests are defined in the pod specification.Answer
- BEnable Cluster Autoscaler on the GKE node pool to automatically increase pod replica counts when metric requests fail.
- CMigrate the cluster to GKE Autopilot mode because GKE Standard does not support pod-level resource metrics.
- DRecreate the node pool using Spot VMs so that node telemetry metrics can be streamed directly to Cloud Monitoring.
Answer
Ensure the Metrics Server addon is enabled on the GKE cluster and that container resource requests are defined in the pod specification.
The Horizontal Pod Autoscaler relies on the Kubernetes Resource Metrics API to query pod CPU and memory usage. In GKE, the Metrics Server addon collects these metrics from node kubelets. Additionally, the pod deployment spec must include resource requests for HPA to determine the current utilization percentage against the requested target.
Step-by-Step Solution
Key Concept
Horizontal Pod Autoscaling Prerequisites and Metrics Server Management