Skip to content

Commit 6325a08

Browse files
authored
Document overprovisioning for node autoscaling (#46635)
* Documented overprovisioning for node autoscaling * Migrate to task page and refactors the steps * traverses to task path * updates task for configuration * adds the configs steps * adds resources to examples dir and refactors the tasks * updates the deployment with Pod Anti-Affinity rules * fixes the indentation * removed index, transformed the deployment priority class and changed the section * reformated the docs act docs standard
1 parent 0b5fbbe commit 6325a08

File tree

4 files changed

+160
-0
lines changed

4 files changed

+160
-0
lines changed

content/en/docs/concepts/cluster-administration/cluster-autoscaling.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,4 @@ in the cluster.
115115
## {{% heading "whatsnext" %}}
116116

117117
- Read about [workload-level autoscaling](/docs/concepts/workloads/autoscaling/)
118+
- Read about [node overprovisioning](/docs/tasks/administer-cluster/node-overprovisioning/)
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
---
2+
title: Overprovision Node Capacity For A Cluster
3+
content_type: task
4+
weight: 10
5+
---
6+
7+
8+
<!-- overview -->
9+
10+
This page guides you through configuring {{< glossary_tooltip text="Node" term_id="node" >}} overprovisioning in your Kubernetes cluster. Node overprovisioning is a strategy that proactively reserves a portion of your cluster's compute resources. This reservation helps reduce the time required to schedule new pods during scaling events, enhancing your cluster's responsiveness to sudden spikes in traffic or workload demands.
11+
12+
By maintaining some unused capacity, you ensure that resources are immediately available when new pods are created, preventing them from entering a pending state while the cluster scales up.
13+
14+
## {{% heading "prerequisites" %}}
15+
16+
- You need to have a Kubernetes cluster, and the kubectl command-line tool must be configured to communicate with
17+
your cluster.
18+
- You should already have a basic understanding of
19+
[Deployments](/docs/concepts/workloads/controllers/deployment/),
20+
Pod {{<glossary_tooltip text="priority" term_id="pod-priority">}},
21+
and [PriorityClasses](/docs/concepts/scheduling-eviction/pod-priority-preemption/#priorityclass).
22+
- Your cluster must be set up with an [autoscaler](/docs/concepts/cluster-administration/cluster-autoscaling/)
23+
that manages nodes based on demand.
24+
25+
<!-- steps -->
26+
27+
## Create a placeholder Deployment
28+
29+
Begin by defining a PriorityClass for the placeholder Pods. First, create a PriorityClass with a
30+
negative priority value, that you will shortly assign to the placeholder pods.
31+
Later, you will set up a Deployment that uses this PriorityClass
32+
33+
{{% code_sample language="yaml" file="priorityclass/low-priority-class.yaml" %}}
34+
35+
Then create the PriorityClass:
36+
37+
```shell
38+
kubectl apply -f https://k8s.io/examples/priorityclass/low-priority-class.yaml
39+
```
40+
41+
You will next define a Deployment that uses the negative-priority PriorityClass and runs a minimal container.
42+
When you add this to your cluster, Kubernetes runs those placeholder pods to reserve capacity. Any time there
43+
is a capacity shortage, the control plane will pick one these placeholder pods as the first candidate to
44+
{{< glossary_tooltip text="preempt" term_id="preemption" >}}.
45+
46+
Review the sample manifest:
47+
48+
{{% code_sample language="yaml" file="deployments/deployment-with-capacity-reservation.yaml" %}}
49+
50+
Create a Deployment based on that manifest:
51+
52+
```shell
53+
kubectl apply -f https://k8s.io/examples/deployments/deployment-with-capacity-reservation.yaml
54+
```
55+
56+
## Adjust placeholder resource requests
57+
58+
Configure the resource requests and limits for the placeholder pods to define the amount of overprovisioned resources you want to maintain. This reservation ensures that a specific amount of CPU and memory is kept available for new pods.
59+
60+
To edit the Deployment, modify the `resources` section in the Deployment manifest file
61+
to set appropriate requests and limits. You can download that file locally and then edit it
62+
with whichever text editor you prefer.
63+
64+
For example, to reserve 500m CPU and 1Gi memory across 5 placeholder pods,
65+
define the resource requests and limits for a single placeholder pod as follows:
66+
67+
```yaml
68+
resources:
69+
requests:
70+
cpu: "100m"
71+
memory: "200Mi"
72+
limits:
73+
cpu: "100m"
74+
```
75+
76+
## Set the desired replica count
77+
78+
### Calculate the total reserved resources
79+
80+
For example, with 5 replicas each reserving 0.1 CPU and 200MiB of memory:
81+
82+
Total CPU reserved: 5 × 0.1 = 0.5 (in the Pod specification, you'll write the quantity `500m`)
83+
Total Memory reserved: 5 × 200MiB = 1GiB (in the Pod specification, you'll write `1 Gi`)
84+
85+
To scale the Deployment, adjust the number of replicas based on your cluster's size and expected workload:
86+
87+
```shell
88+
kubectl scale deployment capacity-reservation --replicas=5
89+
```
90+
91+
Verify the scaling:
92+
93+
```shell
94+
kubectl get deployment capacity-reservation
95+
```
96+
97+
The output should reflect the updated number of replicas:
98+
99+
```none
100+
NAME READY UP-TO-DATE AVAILABLE AGE
101+
capacity-reservation 5/5 5 5 2m
102+
```
103+
104+
{{< note >}}
105+
Some autoscalers, notably [Karpenter](/docs/concepts/cluster-administration/cluster-autoscaling/#autoscaler-karpenter),
106+
treat preferred affinity rules as hard rules when considering node scaling.
107+
If you use Karpenter or another node autoscaler that uses the same heuristic,
108+
the replica count you set here also sets a minimum node count for your cluster.
109+
{{< /note >}}
110+
111+
## {{% heading "whatsnext" %}}
112+
113+
- Learn more about [PriorityClasses](/docs/concepts/scheduling-eviction/pod-priority-preemption/#priorityclass) and how they affect pod scheduling.
114+
- Explore [node autoscaling](/docs/concepts/cluster-administration/cluster-autoscaling/) to dynamically adjust your cluster's size based on workload demands.
115+
- Understand [Pod preemption](/docs/concepts/scheduling-eviction/pod-priority-preemption/), a
116+
key mechanism for Kubernetes to handle resource contention. The same page covers _eviction_,
117+
which is less relevant to the placeholder Pod approach, but is also a mechanism for Kubernetes
118+
to react when resources are contended.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: capacity-reservation
5+
spec:
6+
replicas: 1
7+
selector:
8+
matchLabels:
9+
app.kubernetes.io/name: capacity-placeholder
10+
template:
11+
metadata:
12+
labels:
13+
app.kubernetes.io/name: capacity-placeholder
14+
annotations:
15+
kubernetes.io/description: "Capacity reservation"
16+
spec:
17+
priorityClassName: placeholder
18+
affinity: # Try to place these overhead Pods on different nodes
19+
# if possible
20+
podAntiAffinity:
21+
preferredDuringSchedulingIgnoredDuringExecution:
22+
- labelSelector:
23+
matchLabels:
24+
app: placeholder
25+
topologyKey: "kubernetes.io/hostname"
26+
containers:
27+
- name: pause
28+
image: registry.k8s.io/pause:3.6
29+
resources:
30+
requests:
31+
cpu: "50m"
32+
memory: "512Mi"
33+
limits:
34+
memory: "512Mi"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: scheduling.k8s.io/v1
2+
kind: PriorityClass
3+
metadata:
4+
name: placeholder
5+
value: -1000
6+
globalDefault: false
7+
description: "Negative priority for placeholder pods to enable overprovisioning."

0 commit comments

Comments
 (0)