How to Find an Optimal Set of Nodes for A Kubernetes Cluster
One of the most impactful ways to reduce spend on Kubernetes infrastructure is to make sure your clusters are optimally sized for the workloads they run.
Join the DZone community and get the full member experience.Join For Free
One of the most impactful ways to reduce spend on Kubernetes infrastructure is to make sure your clusters are optimally sized for the workloads they run. Working with many teams over the past year we have seen that it’s not so obvious how to arrive at an optimally-sized cluster, even in autoscaling environments. In response, we are publicly launching a new tool that we’ve used to help teams recently! While implementing this solution with users so far we’ve seen savings in the range of 25-60%, even having a major impact in autoscaling environments.
How It WorksPermalink
This new tool generates context-aware cluster sizing recommendations after analyzing Kubernetes metrics on historical workloads and cloud billing data. As a user, you only need to provide the context of the cluster, i.e. whether it is being used for development, production, or high-availability workloads. We then recommend cluster configurations, which optimize for the respective balance of cost, simplicity, and performance/headroom. Because this solution is Kubernetes native, we consider the following when providing recommendations:
- Analysis of historical pod/container resource consumption to predict future requirements.
- Consideration of both resource requests and usage.
- Ensuring the largest workloads can be scheduled successfully.
- Accounting for DaemonSet/kube-system replication requirements for each node.
- Allocating headroom based on cluster context, e.g., dev, prod, high availability.
- Avoiding shared core machines for production/HA environments.
How to Use
This tool is free to use and can be installed in minutes with Helm or a flat manifest. After installing Kubecost, then navigate to the Savings page and look for cluster right-sizing. You will see initial recommendations based on a “development” cluster context, but you can select a different cluster type to receive recommendations more customized to your situation.
The product supports clusters on both AWS and GCP today and begins collecting workload data as soon as it’s installed. Note: no data is egressed from your cluster with this product and everything runs with your infrastructure.
The following example presents two potential strategies in a Production cluster. There is a tradeoff between cost and complexity in this scenario. The simpler of the two configurations requires only a single node pool, but the multi-pool solution offers an additional 14% savings per month by bin packing resources more efficiently than otherwise possible with only one node type. Advanced metrics are available directly in the UI to better understand the rationale for these recommendations.
To generate accurate recommendations, a potential cluster must be adequately-sized such that it is possible to schedule all workloads on the cluster. To assess this requirement, workloads scheduled as DaemonSets must appear on each node, making total resource allocation a function of node count. Furthermore, one large workload may not be able to fit on a fleet of small nodes, even if the aggregate amount of resources would appear adequate. We are able to use metrics generated by the core Kubecost allocation model (open source) to calculate nth-percentile total resource allocation over time, the percentage attributed to DaemonSets, and the largest single workload.
As a function of the cluster context, e.g. dev or production, we then analyze the shape of historical resource consumption and apply the appropriate headroom budget. For development clusters, we look at the trending 85th percentile consumption, for production 98th, and HA 99.9th.
Beyond these requirements, we apply a heuristic to manage the tradeoff between cost and complexity. For example, many teams would agree that, given the choice between saving 30% with a simple option and saving 31% with an utterly complex one, the simple option sounds more attractive. Therefore, we’ve chosen to start with two implementation strategies instead of one, hence the recommendations in the aforementioned examples.
You might be wondering why cluster sizing can not be solved by autoscaling. In the time we’ve spent helping teams of all kinds optimize their Kubernetes environments, we’ve found that cluster autoscaling, while useful, does not always resolve right-sizing concerns. Consider that autoscaling, even when it is working, does not allow for the possibility of adding different node pools to a cluster. It’s still easy, therefore, to end up over-provisioning if the autoscaler’s single node type is inappropriate for the resource proportions of the given workload. Over-provisioning by an autoscaler can be a painful experience, whereas using the cluster sizing recommendation puts the control and information in your hands to right-size your cluster when the time is right, without fear of runaway costs due to a single resource spike, memory leak, or ill-fitting node type.
Published at DZone with permission of Webb Brown. See the original article here.
Opinions expressed by DZone contributors are their own.