{"id":150665,"date":"2026-12-05T12:07:46","date_gmt":"2026-12-05T06:37:46","guid":{"rendered":"https:\/\/www.guvi.in\/blog\/?p=150665"},"modified":"2026-12-05T12:07:47","modified_gmt":"2026-12-05T06:37:47","slug":"kubernetes-hpa-tutorial","status":"publish","type":"post","link":"https:\/\/www.guvi.in\/blog\/kubernetes-hpa-tutorial\/","title":{"rendered":"Kubernetes HPA Tutorial: Automatically Scale Applications Based on Demand"},"content":{"rendered":"\n<p>Modern applications experience changing workloads throughout the day. An e-commerce application may receive thousands of requests during a sale, while traffic remains low during regular hours. Running the same number of application instances throughout these periods can waste resources or affect application performance.<\/p>\n\n\n\n<p><strong>Kubernetes HPA (Horizontal Pod Autoscaler)<\/strong> helps solve this problem by automatically increasing or decreasing the number of Pods based on resource utilisation or other configured metrics. It allows applications to handle changing workloads without requiring developers to manually adjust replica counts.<\/p>\n\n\n\n<p>In this tutorial, you will learn how Kubernetes HPA works, its prerequisites, how to configure autoscaling using YAML and kubectl commands, and how to troubleshoot common scaling issues.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>TL;DR<\/strong><\/h2>\n\n\n\n<ul>\n<li>Kubernetes HPA automatically increases or decreases the number of Pod replicas based on application demand.<\/li>\n\n\n\n<li>It uses CPU, memory, custom, or external metrics to determine when scaling is required.<\/li>\n\n\n\n<li>Metrics Server provides CPU and memory metrics required for resource-based autoscaling.<\/li>\n\n\n\n<li>The autoscaling\/v2 API supports multiple metrics and configurable scaling behaviour.<\/li>\n\n\n\n<li>HPA manages Pod replicas, while solutions such as Cluster Autoscaler manage Kubernetes worker nodes.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What Is Kubernetes HPA (Horizontal Pod Autoscaler)?<\/strong><\/h2>\n\n\n\n<p><strong>Kubernetes HPA is a built-in autoscaling mechanism that automatically adjusts the number of running Pod replicas based on observed resource utilisation or other configured metrics.<\/strong><\/p>\n\n\n\n<p>It helps applications handle changing workloads by scaling horizontally. Instead of increasing the CPU or memory allocated to an existing Pod, HPA creates additional Pods when demand increases and reduces their number when demand decreases.<\/p>\n\n\n\n<p>For example, consider an online shopping application running three Pods. During a promotional sale, incoming requests increase and CPU utilisation rises. Kubernetes HPA detects the higher utilisation and increases the number of replicas to handle the additional traffic.<\/p>\n\n\n\n<p>When traffic decreases, HPA gradually reduces the replicas, subject to its configured scaling behaviour and minimum replica count.<\/p>\n\n\n\n<p>The main benefits include:<\/p>\n\n\n\n<ul>\n<li><strong>Improved availability:<\/strong> Additional Pods help applications handle increased workloads.<\/li>\n\n\n\n<li><strong>Resource efficiency:<\/strong> Unnecessary replicas can be removed when demand decreases.<\/li>\n\n\n\n<li><strong>Reduced manual work:<\/strong> Developers do not need to continuously adjust replica counts.<\/li>\n\n\n\n<li><strong>Better scalability:<\/strong> Applications can respond to changing traffic more effectively.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How Does Horizontal Pod Autoscaler Work in Kubernetes?<\/strong><\/h2>\n\n\n\n<p>Horizontal Pod Autoscaler Kubernetes uses a control loop to monitor application metrics, calculate the required number of replicas, and update the target workload.<\/p>\n\n\n\n<p>The process involves five main steps:<\/p>\n\n\n\n<ol>\n<li><strong>Metric collection:<\/strong> Kubernetes collects CPU, memory, or configured application metrics from running Pods.<\/li>\n\n\n\n<li><strong>Metric availability:<\/strong> Metrics Server or an appropriate metrics adapter exposes the required metrics through Kubernetes APIs.<\/li>\n\n\n\n<li><strong>Metric comparison:<\/strong> The HPA controller compares current metric values against the configured target.<\/li>\n\n\n\n<li><strong>Replica calculation:<\/strong> It calculates how many replicas are required to reach the target utilisation.<\/li>\n\n\n\n<li><strong>Workload scaling:<\/strong> The controller updates the Deployment&#8217;s desired replica count, and Kubernetes creates or removes Pods accordingly.<\/li>\n<\/ol>\n\n\n\n<p>For example, suppose an application has four replicas, with an average CPU utilisation of 80%. Its HPA target is 40%.<\/p>\n\n\n\n<p>The simplified scaling calculation is:<\/p>\n\n\n\n<div style=\"background-color: #f5f5f5; padding: 16px; border-radius: 8px; text-align: center; margin: 15px 0;\">\n  <p><strong>Desired Replicas = Current Replicas \u00d7 (Current Utilisation \/ Target Utilisation)<\/strong><\/p>\n  <p>= 4 \u00d7 (80 \/ 40)<\/p>\n  <p><strong>= 8 Replicas<\/strong><\/p>\n<\/div>\n\n\n\n<p>Kubernetes may therefore increase the desired replica count to eight, subject to scaling limits and other controller checks.<\/p>\n\n\n\n<p><strong><em>Want to build practical DevOps skills?<\/em><\/strong><em> Explore the HCL GUVI <a href=\"https:\/\/www.guvi.in\/zen-class\/devops-course\/?utm_source=blog&amp;utm_medium=hyperlink&amp;utm_campaign=kubernetes-hpa-tutorial\" target=\"_blank\" data-type=\"link\" data-id=\"https:\/\/www.guvi.in\/zen-class\/devops-course\/?utm_source=blog&amp;utm_medium=hyperlink&amp;utm_campaign=kubernetes-hpa-tutorial\" rel=\"noreferrer noopener\">DevOps course<\/a> to learn essential DevOps tools, containerisation, Kubernetes, CI\/CD, and deployment practices through structured learning and hands-on projects.<\/em><\/p>\n\n\n<div class=\"wp-block-guvi-cta-button\" style=\"justify-content:center;\"><a href=\"https:\/\/www.guvi.in\/zen-class\/devops-course\/?utm_source=blog&#038;utm_medium=cta_button&#038;utm_campaign=kubernetes-hpa-tutorial\" class=\"guvi-btn-enquire\" target=\"_blank\" rel=\"noopener noreferrer\">Enquire Now<\/a><\/div>\n\n\n<p><strong>What is the role of Metrics Server?<\/strong><\/p>\n\n\n\n<p>Metrics Server collects CPU and memory usage information from Kubernetes nodes through their kubelets and exposes it through the Metrics API.<\/p>\n\n\n\n<p>The HPA controller uses these metrics to make scaling decisions. The controller runs as part of the Kubernetes control plane and periodically evaluates the configured scaling targets.<\/p>\n\n\n\n<p>Metrics Server is designed for autoscaling and basic resource metrics. It is not a replacement for full monitoring solutions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Kubernetes HPA Prerequisites<\/strong><\/h2>\n\n\n\n<p>Before configuring Kubernetes autoscaling, ensure that your cluster meets the following requirements:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>Prerequisite<\/strong><\/td><td><strong>Purpose<\/strong><\/td><\/tr><tr><td>Running Kubernetes cluster<\/td><td>Provides the environment to deploy and manage applications.<\/td><\/tr><tr><td>Deployment or scalable workload<\/td><td>Provides the Pods that HPA will scale.<\/td><\/tr><tr><td>Resource requests<\/td><td>Required for CPU and memory utilisation-based scaling.<\/td><\/tr><tr><td>Metrics Server<\/td><td>Supplies CPU and memory metrics through the Metrics API.<\/td><\/tr><tr><td>Kubernetes permissions<\/td><td>Allows you to create and manage HPA resources.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>You can check whether Metrics Server is providing resource metrics using:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl top nodes\n\nkubectl top pods<\/code><\/pre>\n\n\n\n<p>If these commands return resource usage information, the Metrics API is available.<\/p>\n\n\n\n<p>If Metrics Server is not installed, install a compatible release by following its official deployment instructions:<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/kubernetes-sigs\/metrics-server\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Kubernetes Metrics Server installation guide<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Kubernetes HPA Tutorial: Step-by-Step Implementation<\/strong><\/h2>\n\n\n\n<p>Let&#8217;s implement Kubernetes HPA using a sample NGINX application. You will create a Deployment, expose it through a Service, configure autoscaling, and generate traffic to observe how the replica count changes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 1: Create a Kubernetes Deployment<\/strong><\/h3>\n\n\n\n<p>First, create a Deployment with two NGINX replicas.<\/p>\n\n\n\n<p>Create a file named nginx-deployment.yaml:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apiVersion: apps\/v1\n\nkind: Deployment\n\nmetadata:\n\n&nbsp;&nbsp;name: nginx-deployment\n\nspec:\n\n&nbsp;&nbsp;replicas: 2\n\n&nbsp;&nbsp;selector:\n\n&nbsp;&nbsp;&nbsp;&nbsp;matchLabels:\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;app: nginx\n\n&nbsp;&nbsp;template:\n\n&nbsp;&nbsp;&nbsp;&nbsp;metadata:\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;labels:\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;app: nginx\n\n&nbsp;&nbsp;&nbsp;&nbsp;spec:\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;containers:\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- name: nginx\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;image: nginx:1.27\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ports:\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- containerPort: 80\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;resources:\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;requests:\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cpu: 100m\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memory: 64Mi\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;limits:\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cpu: 500m\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memory: 128Mi<\/code><\/pre>\n\n\n\n<p>Here:<\/p>\n\n\n\n<ul>\n<li>replicas: 2 starts two application Pods.<\/li>\n\n\n\n<li>requests specifies the CPU and memory resources requested by each container.<\/li>\n\n\n\n<li>limits defines the maximum CPU and memory resources available to each container.<\/li>\n<\/ul>\n\n\n\n<p>Apply the configuration:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl apply -f nginx-deployment.yaml<\/code><\/pre>\n\n\n\n<p>Verify the Deployment:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl get deployments\n\nkubectl get pods<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 2: Expose the Application Using a Service<\/strong><\/h3>\n\n\n\n<p>Create a Service to expose the NGINX application inside the cluster.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl expose deployment nginx-deployment \\\n\n&nbsp;&nbsp;--name=nginx-service \\\n\n&nbsp;&nbsp;--port=80 \\\n\n&nbsp;&nbsp;--target-port=80 \\\n\n&nbsp;&nbsp;--type=ClusterIP<\/code><\/pre>\n\n\n\n<p>Check whether the Service is running:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl get services<\/code><\/pre>\n\n\n\n<p>The Service provides a stable network endpoint for accessing the application, even when HPA changes the number of Pods.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 3: Create a Kubernetes HPA<\/strong><\/h3>\n\n\n\n<p>Now, configure HPA to maintain CPU utilisation around 50%.<\/p>\n\n\n\n<p>Run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl autoscale deployment nginx-deployment \\\n\n&nbsp;&nbsp;--cpu-percent=50 \\\n\n&nbsp;&nbsp;--min=2 \\\n\n&nbsp;&nbsp;--max=10<\/code><\/pre>\n\n\n\n<p>This command creates an HPA with the following configuration:<\/p>\n\n\n\n<ul>\n<li>Minimum replicas: 2<\/li>\n\n\n\n<li>Maximum replicas: 10<\/li>\n\n\n\n<li>Target CPU utilisation: 50%<\/li>\n<\/ul>\n\n\n\n<p>Kubernetes will monitor CPU utilisation and adjust the Deployment&#8217;s replica count when scaling is required.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 4: Check HPA Status<\/strong><\/h3>\n\n\n\n<p>Use the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl get hpa<\/code><\/pre>\n\n\n\n<p>Example output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>NAME &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; REFERENCE\n\nnginx-deployment &nbsp; Deployment\/nginx-deployment\n\nTARGETS &nbsp; &nbsp; MINPODS &nbsp; MAXPODS &nbsp; REPLICAS\n\n25%\/50% &nbsp; &nbsp; 2 &nbsp; &nbsp; &nbsp; &nbsp; 10&nbsp; &nbsp; &nbsp; &nbsp; 2<\/code><\/pre>\n\n\n\n<p>The 25%\/50% value indicates that the current average CPU utilisation is 25%, against a target of 50%.<\/p>\n\n\n\n<p>You can also inspect additional information using:<\/p>\n\n\n\n<p>kubectl describe hpa nginx-deployment<\/p>\n\n\n\n<p>This command displays current metrics, scaling events, replica counts, and possible errors.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 5: Generate Traffic to Trigger Scaling<\/strong><\/h3>\n\n\n\n<p>To observe autoscaling, generate traffic against the NGINX application.<\/p>\n\n\n\n<p>Run a temporary BusyBox Pod:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl run load-generator \\\n\n&nbsp;&nbsp;--image=busybox:1.36 \\\n\n&nbsp;&nbsp;--restart=Never \\\n\n&nbsp;&nbsp;-- \/bin\/sh -c \\\n\n&nbsp;&nbsp;\"while true; do wget -q -O- http:\/\/nginx-service; done\"<\/code><\/pre>\n\n\n\n<p>This command continuously sends requests to the NGINX Service.<\/p>\n\n\n\n<p>In another terminal, monitor the HPA:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl get hpa nginx-deployment --watch<\/code><\/pre>\n\n\n\n<p>You can also monitor the Pods:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl get pods --watch<\/code><\/pre>\n\n\n\n<p>If the workload increases CPU utilisation above the configured target, HPA may increase the number of replicas.<\/p>\n\n\n\n<p><strong>Note:<\/strong> A continuous HTTP request loop does not guarantee that CPU utilisation will reach 50%. The actual scaling response depends on the workload, available resources, metrics collection, and scaling policies.<\/p>\n\n\n\n<p>After testing, stop the load generator and remove it:<\/p>\n\n\n\n<p>kubectl delete pod load-generator<\/p>\n\n\n\n<p>As application demand decreases, HPA can reduce the number of replicas until the configured minimum is reached.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 6: Configure HPA Using YAML<\/strong><\/h3>\n\n\n\n<p>You can also define HPA using a Kubernetes YAML manifest. The autoscaling\/v2 API is recommended because it supports multiple metrics and configurable scaling behaviour.<\/p>\n\n\n\n<p>Create a file named nginx-hpa.yaml:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apiVersion: autoscaling\/v2\n\nkind: HorizontalPodAutoscaler\n\nmetadata:\n\n&nbsp;&nbsp;name: nginx-hpa\n\nspec:\n\n&nbsp;&nbsp;scaleTargetRef:\n\n&nbsp;&nbsp;&nbsp;&nbsp;apiVersion: apps\/v1\n\n&nbsp;&nbsp;&nbsp;&nbsp;kind: Deployment\n\n&nbsp;&nbsp;&nbsp;&nbsp;name: nginx-deployment\n\n&nbsp;&nbsp;minReplicas: 2\n\n&nbsp;&nbsp;maxReplicas: 10\n\n&nbsp;&nbsp;metrics:\n\n&nbsp;&nbsp;- type: Resource\n\n&nbsp;&nbsp;&nbsp;&nbsp;resource:\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name: cpu\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;target:\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type: Utilization\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;averageUtilization: 50\n\n&nbsp;&nbsp;behavior:\n\n&nbsp;&nbsp;&nbsp;&nbsp;scaleDown:\n\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stabilizationWindowSeconds: 300<\/code><\/pre>\n\n\n\n<p>This configuration:<\/p>\n\n\n\n<ul>\n<li>Targets the nginx-deployment Deployment.<\/li>\n\n\n\n<li>Maintains between two and ten replicas.<\/li>\n\n\n\n<li>Targets average CPU utilisation of 50%.<\/li>\n\n\n\n<li>Uses a five-minute scale-down stabilization window to reduce unnecessary fluctuations.<\/li>\n<\/ul>\n\n\n\n<p>Apply the configuration:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl apply -f nginx-hpa.yaml<\/code><\/pre>\n\n\n\n<p>Check the configuration:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl get hpa\n\nkubectl describe hpa nginx-hpa<\/code><\/pre>\n\n\n\n<p>Use either the command-based HPA or the YAML-based HPA for this Deployment, rather than creating two competing autoscalers for the same workload.<\/p>\n\n\n\n<p><em><strong>Also checkout: <a href=\"https:\/\/www.guvi.in\/blog\/kubernetes-roadmap\/\" target=\"_blank\" rel=\"noreferrer noopener\">Kubernetes Roadmap 2026: How to Learn Kubernetes Step by Step for a Successful DevOps Career<\/a><\/strong><\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Kubernetes HPA Metrics and Scaling Targets<\/strong><\/h2>\n\n\n\n<p>Kubernetes HPA supports different metric types to determine when an application needs additional resources.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>Metric type<\/strong><\/td><td><strong>What it measures<\/strong><\/td><td><strong>Example<\/strong><\/td><\/tr><tr><td>CPU utilisation<\/td><td>Average CPU usage relative to requested CPU<\/td><td>Scale when CPU utilisation exceeds 60%.<\/td><\/tr><tr><td>Memory utilisation<\/td><td>Average memory usage relative to requested memory<\/td><td>Scale when memory utilisation exceeds 70%.<\/td><\/tr><tr><td>Custom metrics<\/td><td>Application-specific metrics<\/td><td>Scale based on requests processed per second.<\/td><\/tr><tr><td>External metrics<\/td><td>Metrics from systems outside the Kubernetes workload<\/td><td>Scale based on message queue length.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>Resource metrics:<\/strong> CPU and memory are built-in resource metrics. Metrics Server provides the information required for these scaling decisions.<\/p>\n\n\n\n<p><strong>Custom metrics:<\/strong> These represent application-specific measurements, such as active connections, request rates, or messages processed per second. They require a compatible custom metrics API adapter.<\/p>\n\n\n\n<p><strong>External metrics:<\/strong> These come from sources outside the Kubernetes workload, such as cloud message queues or external monitoring systems. They require an external metrics adapter.<\/p>\n\n\n\n<p>An HPA can also use multiple metrics simultaneously. Kubernetes calculates a replica recommendation for each metric and selects the highest recommendation, subject to the configured maximum replicas.<\/p>\n\n\n\n<p><strong><em>Also checkout: <a href=\"https:\/\/www.guvi.in\/blog\/what-to-learn-to-become-a-devops-engineer\/\" target=\"_blank\" rel=\"noreferrer noopener\">What to Learn to Become a DevOps Engineer in 2026?<\/a><\/em><\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Kubernetes HPA vs VPA: What Is the Difference?<\/strong><\/h2>\n\n\n\n<p>Kubernetes HPA and VPA are both autoscaling mechanisms, but they solve different resource management problems.<\/p>\n\n\n\n<p><strong>HPA increases or decreases the number of Pods, whereas VPA adjusts the CPU and memory resource requests of existing application containers.<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>Comparison factor<\/strong><\/td><td><strong>Kubernetes HPA<\/strong><\/td><td><strong>Kubernetes VPA<\/strong><\/td><\/tr><tr><td>Primary purpose<\/td><td>Adjusts the number of Pods<\/td><td>Adjusts Pod resource requests<\/td><\/tr><tr><td>Scaling approach<\/td><td>Horizontal scaling<\/td><td>Vertical scaling<\/td><\/tr><tr><td>Resource adjustments<\/td><td>Changes replica count<\/td><td>Changes CPU and memory requests<\/td><\/tr><tr><td>Impact on Pods<\/td><td>Creates or removes Pods<\/td><td>May restart Pods to apply recommendations<\/td><\/tr><tr><td>Typical use cases<\/td><td>Applications with changing traffic<\/td><td>Applications with changing resource requirements<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>When should you use HPA?<\/strong><\/p>\n\n\n\n<p>Choose HPA when your application needs additional replicas to handle increasing traffic. It is useful for web applications, APIs, and microservices.<\/p>\n\n\n\n<p><strong>When should you use VPA?<\/strong><\/p>\n\n\n\n<p>Choose VPA when your application needs more or fewer CPU and memory resources per Pod rather than additional replicas.<\/p>\n\n\n\n<p>You can also use HPA and VPA together, but avoid having both independently control the same CPU or memory resource in ways that conflict with each other.<\/p>\n\n\n\n<p><strong><em>Also read: <a href=\"https:\/\/www.guvi.in\/blog\/how-is-ai-transforming-devops\/\" target=\"_blank\" rel=\"noreferrer noopener\">How Is AI Transforming DevOps? Check 7 Intriguing Ways!<\/a><\/em><\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Kubernetes HPA Best Practices<\/strong><\/h2>\n\n\n\n<p>Following the right practices helps make Kubernetes autoscaling more reliable and predictable.<\/p>\n\n\n\n<ol>\n<li><strong>Set appropriate resource requests:<\/strong> Configure CPU and memory requests for containers so HPA can calculate resource utilisation accurately.<\/li>\n\n\n\n<li><strong>Define minimum and maximum replicas:<\/strong> Set suitable replica limits based on application capacity, availability requirements, and infrastructure resources.<\/li>\n\n\n\n<li><strong>Choose realistic scaling targets:<\/strong> Avoid setting CPU or memory targets without understanding your application&#8217;s normal resource consumption.<\/li>\n\n\n\n<li><strong>Configure scaling behaviour:<\/strong> Use stabilization windows and scaling policies to prevent unnecessary scaling up and down during short-lived traffic fluctuations.<\/li>\n\n\n\n<li><strong>Monitor application performance:<\/strong> Track CPU, memory, response times, errors, and application-level metrics to understand scaling effectiveness.<\/li>\n\n\n\n<li><strong>Test under realistic workloads:<\/strong> Perform load testing to determine whether your HPA configuration can handle expected traffic patterns.<\/li>\n\n\n\n<li><strong>Plan node capacity:<\/strong> Remember that HPA scales Pods, not worker nodes. If the cluster lacks capacity to schedule new Pods, use a node autoscaling solution such as Cluster Autoscaler alongside HPA.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Common Kubernetes HPA Issues and Troubleshooting<\/strong><\/h2>\n\n\n\n<p>Sometimes HPA may fail to scale applications as expected. Understanding common issues helps identify the problem quickly.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>Common issue<\/strong><\/td><td><strong>Possible reason<\/strong><\/td><td><strong>Troubleshooting command<\/strong><\/td><\/tr><tr><td>Unknown metrics<\/td><td>Metrics Server is unavailable<\/td><td>kubectl top pods<\/td><\/tr><tr><td>Pods not scaling up<\/td><td>Metrics are below target or Pods cannot be scheduled<\/td><td>kubectl describe hpa<\/td><\/tr><tr><td>CPU target not reached<\/td><td>CPU requests are too high or workload is not CPU-intensive<\/td><td>kubectl describe deployment<\/td><\/tr><tr><td>Metrics Server issues<\/td><td>Metrics API or kubelet communication failure<\/td><td>kubectl get apiservice v1beta1.metrics.k8s.io<\/td><\/tr><tr><td>Maximum replicas reached<\/td><td>HPA has reached maxReplicas<\/td><td>kubectl get hpa<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Here are some additional commands to investigate scaling problems:<\/p>\n\n\n\n<p><strong>Check HPA events:<\/strong><\/p>\n\n\n\n<p>kubectl describe hpa nginx-hpa<\/p>\n\n\n\n<p><strong>Check resource usage:<\/strong><\/p>\n\n\n\n<p>kubectl top pods<\/p>\n\n\n\n<p>kubectl top nodes<\/p>\n\n\n\n<p><strong>Check Metrics Server status:<\/strong><\/p>\n\n\n\n<p>kubectl get pods -n kube-system<\/p>\n\n\n\n<p><strong>Check application events:<\/strong><\/p>\n\n\n\n<p>kubectl get events &#8211;sort-by=.lastTimestamp<\/p>\n\n\n\n<p>Also verify that the target Deployment exists, its Pods have the required resource requests, and the metrics APIs are available.<\/p>\n\n\n\n<p>If the HPA reaches its maximum replica count, review whether the application needs a higher replica limit or whether the underlying infrastructure needs additional capacity.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p>Kubernetes HPA makes application scaling easier by automatically adjusting Pod replicas based on changing workloads. It helps developers maintain application availability, improve resource utilisation, and reduce the need for manual scaling.<\/p>\n\n\n\n<p>By understanding how Horizontal Pod Autoscaler works, configuring resource requests, choosing suitable scaling targets, and monitoring application metrics, you can build more reliable Kubernetes deployments.<\/p>\n\n\n\n<p>Learning Kubernetes autoscaling is also an important step towards managing production-ready containerised applications. With practical experience in Deployments, Services, HPA, and resource management, you can strengthen your DevOps skills and work more confidently with cloud-native environments.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Frequently Asked Questions (FAQs)<\/strong><\/h2>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1796323310352\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>1. What is Kubernetes HPA used for?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Kubernetes HPA is used to automatically increase or decrease the number of Pod replicas based on resource utilisation or configured metrics. It helps applications handle changing workloads efficiently.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1796323315972\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>2. How does Horizontal Pod Autoscaler work in Kubernetes?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>HPA periodically collects application metrics, compares them with configured targets, calculates the required replica count, and updates the target workload&#8217;s scale.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1796323331285\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>3. What metrics does Kubernetes HPA use?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Kubernetes HPA supports CPU utilisation, memory utilisation, custom application metrics, and external metrics. These metrics help determine when an application needs additional or fewer Pods.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1796323341906\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>4. What is the difference between HPA and VPA in Kubernetes?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>HPA changes the number of Pod replicas to handle changing workloads, while VPA adjusts CPU and memory resource requests for individual Pods.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Modern applications experience changing workloads throughout the day. An e-commerce application may receive thousands of requests during a sale, while traffic remains low during regular hours. Running the same number of application instances throughout these periods can waste resources or affect application performance. Kubernetes HPA (Horizontal Pod Autoscaler) helps solve this problem by automatically increasing [&hellip;]<\/p>\n","protected":false},"author":63,"featured_media":150796,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[621],"tags":[],"views":"57","authorinfo":{"name":"Vishalini Devarajan","url":"https:\/\/www.guvi.in\/blog\/author\/vishalini\/"},"thumbnailURL":"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/12\/k8s-pv-pvc-300x116.webp","_links":{"self":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/150665"}],"collection":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/users\/63"}],"replies":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/comments?post=150665"}],"version-history":[{"count":13,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/150665\/revisions"}],"predecessor-version":[{"id":150800,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/150665\/revisions\/150800"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media\/150796"}],"wp:attachment":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media?parent=150665"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/categories?post=150665"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/tags?post=150665"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}