Guide
Chapter 4 - Karpenter Consolidation
Consolidation is a key feature in Karpenter that sets it apart from the traditional cluster autoscaler. Understanding how it fits into the broader Karpenter framework is crucial for fully leveraging Karpenter’s capabilities to optimize workload management on Kubernetes clusters.
This article starts with the basics, explaining core concepts like node provisioning, scheduling, and disruption management. It then covers how consolidation works within Karpenter to make resource allocation more efficient and reduce waste. Finally, we have provided a real-life example to show how an AI startup can use these tools to its advantage.
Karpenter is an advanced Kubernetes node autoscaler that optimizes the use of cloud resources through dynamic provisioning. It is designed to respond quickly to changes in workload demands by adjusting the number of nodes in a cluster. In order to achieve that, Karpenter employs specific approaches to node provisioning, scheduling, and disruption. Let’s review them.
Unlike traditional autoscalers, Karpenter proactively assesses application needs and cluster states to provision nodes. This dynamic provisioning can be configured using NodePools and NodeClass CRDs, which are essential elements in Karpenter’s architecture.
NodePools allow you to define groups of nodes with specific characteristics and scaling behaviors. Some example scenarios may include:
NodeClasses, on the other hand, define specific configurations, like instance storage(e.g., EBS volumes) and OS settings for the nodes within a NodePool.
Effective node orchestration requires mechanisms for scheduling and disruption to maintain cluster health and efficiency. Karpenter introduces several concepts to manage these aspects:
Disruption is one of the most sophisticated features of Karpenter, so let’s dive into it. Karpenter employs a variety of disruption methods to manage node lifecycles within a Kubernetes cluster. These methods fall into two distinct categories: manual and automated.
These involve direct administrator actions, such as manually deleting nodes or NodePools using kubectl:
Additionally, Karpenter enhances the standard manual disruption process in Kubernetes by introducing additional features that ensure thorough cleanup and resource management.
These improvements make Karpenter's manual disruption methods more effective and reliable, providing a seamless and cleaner node management experience.
Automated methods are managed by Karpenter itself. These automated processes ensure that nodes are cycled out in accordance with cluster policies and workload demands without constant human intervention. They include:
Now, let’s review how these methods are prioritized and applied within the system to maintain optimal cluster operations.
Initially, Karpenter evaluates nodes for any manual disruption commands; if none are found, it proceeds with automated disruptions based on the cluster’s configuration and current state. Then Karpenter disrupts nodes by executing one automated method at a time in this order: expiration, drift, and consolidation.
If interruption handling is enabled, Karpenter will watch for upcoming involuntary interruption events that would cause disruption to workloads. These interruption events include:
Karpenter uses consolidation as a strategy to reduce costs and optimize resource allocation within a Kubernetes cluster. This process involves assessing and reallocating nodes based on current demand to enhance efficiency. Within consolidation, Karpenter employs deletion and replacement techniques, prioritizing actions that least disrupt ongoing workloads.
Consolidation employs three different strategies designed to identify potential consolidation actions:
Node consolidation in Karpenter assesses various aspects of the cluster’s current state to optimize resource usage and reduce cloud costs.
This decision-making process is influenced by several key criteria:
Nodes with low utilization and fewer critical pods are prime candidates for consolidation. This ensures that resources are allocated where they are most needed, maintaining cluster efficiency.
Pod disruption budgets define the minimum number of pods that must remain running during voluntary disruptions. Karpenter respects these budgets, carefully evaluating which nodes can be consolidated without violating these constraints.
In addition to a standard PDB in Kubernetes, Karpenter introduces the extended tuning of disruption strategies, specifically targeting NodePools with its own disruption budget settings.
Disruption budgets within NodePools allow for more granular control over how nodes within these pools are disrupted. When Karpenter considers node termination, it evaluates the node’s association with its NodePool and adheres to the disruption budgets defined for that pool. This means that even if a node individually could be terminated without violating a pod-specific PDB, it might still be retained if its removal would breach the NodePool’s disruption budget.
The discussions that follow show how disruption control works on the pod and the node levels.
To ensure that certain pods remain uninterrupted, you can apply the annotation karpenter.sh/do-not-disrupt: "true"
to the pod. The example would look like this:
apiVersion: v1
kind: Pod
metadata:
name: your-pod-name
annotations:
karpenter.sh/do-not-disrupt: "true"
spec:
containers:
- name: your-container-name
image: your-container-image
This informs Karpenter not to voluntarily terminate a node that hosts these marked pods, making it ideal for processes that require running from start to completion without interruptions. This functionality is not limited to pods, but it can also be applied to other workload management resources like Deployments and StatefulSets.
Karpenter starts by counting the active nodes in a NodePool. It ignores nodes that are being deleted or aren't ready. Karpenter won't disrupt any nodes if the amount of nodes already deleted or unready exceeds a budget.
If a NodePool has multiple disruption limits, Karpenter uses the strictest one. We can use percentages or fixed numbers for setting limits on disruptions:
By default, Karpenter will use one disruption budget with 10%. This can be configured using spec.disruption.budgets
in NodePool. Budgets take into account any nodes that are currently being terminated for any reason. They specifically prevent Karpenter from stopping nodes due to expiration, lack of use, drift, or consolidation.
Let’s review how what we’ve discussed so far can be applied in practice.
Imagine an AI startup that is leveraging Karpenter to manage nodes for its Kubernetes environment. Based on the nature of the workloads, the architecture team created a design with three different node pools to cover the company’s needs. Each NodePool would leverage a different consolidation strategy to balance satisfying application needs and cost constraints.
Here’s a summary of the NodePools:
Let’s now look at each of these in more detail.
This configuration allows the NodePool to react quickly to changing demands, optimizing resource allocation quickly, which is crucial for maintaining high performance and operational efficiency in environments with highly variable data processing needs.
The layout of the NodePool manifest is as shown below:
apiVersion: karpenter.sh/v1beta1
kind: NodePool
metadata:
name: adaptive-demand-nodepool
spec:
disruption:
consolidationPolicy: WhenUnderutilized
budgets:
- nodes: "25%" # Allows flexibility to disrupt up to 25% of nodes under fluctuating demand
reasons:
"Empty"
"Drifted"
- nodes: "3" # Ensures no more than 3 nodes can be disrupted at any one time
reasons:
"Empty"
"Drifted"
- nodes: "40%" # Extended allowance during anticipated low-demand periods
reasons:
"Underutilized"
duration: 4h
schedule: "0 4 * * *" # Scheduled during typical low-demand hours at 4 AM
- nodes: "0"
duration: 8h
schedule: "0 9 * * 1-5" # Prevents disruptions during peak business hours from 9 AM to 5 PM on weekdays
Explanation:
This configuration maximizes the financial efficiency of the NodePool by adjusting to both performance needs and cost considerations, which is particularly useful in continuous, high-demand environments like AI/ML data processing.
The layout of the NodePool manifest is as shown below:
apiVersion: karpenter.sh/v1beta1
kind: NodePool
metadata:
name: cost-performance-optimized-nodepool
spec:
disruption:
consolidationPolicy: WhenUnderutilized
budgets:
- nodes: "30%" # Allows up to 30% of nodes to be disrupted during low-cost periods
reasons:
"Empty"
"Drifted"
- nodes: "5" # Maximum of 5 nodes can be disrupted at any given time
"Empty"
"Drifted"
- nodes: "40%" # Extended budget during off-peak hours for further cost savings
reasons:
"Underutilized"
duration: "6h"
schedule: "0 1 * * *" # Scheduled during the lowest cost hours at 1 AM
- nodes: "0"
schedule: "@daily"
duration: "10m" # Prevents any disruptions during the first 10 minutes of each day
Explanation:
This setup is designed to optimize node usage around a predictable training schedule, reducing resources when they are not needed and preparing them just in time for scheduled training tasks, providing robust support during active training periods and minimizing costs during downtime.
apiVersion: karpenter.sh/v1beta1
kind: NodePool
metadata:
name: time-based-model-training-nodepool
spec:
disruption:
consolidationPolicy: WhenUnderutilized
expireAfter: 720h # Nodes expire after 30 days
budgets:
- nodes: "20%" # Allows disruptions of up to 20% of nodes under normal operations
- nodes: "0"
duration: "1h"
schedule: "55 23 * * *" # Prevent disruptions 5 minutes before midnight, preparing for night tasks
- nodes: "0"
duration: "2h"
schedule: "0 7 * * *" # Prevent disruptions at 7 AM, post night tasks to retain results
- nodes: "0"
duration: "2h"
schedule: "0 18 * * *" # Prevent disruptions at 6 PM when evening tasks begin
Explanation:
Karpenter’s consolidation feature is a powerful tool for managing Kubernetes clusters more efficiently, particularly when it comes to optimizing resource allocation and reducing unnecessary expenses. By integrating node provisioning, scheduling, and disruption management with advanced consolidation techniques, Karpenter offers a robust solution for dynamic resource management.
The example with the AI startup illustrates just how impactful these capabilities can be in a practical setting, demonstrating that Karpenter is not just about maintaining performance but also about enhancing operational efficiency in real-world applications. This makes it an invaluable tool for any organization looking to intelligently optimize its cloud infrastructure.
We use cookies to provide you with a better website experience and to analyze the site traffic. Please read our "privacy policy" for more information.