123Line blog explosion

Lets find out whats going on in this world

Managing a Kubernetes cluster is a complex endeavor. As demands on a cluster grow, increasing the number of deployed pods can help ease the load on the system. But what do you do when you run out of nodes to host those pods, or when the load decreases and some nodes are no longer needed? Manually adding or removing nodes is possible, but wouldn’t it be better if there was a way to automate that task? Fortunately, that’s exactly what the Kubernetes Autoscaler charm is for! 

Types of Autoscalers

Before diving into the details of the Kubernetes Autoscaler charm, it’s important to understand the different types of autoscaling that are possible in Kubernetes. 

There are three types of autoscaling available: horizontal pod autoscaling, vertical pod autoscaling, and cluster autoscaling. 

Horizontal Pod Autoscaling

Horizontal pod autoscaling involves responding to changes in cluster load by adding and removing pods. As workload demand increases, more pods are added. If the demand slows down, pods are removed.

<noscript>
<img alt=”” src=”https://res.cloudinary.com/canonical/image/fetch/f_auto,q_auto,fl_sanitize,c_fill,w_720/https://lh6.googleusercontent.com/7niI3DV1JZKzDCpBs6_Z3oYHQQX-aP3sOFH6cNUjzH_4qWWZpLUdKfQM07_8QMfGeTh2HgV7qiBhWw8pKkIgmfntszYZP-eOXDz1OKNr91lWWyLSuoaH8Z22uCpwJhlQZZ98xM1Wa_MiAE-_ww” width=”720″ />
</noscript>

Horizontal Pod Autoscaling

Vertical Pod Autoscaling

Vertical pod autoscaling adjusts pod memory and CPU limits. When workload demand increases, the resource limits for a pod are increased. Similarly when the demand decreases, the resource limits are lowered. 

<noscript>
<img alt=”” src=”https://res.cloudinary.com/canonical/image/fetch/f_auto,q_auto,fl_sanitize,c_fill,w_720/https://lh6.googleusercontent.com/RpsOffcNuAd2ADxYUrLz_FFGlatsPWZ8v-Aic4DOA1foCP-3hM2YEL4lz8caPg4kQm8OWaB5uxGVWVNBjAAPhkAu1IIXGMIMi1ETMiz16SnC7PH3b48Mpu57lqmC8__JpwqfO2XGXzs512_Hmw” width=”720″ />
</noscript>

Vertical Pod Autoscaling

Cluster Autoscaling

Cluster autoscaling scales the cluster itself, adding nodes to accommodate unscheduled pods, and removing nodes when they become underutilized. 

<noscript>
<img alt=”” src=”https://res.cloudinary.com/canonical/image/fetch/f_auto,q_auto,fl_sanitize,c_fill,w_720/https://lh3.googleusercontent.com/YHjyyRV4-R3cDM5XcMCSbKI46WCRpUEQHEQunsfW0zV3QcV1Bv60htJIhLjaKg5caCUe8wrlHk6HcmOPUWmnTIUfXuYlei37wxvUsCccN38a-QpN6hROhmihjbiTZ5s2k-tsDcUliVS6fOpLVA” width=”720″ />
</noscript>

Cluster Autoscaling

The Kubernetes Autoscaler charm is a cluster autoscaler

Why would you want to use a cluster autoscaler?

Using a cluster autoscaler allows you to automatically resize your cluster, increasing the number of nodes to meet pod scheduling requirements. On the other hand, the autoscaler can also remove nodes that are not being used. This can save you money, as you can stop using machines that are no longer necessary. A cluster autoscaler can help you maintain a cluster that is just the right size for your current needs. 

How does the Kubernetes Autoscaler Charm work?

The Kubernetes Autoscaler charm is designed to run on top of a Charmed Kubernetes cluster. Once deployed, the autoscaler interacts directly with Juju in order to respond to changing cluster demands. Remember, cluster autoscaling involves adding and removing nodes, so when pods are unable to be scheduled, or if a node is not being fully utilized, the autoscaler charm uses Juju constructs to resolve these issues.

Scale up

When the scheduler is unable to find a node to place a pod on, it will mark that pod as unschedulable. The autoscaler watches for unschedulable pods, and responds by sending a request to Juju asking that a unit be added to the Kubernetes worker application. Juju then adds a unit resulting in a new node being added to the cluster. The pod can then be scheduled on the new node. Problem solved!

<noscript>
<img alt=”” src=”https://res.cloudinary.com/canonical/image/fetch/f_auto,q_auto,fl_sanitize,c_fill,w_720/https://lh6.googleusercontent.com/Tswy1bHkhZKJJ75JWqF3oovt-qlGO8IYhkGAST85E3c0d6aTBjdbswSpSB5THwX-DW2JwMJ5y-3iqQARqgyL1IX16mBU-uw0kc3AEXZaGK24eU_NZJHqMY_KJIgH30e4Xq5wkUWVa9-TVwrzSw” width=”720″ />
</noscript>

Scale Up Process

Scale down

The autoscaler periodically checks to see if any nodes are being underutilized. If it finds an underutilized node, it will attempt to move all the pods currently running on that node to other nodes. Once the node is empty, the autoscaler sends a remove-unit request to Juju to remove the now-empty node. Juju removes the unit from the worker application, which results in the node being removed from the cluster. 

<noscript>
<img alt=”” src=”https://res.cloudinary.com/canonical/image/fetch/f_auto,q_auto,fl_sanitize,c_fill,w_720/https://lh5.googleusercontent.com/FOk33AFBTpfeS5JjGyYR9gNGaFX0GuNRlT08LV6P1SiM57LFARdOUsPLCGsmociiVZrDu2TinBUrXh5CafOhRHrnGkTHP2xaOk1i1xIPqdIpZ-AqDt41Fuc-GrSBWhz4bilfQthuxg74ubNoxg” width=”720″ />
</noscript>

Scale Down Process

Wrapping up

Autoscaling is a complicated topic, but now you know a little more about the different types of solutions available. You also learned how the Kubernetes Autoscaler charm can solve some of the common problems associated with responding to changing cluster demands, and gained insight into how the autoscaler charm works internally.  

Demo

What next

  • Read the docs to learn how to deploy and configure the Kubernetes Autoscaler charm
  • Deploy the autoscaler charm from Charmhub

Subscribe Our Newsletter.

What is more interesting is if you find out about  all the existing new things we are up to