<?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 Maximiliano Curia on Medium]]></title>
        <description><![CDATA[Stories by Maximiliano Curia on Medium]]></description>
        <link>https://medium.com/@maximiliano.curia?source=rss-8d30a7de8cec------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*B_GCeLK1fB7xxllWu6sWlg.jpeg</url>
            <title>Stories by Maximiliano Curia on Medium</title>
            <link>https://medium.com/@maximiliano.curia?source=rss-8d30a7de8cec------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 19:27:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@maximiliano.curia/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[Deploying Kubernetes — Understanding the Horizontal Pod Autoscaler]]></title>
            <link>https://medium.com/@maximiliano.curia/deploying-kubernetes-understanding-the-horizontal-pod-autoscaler-e9cb9abec5bb?source=rss-8d30a7de8cec------2</link>
            <guid isPermaLink="false">https://medium.com/p/e9cb9abec5bb</guid>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[autoscaling]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Maximiliano Curia]]></dc:creator>
            <pubDate>Sat, 04 Apr 2020 12:45:24 GMT</pubDate>
            <atom:updated>2020-04-04T12:45:24.619Z</atom:updated>
            <content:encoded><![CDATA[<h3>Deploying Kubernetes — Understanding the Horizontal Pod Autoscaler</h3><p>One of the key features of Kubernetes is that it comes with built-in systems to automatically scale our services up and down to match demand. You can scale your pods vertically (making each of the pods bigger) or horizontally (starting more replicas for the same service). In this post, I’ll talk about the caveats that we need to take into account when using the Horizontal Pod Autoscaler, or HPA.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0SI829aqDiP30rsR" /><figcaption><a href="https://www.flickr.com/photos/robdammers/40789438024">Photo by Rob Dammers on Flickr</a></figcaption></figure><p>The basic principle of the HPA is that it will start up more replicas of a service when there’s high demand and turn some off when there’s low demand. This basic principle is easy to understand, but it can be tricky to get the configuration right, there’s a bunch of numbers involved and it might not be immediately apparent what each of those numbers do. Let’s go step by step.</p><p>How does the HPA know that it needs to scale the number of replicas? It uses metrics. There’s currently two built-in metrics: CPU and memory usage. We can also define our own custom or external metrics, but in this post I focus on the built-in ones.</p><p>When we configure a deployment in Kubernetes, we state how much CPU and memory each pod should be allocated using the <em>requests</em> field. The numbers to choose will depend on the application we’re running. When first launching an application, we’ll usually start by setting some estimated values and then adjust them once we see how the app performs in reality.</p><p>Once the pods start serving, they’ll use some amount of CPU and memory which might be more or less than the requested values. If we’ve set up Horizontal Pod Autoscaling, the autoscaler will look at all the pods in the deployment, sum up the current usage of CPU and memory and then divide that sum by the requested amount, to obtain the current overall <strong><em>utilization</em></strong>:</p><blockquote>currentUtilization = metricsTotal * 100 / requestedTotal</blockquote><p>Say our deployment has 5 replicas, with 120 mCPUs of requested CPU each, and they are currently using a total of 440 mCPU. This means that the current utilization is 440 * 100 / (5 * 120) = 73. In other words, these pods are using 73% of the requested CPU allocation.</p><p>Now, the HPA needs to decide whether to scale the deployment up or down. To do that, it will use another value that we configure when we set up the HPA for our deployment: the <strong><em>target utilization</em></strong>. This number is the percentage of utilization of the requested resources that we want to aim for, it’s typically set at 80% or 90%, the actual setting will depend on the specifics of your deployment. Dividing the current utilization by this target utilization gives us the current <strong><em>usage ratio</em></strong>:</p><blockquote>usageRatio = currentUtilization / targetUtilizatio<em>n</em></blockquote><p>For the example above, if we set targetUtilization to 80, usageRatio would be 73 / 80 = 0.9125. What does the HPA do with this number? If it’s within a tolerance value of 1, it does nothing and leaves the amount of replicas as is. The tolerance value is set to 0.1 by default and depending on the way you’re deploying Kubernetes, you might not be able to change it.</p><blockquote>if 0.9 &lt;= usageRatio &lt;= 1.1: keep current replica amount</blockquote><p>So, for our example it would just keep the 5 replicas that we had. Now, a few minutes later the load might be different. What if the next time the HPA looks at our metrics the total usage is 380 mCPU? In that case, the currentUtilization would be (380 * 100) / (5 * 120) = 63.3333. And the usageRatio would be 63.3333 / 80 = 0.7917</p><p>This would now be below the tolerance range, so the HPA would check whether it needs to modify the amount of replicas. To do that, it takes the usageRatio value, multiplies it by the current amount of replicas and then rounds the number up:</p><blockquote>newReplicas: ceil(usageRatio * currentReplicas)</blockquote><p>In our example, this would be 0.63333 * 5 = 3.9583, which rounded up is 4. So, the HPA would decide to turn one of the pods off. Once the pod is turned off, the requested CPU allocation will go down by one pod. Assuming the load stays the same, that would be: (380 * 100) / (4 * 120) = 79.1666. When dividing this by the target utilization of 80, we get 0.9895 which is within the tolerance range. Our deployment would keep this number of replicas until the load changes significantly in one direction or the other.</p><p>If you want to look at these formulas and the surrounding source code yourself, you can check out the <a href="https://github.com/kubernetes/kubernetes/blob/master/pkg/controller/podautoscaler/metrics/utilization.go#L26">podautoscaler/metrics/utilization.go</a> and the <a href="https://github.com/kubernetes/kubernetes/blob/master/pkg/controller/podautoscaler/replica_calculator.go#L64">podautoscaler/replica_calculator.go</a> files.</p><p>The following graph shows how the HPA would respond to ups and downs in the total usage of a resource. When a new pod gets started the total requested goes up, and when it gets turned off, it goes down.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ydqGisnYXIe4Pz-D" /></figure><p>The example above uses a requested size of 120 mCPU and a target utilization of 80%. Because of the 80% value, there’s usually a gap between how much was requested and how much is actually in use. Except when the increase goes so quickly that the new pod isn’t up yet.</p><p>What does this mean? Even if it’s quite fast, starting up a pod takes time. The binary needs to be loaded, the application started, and then all the necessary data needs to be in memory before the pod is fully ready to respond to incoming requests. This might take more or less time depending on the application, but it’s never instantaneous.</p><p>So, the current set of pods needs to be able to handle a small spike in requests until the new pod is ready to serve. This is why we typically don’t have the target utilization at 100%: having it at 80% or 90% gives our pods some leeway in still being able to respond to requests when demand is increasing.</p><h4>Deciding the numbers to set</h4><p>You might be wondering, how do I know which numbers to set? How do I decide the right sizes of the requested fields and the target utilization? Each application will be different, so you’ll need to monitor the system. Check out what are the minimum and maximum loads your system sees, and how they vary throughout the day or the week.</p><p>In <a href="https://medium.com/@maximiliano.curia/deploying-kubernetes-deciding-the-size-of-your-nodes-a115e770e09">my previous post</a>, I looked into the criteria for deciding the size for the nodes in the cluster. I mentioned that we want our nodes to be big enough that the management overhead doesn’t end up taking too much space and that we can fit many pods in them. How many pods we can fit will depend on the sizes and requirements of those pods.</p><p>When deciding the size of our pods, we want to find the right balance between making them small enough that we can fit a bunch of them in our nodes and making them big enough that they can handle small variations in demand. As I mentioned earlier, we’ll start with estimating the sizes and then progressively adjust those estimates to better fit the reality we see through our monitoring system.</p><p>If you want your service to have <em>high-availability</em>, i.e. be resilient to failures in one zone of your cluster, you’ll want to set your deployment to have a minimum amount of replicas, between 3 and 5 probably makes sense. That way, if a node goes down, the service can stay up thanks to the pods running in other nodes, which will handle the current load until a new pod gets started and added to the deployment.</p><p>On top of the minimum amount of replicas, you’d then use the HPA to ensure that the size of the deployment grows as needed when demand increases. And don’t forget to set a maximum to avoid overspending in case of a <em>Denial of Service</em>.</p><h4>A note about the different metrics available</h4><p>I’ve mentioned that you can set the target utilization for both CPU and memory. So, how do these two get combined? The HPA calculates the desired amount of replicas for each metric independently, and then takes the <strong>maximum</strong> value.</p><p>Depending on the applications your deployments are running, you might want to choose only CPU, only memory, or both.</p><p>In many web applications the CPU usage pretty much tracks the amount of requests your pod is getting. The more requests being served, the more CPU that gets used. If that’s the case for your app, it probably makes sense to use CPU as your metric for autoscaling.</p><p>If you’re going to use memory for autoscaling, there’s a few caveats to take into account. First, you need to consider that just having the application running will use a baseline of memory. This baseline needs to be well below the target utilization, or the autoscaler will never shutdown your pods, even if they are idle.</p><p>On top of this, you need to consider how your application handles the memory it uses. For example, some applications may use more and more memory until the garbage collector makes it go down. If your application behaves like that, you might end up with a bunch of pods getting launched (and not really used) until the garbage collector does its job.</p><p>Other applications may have very short-lived spikes of memory usage (for example, if some specific request uses a lot of memory, but most requests don’t). This might lead to pods getting launched when the spike triggers and then shutdown immediately afterwards without really being useful.</p><p>So, when should you use memory as your target? When the memory used by your pod tracks the amount of work your pod is doing. This could be for example if your application is starting a new thread for each new request, and these threads aren’t doing a lot of compute work, but taking memory space.</p><h3>About me</h3><p>I’ve been an open source developer for a long time, I’ve maintained KDE packages for the Debian GNU/Linux distribution, and I’ve had the opportunity to work with a broad array of open source projects.</p><p>The field of IT keeps growing and getting more complex, so of course over all these years I’ve kept expanding my knowledge. I’ve learnt about monitoring tools like Prometheus, infrastructure as code tools like Helm or Terraform, or continuous integration tools like Jenkins and GitLab’s CI.</p><p>In the past few months, I’ve started working with a few different clients, helping with their Cloud deployments. I’ve been able to help them optimize existing Kubernetes deployments, and also set up Kubernetes starting from scratch.</p><p>Is your company thinking about moving to the Cloud but in need of an expert to help them along with the deployment? If yes, I could be the help you need! Feel free to <a href="https://www.linkedin.com/in/mcuria/">contact me</a> for more information.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e9cb9abec5bb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploying Kubernetes — Deciding the size of your nodes]]></title>
            <link>https://medium.com/swlh/deploying-kubernetes-deciding-the-size-of-your-nodes-a115e770e09?source=rss-8d30a7de8cec------2</link>
            <guid isPermaLink="false">https://medium.com/p/a115e770e09</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Maximiliano Curia]]></dc:creator>
            <pubDate>Tue, 24 Mar 2020 14:11:22 GMT</pubDate>
            <atom:updated>2020-04-20T18:37:16.076Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-sa/4.0/</cc:license>
            <content:encoded><![CDATA[<h3>Deploying Kubernetes — Deciding the size of your nodes</h3><p>If you’ve already gone through the process of moving some workloads from your on-premise infrastructure to the Cloud, you probably already know that in the Infrastructure as a Service model, you pay for the amount of compute power that you deploy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Z3h-xLZOseU87chp" /><figcaption>Photo by<a href="https://www.pexels.com/@quang-nguyen-vinh-222549?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels"> <strong>Quang Nguyen Vinh</strong></a> from<a href="https://www.pexels.com/photo/two-cargo-ships-sailing-near-city-2144905/?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels"> <strong>Pexels</strong></a></figcaption></figure><p>When using virtual machines to replace on-premise infrastructure it’s pretty typical to try to use the cheapest machine possible. This mindset works fine when each VM is in charge of one service. You choose the smallest machine that can fit your workload to avoid paying for resources you won’t use.</p><p>This plays out differently when we move to Kubernetes. In Kubernetes, we have a cluster of nodes (virtual machines) where we run a bunch of pods, supporting different services. The key advantage is that we can easily scale the amount of pods assigned to each service depending on current demand. More demand means more pods, and less demand means less pods. The applications running inside those pods don’t care in which nodes they are running, as long as they have access to the resources they need.</p><p>This gives us a lot of flexibility, but of course there is a cost: on each of the nodes in the cluster there’s some management overhead using part of the CPU and memory assigned to that VM. This is done through additional pods running on those nodes. When deciding the size of our nodes, we need to account for the resources that the management pods will use.</p><p>Another cool thing is that it’s possible to configure the amount of nodes in our cluster to scale automatically. If this is enabled, new nodes will get deployed when a new pod needs to be launched but there isn’t enough capacity for it.</p><p>The unexpected consequence of this is that if we go with the cheapest VMs available, we might end up running <strong>a lot of</strong> nodes. With a significant portion of each of the nodes dedicated to running the Kubernetes management layer. This can quickly add up to a lot of wasted resources.</p><h4>Management overhead for an idle single-node cluster</h4><p>Let’s look at an example. Say you’re deploying a Kubernetes cluster on GKE, and you choose n1-standard-1 as the machine type for your nodes (the current default type in GKE, and one of the cheapest available). This machine type comes with 1 vCPU and 3.75 GB of RAM.</p><p>The overhead used by Kubernetes depends on a bunch of factors, like how many nodes are in the cluster, how many pods are running on those nodes, what kind of workloads you’re generating, and so on. In a cluster of single idle node (no other pods) the Kubernetes management layer requests 642 mCPU (milliCPU).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/0*IqYh8bgr5EZoXDI_" /></figure><p>Note that while the machine selected has 1 CPU, only 940 mCPU can be used. The rest is not available due to how the infrastructure works. You might wonder, what is it that’s requesting all those milliCPUs? Is it really necessary? We can list the running pods to find out:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/0*5L3eKD2eiFL1GdoF" /></figure><p>If you’re new to Kubernetes this probably doesn’t tell you much. These are the services that are enabled by default when creating a Kubernetes cluster in GKE. While your first desire might be to disable some of these services, that’s not really the point. The point is that this management layer is useful, because it’s what brings a lot of the Kubernetes magic, but <strong>we need to account for it</strong>.</p><p>If you’re trying to save on resources and run a cluster like this one, with one node of 1 vCPU, you’ll only be able to schedule a few pods until you need an additional node. By default, pods request 100 mCPU, and the management layer is using 642 mCPU out of 940 mCPU allocatable. This means that you’ll be able to fit 2 pods of the default size and then you’ll need a whole extra node to fit the next pod.</p><p>You could, instead, select machines of type e2-standard-2 for your cluster. These machines come with 2 vCPUs and 8 GB of memory. The management overhead will be exactly the same (642 mCPU for a single node cluster) but because the nodes are bigger you’ll have space for 12 pods of the default size before you need to add an extra node to your cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/0*MWwrysgix1HpAWyo" /></figure><p>As of March 2020, a n1-standard-1 machine costs $24.27 per month while a e2-standard-2 costs $48.92. This means that by changing the machine type, you can run 6 times more pods for the price of two n1-standard-1 machines.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/0*9oGJwBgDHGtLPVxL" /></figure><h4>Management overhead for an idle 3-node cluster</h4><p>Running a Kubernetes cluster of a single node is not recommended (for reasons that are not in the scope of this post). In GKE, the default size is 3. So, let’s look at the usage in an empty cluster of 3 nodes of n1-standard-1 nodes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/966/0*kpaPOfrPkv0t0IjF" /></figure><p>The numbers are different because not all services need to run in all nodes. While none of the nodes reached the 641 mCPU requested in our previous example, the total is now 1304 mCPU or 1.3 CPU. This cluster is allocating more than 1 full node of processing power, just for the management overhead.</p><p>In the one-node example, the management layer was requesting 68% of the allocatable CPU. In this case, it’s 46%. While this is slightly better, it’s still a lot. In general, we want to keep the management layer using less than 20% of our infrastructure.</p><p>This cluster will be able to run 14 pods of the default size before we need to add an extra node. Depending on your use case, this might be ok, especially if you’re just starting to experiment with Kubernetes.</p><p>But once you start running more workloads on your cluster, you’ll need resources to run more and more pods. This means that the number of nodes needed will keep growing, and everytime you deploy a new node, some portion of it will be used for the management layer, spending more of the money you were trying to save.</p><p>Once again, replacing these nodes with bigger ones lets you run a lot more workloads without adding more overhead. Using the e2 machines mentioned in the previous example, the cluster would be able to run 44 pods of the default size before needing an extra node. So, over three times as many pods, paying only two times the price.</p><h4><strong>Not all pods are created equal</strong></h4><p>The examples up to now have shown idle clusters because it’s easier to see and understand the management overhead when there are no other workloads. And I measured the available capacity of the clusters using pods of the default size (100 mCPU).</p><p>Of course, in real life you won’t set up a Kubernetes cluster just to keep it idle, the management overhead will take up more resources when the cluster is being used. But more importantly, your pods will be of many different sizes. Some may require a lot of CPU, others may require very little CPU but a lot of memory, and so on.</p><p>What does this mean for the size of your nodes? You’ll want to make sure that you can fit many of your pods in each node. If you’re running large pods in small nodes, you might be leaving a lot of processing power and memory unused, because when you need to scale your deployment, the additional pod doesn’t fit in the available nodes and a new node needs to be spawned.</p><p>Say you’re running a bunch of pods with Node.js applications. Some of these applications may need quite some processing power, 400 mCPU would be pretty typical. If the nodes in your cluster are n1-standard-1 (with only 1 vCPU), 400 mCPU is more than half of what’s left available for pods to allocate. This means that you won’t be able to fit more than one pod like this in each node, leaving a lot of unused resources. If the nodes are double the size, you’ll be able to fit 3 of these 400 mCPU pods, and resources will be better utilized.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/590/1*H3BYLzG9ye2rgK0_KOcyzw.png" /></figure><p>I recently helped one of my clients go through a transition like this. The original cluster was using 30 n1-standard-2 nodes ($48.55 per month), which have 2 vCPUs and 7.5GB of RAM. The nodes were severely underutilized because many of the pods were big, which meant a bunch of the nodes were running <strong>a single pod each</strong>. A lot of resources were going unused, but the client was still paying for them.</p><p>So, we decided to migrate to a cluster based on c2-standard-4 nodes ($121.94 per month), which have 4 vCPUs and 16 GB of RAM (and use processors that are compute-optimized). While the new resource size is about double the original one, having bigger nodes meant that we were wasting less resources in management overall, and that a single node could fit a bunch of different pods, including a couple of the bigger ones. This let us run the same workloads on just 6 large nodes instead of 30 of the smaller ones. This meant that switching to the larger nodes meant spending $730 per month instead of $1450.</p><blockquote>Yes, that’s right. <strong>Spending more per node meant spending less overall, because the resources were better utilized</strong>.</blockquote><h4><strong>Final words</strong></h4><p>When trying to determine the size of the nodes in your cluster, my recommendation is to assess your minimal resource usage and aim to cover it with 5 to 6 “large” nodes. This way, adding an extra node means 20% or less added expenses while letting your nodes still be flexible enough to run many pods of different sizes.</p><h4>About me</h4><p>I’ve been an open source developer for a long time, I’ve maintained KDE packages for the Debian GNU/Linux distribution, and I’ve had the opportunity to work with a broad array of open source projects.</p><p>The field of IT keeps growing and getting more complex, so of course over all these years I’ve kept expanding my knowledge. I’ve learnt about monitoring tools like Prometheus, infrastructure as code tools like Helm or Terraform, or continuous integration tools like Jenkins and GitLab’s CI.</p><p>In the past few months, I’ve started working with a few different clients, helping with their Cloud deployments. I’ve been able to help them optimize existing Kubernetes deployments, and also set up Kubernetes starting from scratch.</p><p>Is your company thinking about moving to the Cloud but in need of an expert to help them along with the deployment? If yes, I could be the help you need! Feel free to <a href="https://www.linkedin.com/in/mcuria/">contact me</a> for more information.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a115e770e09" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/deploying-kubernetes-deciding-the-size-of-your-nodes-a115e770e09">Deploying Kubernetes — Deciding the size of your nodes</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>