|
| 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. |
0 commit comments