<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Furkan Berber on Medium]]></title>
        <description><![CDATA[Stories by Furkan Berber on Medium]]></description>
        <link>https://medium.com/@furkanberber?source=rss-c1d4eb500986------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*1CXqcnas2WCKLC36.jpg</url>
            <title>Stories by Furkan Berber on Medium</title>
            <link>https://medium.com/@furkanberber?source=rss-c1d4eb500986------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 09:19:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@furkanberber/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[An Introduction to Kubernetes Horizontal Pod Autoscaler]]></title>
            <link>https://medium.com/kloia/an-introduction-to-kubernetes-horizontal-pod-autoscaler-2b3efc9ffbcf?source=rss-c1d4eb500986------2</link>
            <guid isPermaLink="false">https://medium.com/p/2b3efc9ffbcf</guid>
            <category><![CDATA[hpa]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[eng]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Furkan Berber]]></dc:creator>
            <pubDate>Wed, 04 Nov 2020 07:53:02 GMT</pubDate>
            <atom:updated>2020-11-04T08:29:37.404Z</atom:updated>
            <content:encoded><![CDATA[<p>One of the most praised things about Kubernetes is autoscaling. Most people are excited about the idea of scaling resources on demand without doing anything for it.</p><p>With Kubernetes, we can autoscale our resources natively with the<strong> Horizontal Pod Autoscaler</strong>. It works like a control-loop and queries some metrics. When it finds out that the queried metric is lower or higher than the threshold values we defined, it scales the resources up or down automatically. It does this by increasing the number of pods.</p><p><strong>HPA</strong> works great with <strong>Cluster Autoscaling</strong>. When increasing the number of pods isn’t enough to compensate for the increased traffic, then scaling the infrastructure by increasing the number of nodes would work.</p><p>However, Cluster Autoscaler may not be suitable for every tenant/workload because Cluster Autoscaler is offered by Cloud Providers, it’s not a native Kubernetes resource. That is, this functionality is not available for on-premise environments because you don’t have on-demand resources as you do in cloud environments. That’s why I’ll be explaining the <strong>HPA</strong> for you in this article. We’ll first go into details of <strong>HPA</strong> and then continue with a simple demo that shows HPA in action.</p><p><strong>How Does Horizontal Pod Autoscaler Work?</strong></p><p>HPA scales the number of pods bound to a replication controller, a replica set, a stateful-set or a deployment based on resource metrics. In the first release (with apiVersion: autoscaling/v1), these metrics were only per-pod metrics like CPU utilization. With the latest Kubernetes (with apiVersion: autoscaling/v2beta2 as of writing this) supports more options for metrics; per-pod metrics like Memory Utilization, Object metrics, or external metrics that can come from basically anywhere like Prometheus.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/0*2IaSf-K3gK5gO8XD.png" /></figure><p>For example, if you pick CPU Utilization as a metric and pick %50, then HPA will query the CPU utilization periodically using the metrics server (which is 15 seconds default) through the controller manager. Whenever these queries show more than %50 CPU utilization, HPA will increase the number of pods to meet with the given CPU utilization.</p><p><strong>When To Use Horizontal Pod Autoscaler</strong></p><p>A more important question is when to use HPA rather than how. The most appropriate use case for HPA would be preventing down-time and performance problems caused by unexpected traffic spikes. If you define your pod’s container resource requests and limits the right way, then HPA would be perfect to use for these situations because it works better than manually scaling deployments.</p><p>However, if you have a planned event which will create a big traffic spike, scaling manually before that event would probably make more sense because HPA is not working super fast to compensate for traffic spikes. The reason is HPA’s cooldown period. After a scale-out or in event, HPA will wait for some time, and then if needed it will continue scaling your resources.</p><p><strong>Demo</strong></p><p>Let’s make a small demonstration to see HPA in action. For this blog post, I’ve written a small Node.JS server and dockerized it for Kubernetes.</p><p>To create the deployment and service for this demo;</p><pre>apiVersion: autoscaling/v1 <br>kind: HorizontalPodAutoscaler <br>metadata: <br>  name: node-hpa <br>spec: <br>  maxReplicas: 10 <br>  minReplicas: 1 <br>  scaleTargetRef: <br>    apiVersion: apps/v1 <br>    kind: Deployment <br>    name: node-hpa <br>    targetCPUUtilizationPercentage: 50</pre><ul><li><strong>kubectl apply -f hpa.yaml</strong></li></ul><p>Now, we’ll apply some load to the Node.JS server;</p><ul><li><strong>kubectl run -it — rm load-generator — image busybox — /bin/sh</strong></li><li><strong>while true; do wget -q -O- </strong><a href="http://node-hpa:3000;"><strong>http://node-hpa:3000;</strong></a><strong> done-</strong></li></ul><p>After, waiting for a bit, we can see that the number of pods are increasing with either command;</p><ul><li><strong>kubectl get deployments</strong></li><li><strong>kubectl get pods</strong></li></ul><p>To see HPA activities, we can use the command;</p><p>After seeing that our deployment is scaled, we can remove the load generator by stopping the command on the load-generator pod.</p><p>Because of the cooldown period of HPA, the scale-in activity will probably take more time. After that, we’ll see that our deployment is scaled-in and the number of pods is decreased to the necessary amount.</p><p><strong>Conclusion</strong></p><p>In this blog post, we’ve seen what HPA is and it behaves. We have seen what HPA does for our scalable resources (which can be deployments, replica sets, replication controllers, and stateful sets) and how it increases or decreases the number of pods by comparing current metrics with given thresholds.</p><p>We covered use cases to use HPA and then did a small demo to see HPA in action. We reviewed scaling events with using kubectl.</p><p><em>Originally published at </em><a href="https://www.kloia.com/blog/kubernetes-horizontal-pod-autoscaler"><em>https://www.kloia.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b3efc9ffbcf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/kloia/an-introduction-to-kubernetes-horizontal-pod-autoscaler-2b3efc9ffbcf">An Introduction to Kubernetes Horizontal Pod Autoscaler</a> was originally published in <a href="https://medium.com/kloia">kloia</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>