{"data":{"slug":"github-google-skills-skills-cloud-gke-workload-scaling-a87cec57cc4d","title":"GKE Workload Scaling: HPA and VPA Best Practices","summary":"Configure Horizontal Pod Autoscaler (HPA) and Vertical Pod Autoscaler (VPA) for GKE workloads to automatically scale pods based on CPU or memory utilization and right-size workloads by adjusting CPU and memory reservations.","url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-gke-workload-scaling-a87cec57cc4d","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-google-skills-skills-cloud-gke-workload-scaling-a87cec57cc4d","markdown_url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-gke-workload-scaling-a87cec57cc4d.md","download_url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-gke-workload-scaling-a87cec57cc4d\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"Before executing any `gcloud`, REST API, or MCP command, you must read [Usage Attribution](references\/attribution.md). For commands executed directly in the terminal, prefix `gcloud` with `CLOUDSDK_METRICS_REQUEST_ATTRIBUTION=\"agent-skills\/1.0 (skill:gke-workload-scaling)\"` and append `agent-skills\/1.0 (skill:gke-workload-scaling)` to `User-Agent` headers.","instructions":"---\nname: gke-workload-scaling\ndescription: >-\n  Manages scaling for GKE workloads using HPA and VPA. Use when configuring\n  Horizontal Pod Autoscaler (HPA), configuring Vertical Pod Autoscaler (VPA),\n  or applying best practices for GKE workload autoscaling. Do not use for\n  cluster-level autoscaling (Cluster Autoscaler), static cluster sizing,\n  or configuring node-level machine styles directly.\nmetadata:\n  version: \"1.0.1\"\n  category: Containers\n---\n\n# GKE Workload Scaling\n\nThis skill provides workflows and best practices for scaling applications on\nGoogle Kubernetes Engine (GKE). It covers manual scaling, Horizontal Pod\nAutoscaling (HPA), and Vertical Pod Autoscaling (VPA).\n\n## Attribution\n\n**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you\nMUST read [Usage Attribution](references\/attribution.md). For commands executed\ndirectly in the terminal (never in generated scripts, Terraform, or user code),\nprefix `gcloud` with\n`CLOUDSDK_METRICS_REQUEST_ATTRIBUTION=\"agent-skills\/1.0 (skill:gke-workload-scaling)\"`\nand append `agent-skills\/1.0 (skill:gke-workload-scaling)` to `User-Agent` headers.\n\n## Workflows\n\n### 1. Manual Scaling\n\nScale a deployment to a fixed number of replicas. Useful for immediate manual\nintervention or testing.\n\n**Command:**\n\n```bash\nkubectl scale deployment {deployment_name} --replicas={number} -n {namespace}\n\n# Verify the scale event\nkubectl get deployment {deployment_name} -n {namespace}\n```\n\n### 2. Horizontal Pod Autoscaling (HPA)\n\nAutomatically scale the number of pods based on observed CPU utilization, memory\nutilization, or custom metrics.\n\n**Prerequisites:**\n\n-   Metrics Server must be running (enabled by default on GKE).\n-   Containers clearly define resource requests\/limits.\n\n**Quick Command:**\n\n```bash\nkubectl autoscale deployment {deployment_name} --cpu-percent=50 --min=1 --max=10\n```\n\n**Manifest Approach (Recommended):** Use a YAML manifest for version-controlled\nconfiguration. See [assets\/hpa-example.yaml](assets\/hpa-example.yaml) for a\ntemplate.\n\n```bash\nkubectl apply -f assets\/hpa-example.yaml\n\n# Verify HPA is created and fetching metrics\nkubectl get hpa\n```\n\n**Custom Metrics & External Metrics:** For GKE, the modern and recommended\napproach for scaling based on Cloud Monitoring metrics (e.g., Pub\/Sub queue\nlength) is to use the **External** metric type, which is natively supported by\nthe GKE control plane without requiring the Custom Metrics Adapter. For\napplication-specific metrics exposed via Prometheus, you can use **Google Cloud\nManaged Service for Prometheus** or the Prometheus Adapter.\n\n### 3. Vertical Pod Autoscaling (VPA)\n\nAutomatically adjust the CPU and memory reservations for your pods to match\nactual usage. This is critical for right-sizing workloads.\n\n**Prerequisites:**\n\n-   VPA must be enabled on the cluster.\n    -   **Autopilot:** Enabled by default.\n    -   **Standard:** Must be enabled manually.\n\n**Enable VPA on Standard Cluster:**\n\n```bash\ngcloud container clusters update {cluster_name} --enable-vertical-pod-autoscaling --zone {zone}\n```\n\n**Update Modes:**\n\n-   `Off`: Calculates recommendations but does not apply them. Good for \"dry\n    run\" analysis.\n-   `Initial`: Assigns resources only at pod creation time.\n-   `Auto`: Updates running pods by restarting them if recommendations differ\n    significantly from requests.\n-   `InPlaceOrRecreate`: Attempts to update Pod resources without recreating the\n    Pod. If in-place update is not possible, it reverts to `Auto` mode (requires\n    GKE 1.34+).\n\n**Example:** See [assets\/vpa-example.yaml](assets\/vpa-example.yaml) for a\nconfiguration template.\n\n## Best Practices\n\n1.  **Define Resource Requests:** HPA and VPA rely on accurate resource\n    requests. Always define them in your container specs.\n2.  **Avoid Metric Conflicts:** Do not configure HPA and VPA to use the same\n    metric (e.g., both CPU). This causes thrashing.\n    -   *Typical Pattern:* HPA on CPU, VPA on Memory.\n3.  **Pod Disruption Budgets (PDBs):** Define PDBs to ensure application\n    availability during scaling events or node upgrades.\n4.  **HPA Lag:** HPA has a stabilization window (default 5 mins) to prevent\n    rapid fluctuation.\n5.  **VPA \"Auto\" Mode Risks:** In \"Auto\" mode, VPA restarts pods to change\n    resources. Ensure your application handles restarts gracefully (e.g.,\n    handles SIGTERM).\n    -   *Note:* By default, VPA requires at least 2 replicas to perform\n        evictions (to prevent a situation where the only running replica is\n        evicted, causing downtime). In GKE 1.22+, you can override this by\n        setting `minReplicas` in `PodUpdatePolicy`.\n\n## Rightsizing Workflow\n\n1.  Deploy VPA in `Off` mode for 24+ hours\n2.  Read recommendations: `kubectl describe vpa {deployment_name}-vpa -n\n    {namespace}`\n3.  Compare `target` values against current `requests`\n4.  Apply with 20% buffer: `new_request = target * 1.2`\n5.  Use patch format or update deployment manifest to apply new resource\n    requests\n\nCondition                     | Recommendation                       | Risk\n----------------------------- | ------------------------------------ | ------\nCPU request >5x P95 actual    | Reduce to `P95 * 1.2`                | Medium\nMemory request >3x P95 actual | Reduce to `P95 * 1.2`                | Medium\nCPU request >2x P95 actual    | Rightsizing with 20% buffer          | Low\nNo resource limits set        | Add limits to prevent noisy-neighbor | Low\n","use_cases":["Scale a deployment to a fixed number of replicas for immediate manual intervention.","Automatically scale pods based on CPU or memory utilization using HPA.","Right-size workloads by adjusting CPU and memory reservations using VPA."],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/google\/skills\/blob\/e3c591afe426ea585e4c21799e5199d6d47cd1be\/skills\/cloud\/gke-workload-scaling\/SKILL.md","source_commit":"e3c591afe426ea585e4c21799e5199d6d47cd1be","license":null,"version":null,"listing_approved_at":"2026-11-17","created_at":"2026-11-16T16:54:46.000000Z","updated_at":"2026-11-17T10:20:00.000000Z","seo_title":"GKE Workload Scaling: HPA and VPA Best Practices","seo_description":"Learn how to scale GKE workloads using Horizontal Pod Autoscaler (HPA) and Vertical Pod Autoscaler (VPA) for optimal performance and resource management.","seo_keywords":["GKE workload scaling","HPA and VPA best practices","Google Kubernetes Engine scaling","Horizontal Pod Autoscaler","Vertical Pod Autoscaler"]}}