Skip to content

Commit e5764b4

Browse files
authored
Merge pull request #102322 from mburke5678/autoscale-vpa-in-place-updates
OSDOCS 17247 Document InPlaceOrRecreate feature in Vertical Pod Autoscaler
2 parents c56180f + a1500a8 commit e5764b4

6 files changed

+82
-28
lines changed

modules/nodes-pods-vertical-autoscaler-about.adoc

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Recommender::
1414
The VPA recommender monitors the current and past resource consumption. Based on this data, the VPA recommender determines the optimal CPU and memory resources for the pods in the associated workload object.
1515

1616
Updater::
17-
The VPA updater checks if the pods in the associated workload object have the correct resources. If the resources are correct, the updater takes no action. If the resources are not correct, the updater kills the pod so that pods' controllers can re-create them with the updated requests.
17+
The VPA updater checks if the pods in the associated workload object have the correct resources. If the resources are correct, the updater takes no action. If the resources are not correct, the updater ensures that the pods have the updated requests. The way in which the VPA updates the resources depends on the update mode, as described in _About the Vertical Pod Autoscaler Operator modes_ later in this section.
1818

1919
Admission controller::
2020
The VPA admission controller sets the correct resource requests on each new pod in the associated workload object. This applies whether the pod is new or the controller re-created the pod due to the VPA updater actions.
@@ -23,14 +23,14 @@ You can use the default recommender or use your own alternative recommender to a
2323

2424
The default recommender automatically computes historic and current CPU and memory usage for the containers in those pods. The default recommender uses this data to determine optimized resource limits and requests to ensure that these pods are operating efficiently at all times. For example, the default recommender suggests reduced resources for pods that are requesting more resources than they are using and increased resources for pods that are not requesting enough.
2525

26-
The VPA then automatically deletes any pods that are out of alignment with these recommendations one at a time, so that your applications can continue to serve requests with no downtime. The workload objects then redeploy the pods with the original resource limits and requests. The VPA uses a mutating admission webhook to update the pods with optimized resource limits and requests before admitting the pods to a node. If you do not want the VPA to delete pods, you can view the VPA resource limits and requests and manually update the pods as needed.
26+
Depending upon the VPA mode, the VPA can automatically update any pods that are out of alignment with these recommendations one at a time, so that your applications can continue to serve requests with no downtime. The VPA updates the pods with optimized resource limits and requests before admitting the pods to a node. If you do not want the VPA to update pods, you can view the VPA resource limits and requests and manually update the pods as needed.
2727

2828
[NOTE]
2929
====
3030
By default, workload objects must specify a minimum of two replicas for the VPA to automatically delete their pods. Workload objects that specify fewer replicas than this minimum are not deleted. If you manually delete these pods, when the workload object redeploys the pods, the VPA updates the new pods with its recommendations. You can change this minimum by modifying the `VerticalPodAutoscalerController` object as shown in _Changing the VPA minimum value_.
3131
====
3232

33-
For example, if you have a pod that uses 50% of the CPU but only requests 10%, the VPA determines that the pod is consuming more CPU than requested and deletes the pod. The workload object, such as replica set, restarts the pods and the VPA updates the new pod with its recommended resources.
33+
For example, if you have a pod that uses 50% of the CPU but only requests 10%, the VPA determines that the pod is consuming more CPU than requested. Depending upon the VPA mode, the VPA updates the pod or you can manually update the pod at a convenient time.
3434

3535
For developers, you can use the VPA to help ensure that your pods active during periods of high demand by scheduling pods onto nodes that have appropriate resources for each pod.
3636

@@ -40,3 +40,23 @@ Administrators can use the VPA to better use cluster resources, such as preventi
4040
====
4141
If you stop running the VPA or delete a specific VPA CR in your cluster, the resource requests for the pods already modified by the VPA do not change. However, any new pods get the resources defined in the workload object, not the previous recommendations made by the VPA.
4242
====
43+
44+
[id="nodes-pods-vertical-autoscaler-modes_{context}"]
45+
== About the Vertical Pod Autoscaler Operator modes
46+
47+
You can set on of the following VPA modes by using a `VerticalPodAutoscaler` CR:
48+
49+
* `InPlaceOrRecreate`. In this mode, the VPA automatically applies the recommended CPU and memory resources throughout the pod lifetime. When any pod in the project is out of alignment with the VPA recommendations, the VPA attempts to apply updates _in-place_, without restarting the pod. If the VPA is not able to update the containers in-place, the VPA deletes the pod. When redeployed by the workload object, the VPA uses a mutating admission webhook to update the new pod with its recommendations. For specific information about in-place updates, see "About the in-place-or-recreate mode".
50+
+
51+
The container's resize policy dictates the way in which `InPlaceOrRecreate` mode updates are applied. If the policy is set to `NotRequired`, the VPA attempts to update the container without restarting. If the policy is `RestartContainer`, the VPA always restarts the container upon the update.
52+
53+
* `Recreate` and `Auto`. In either of these modes, the VPA automatically applies the recommended CPU and memory resources throughout the pod lifetime. When any pod in the project is out of alignment with the VPA recommendations, the VPA deletes the pod. When redeployed by the workload object, the VPA uses a mutating admission webhook to update the new pod with its recommendations. Use the `Recreate` mode rarely, only if you need to ensure that when the resource request changes the pods restart.
54+
+
55+
--
56+
:FeatureName: The `Auto` VPA mode
57+
include::snippets/deprecated-feature.adoc[leveloffset=+1]
58+
--
59+
60+
* `Initial`. In this mode, the VPA applies the recommended CPU and memory resources mode only at pod creation.
61+
62+
* `Off`. In this mode, the VPA mode only provides the recommended resource limits and requests. You can then manually apply the recommendations. The `Off` mode does not update pods.

modules/nodes-pods-vertical-autoscaler-configuring.adoc

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ spec:
3636
kind: Deployment <1>
3737
name: frontend <2>
3838
updatePolicy:
39-
updateMode: "Auto" <3>
39+
updateMode: "InPlaceOrRecreate" <3>
4040
resourcePolicy: <4>
4141
containerPolicies:
4242
- containerName: my-opt-sidecar
@@ -47,8 +47,8 @@ spec:
4747
<1> Specify the type of workload object you want this VPA to manage: `Deployment`, `StatefulSet`, `Job`, `DaemonSet`, `ReplicaSet`, or `ReplicationController`.
4848
<2> Specify the name of an existing workload object you want this VPA to manage.
4949
<3> Specify the VPA mode:
50-
* `Auto` to automatically apply the recommended resources on pods associated with the controller. The VPA terminates existing pods and creates new pods with the recommended resource limits and requests.
51-
* `Recreate` to automatically apply the recommended resources on pods associated with the workload object. The VPA terminates existing pods and creates new pods with the recommended resource limits and requests. Use the `Recreate` mode rarely, only if you need to ensure that the pods restart whenever the resource request changes.
50+
* `InPlaceOrRecreate` to automatically apply the recommended resources on pods associated with the workload object. The VPA attempts to update the workload object with the new resources without re-creating the pod. If the VPA is unable to update the object in place, the VPA re-creates it.
51+
* `Recreate` to automatically apply the recommended resources on pods associated with the workload object. The VPA terminates existing pods and creates new pods with the recommended resource limits and requests. Use the `Recreate` mode only if you need to ensure that the pods restart whenever the resource request changes.
5252
* `Initial` to automatically apply the recommended resources to newly-created pods associated with the workload object. The VPA does not update the pods as it learns new resource recommendations.
5353
* `Off` to only generate resource recommendations for the pods associated with the workload object. The VPA does not update the pods as it learns new resource recommendations and does not apply the recommendations to new pods.
5454
<4> Optional. Specify the containers you want to opt-out and set the mode to `Off`.
@@ -75,11 +75,13 @@ The output shows the recommendations for CPU and memory requests, similar to the
7575
.Example output
7676
[source,yaml]
7777
----
78-
...
78+
apiVersion: autoscaling.k8s.io/v1
79+
kind: VerticalPodAutoscaler
80+
metadata:
81+
name: vpa-recommender
82+
# ...
7983
status:
80-
81-
...
82-
84+
# ...
8385
recommendation:
8486
containerRecommendations:
8587
- containerName: frontend

modules/nodes-pods-vertical-autoscaler-custom-resource.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,5 @@ spec:
8989
kind: ScalablePod
9090
name: scalable-cr
9191
updatePolicy:
92-
updateMode: "Auto"
92+
updateMode: "InPlaceOrRecreate"
9393
----
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * nodes/nodes-vertical-autoscaler.adoc
4+
5+
:_mod-docs-content-type: CONCEPT
6+
[id="nodes-pods-vertical-autoscaler-in-place_{context}"]
7+
= About the in-place-or-recreate mode
8+
9+
The Vertical Pod Autoscaler Operator (VPA) contains an optional `InPlaceOrRecreate` mode. This mode instructs the VPA to attempt to perform an _in-place pod resize_ when updating CPU or memory resources, where the VPA first attempts to update the resources in a running pod without recreating the pod. If an in-place resize is not possible, the VPA falls back to the `Recreate` mode and restarts the pod in order to update the resources.
10+
11+
When in `InPlaceOrRecreate` mode, the VPA falls back to always recreating pods in the following scenarios:
12+
13+
* The in-place update is considered _infeasible_ for reasons including the following reasons:
14+
** The requested resources exceed the node's total capacity.
15+
** The pod is a static pod.
16+
** The containers has swap enabled.
17+
** The pod is managed by a static `cpuManagerPolicy` or `memoryManagerPolicy` parameter.
18+
* The update is _deferred_ for more than 5 minutes. A deferred update is one that is currently not possible, but might become possible at a later time. For example, if another pod is removed from the node, the requested resources might become available. The kubelet retries the resize when conditions on the node change.
19+
* The update is in progress for more than 1 hour.
20+
* The pod QoS class would change due to the update.
21+
* The update would downscale the memory limit.
22+
23+
If a container in a pod has a `RestartContainer` container resize policy, which requires a restart upon a resource update, a VPA in `InPlaceOrRecreate` mode honors the resize policy and restarts the container.
24+
25+
For more information on in-place updates, see "Adjust pod resource levels without pod disruption".

modules/nodes-pods-vertical-autoscaler-using-about.adoc

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,7 @@
88

99
To use the Vertical Pod Autoscaler Operator (VPA), you create a VPA custom resource (CR) for a workload object in your cluster. The VPA learns and applies the optimal CPU and memory resources for the pods associated with that workload object. You can use a VPA with a deployment, stateful set, job, daemon set, replica set, or replication controller workload object. The VPA CR must be in the same project as the pods that you want to check.
1010

11-
You use the VPA CR to associate a workload object and specify the mode that the VPA operates in:
12-
13-
* The `Auto` and `Recreate` modes automatically apply the VPA CPU and memory recommendations throughout the pod lifetime. The VPA deletes any pods in the project that are out of alignment with its recommendations. When redeployed by the workload object, the VPA updates the new pods with its recommendations.
14-
* The `Initial` mode automatically applies VPA recommendations only at pod creation.
15-
* The `Off` mode only provides recommended resource limits and requests. You can then manually apply the recommendations. The `Off` mode does not update pods.
16-
17-
You can also use the CR to opt-out certain containers from VPA evaluation and updates.
11+
You use the VPA CR to associate a workload object and specify the mode that the VPA operates in. You can also use the CR to opt-out certain containers from VPA evaluation and updates.
1812

1913
For example, a pod has the following limits and requests:
2014

@@ -29,7 +23,7 @@ resources:
2923
memory: 100Mi
3024
----
3125

32-
After creating a VPA that is set to `Auto`, the VPA learns the resource usage and deletes the pod. When redeployed, the pod uses the new resource limits and requests:
26+
After creating a VPA that is set to `Recreate`, the VPA learns the resource usage and deletes the pod. When redeployed, the pod uses the new resource limits and requests:
3327

3428
[source,yaml]
3529
----
@@ -92,6 +86,11 @@ The output shows the recommended resources, `target`, the minimum recommended re
9286

9387
The VPA uses the `lowerBound` and `upperBound` values to determine if a pod needs updating. If a pod has resource requests less than the `lowerBound` values or more than the `upperBound` values, the VPA terminates and recreates the pod with the `target` values.
9488

89+
[role="_additional-resources"]
90+
.Additional resources
91+
92+
* xref:../../nodes/pods/nodes-pods-adjust-resources-in-place.adoc#nodes-pods-adjust-resources-in-place-about_nodes-pods-adjust-resources-in-place[Adjust pod resource levels without pod disruption]
93+
9594
[id="nodes-pods-vertical-autoscaler-using-one-pod_{context}"]
9695
== Changing the VPA minimum value
9796

@@ -128,16 +127,16 @@ spec:
128127

129128
[id="nodes-pods-vertical-autoscaler-using-auto_{context}"]
130129
== Automatically applying VPA recommendations
131-
To use the VPA to automatically update pods, create a VPA CR for a specific workload object with `updateMode` set to `Auto` or `Recreate`.
130+
To use the VPA to automatically update pods, create a VPA CR for a specific workload object with `updateMode` set to `InPlaceOrRecreate` or `Recreate`.
132131

133-
When the pods are created for the workload object, the VPA constantly monitors the containers to analyze their CPU and memory needs. The VPA deletes any pods that do not meet the VPA recommendations for CPU and memory. When redeployed, the pods use the new resource limits and requests based on the VPA recommendations, honoring any pod disruption budget set for your applications. The recommendations are added to the `status` field of the VPA CR for reference.
132+
When the pods are created for the workload object, the VPA constantly monitors the containers to analyze their CPU and memory needs. The VPA updates any pods that do not meet the VPA recommendations for CPU and memory to use the new resource limits and requests based on the VPA recommendations, honoring any pod disruption budget set for your applications. The recommendations are added to the `status` field of the VPA CR for reference.
134133

135134
[NOTE]
136135
====
137136
By default, workload objects must specify a minimum of two replicas in order for the VPA to automatically delete their pods. Workload objects that specify fewer replicas than this minimum are not deleted. If you manually delete these pods, when the workload object redeploys the pods, the VPA does update the new pods with its recommendations. You can change this minimum by modifying the `VerticalPodAutoscalerController` object as shown in _Changing the VPA minimum value_.
138137
====
139138

140-
.Example VPA CR for the `Auto` mode
139+
.Example VPA CR for the `InPlaceOrRecreate` or `Recreate` mode
141140
[source,yaml]
142141
----
143142
apiVersion: autoscaling.k8s.io/v1
@@ -150,13 +149,14 @@ spec:
150149
kind: Deployment <1>
151150
name: frontend <2>
152151
updatePolicy:
153-
updateMode: "Auto" <3>
152+
updateMode: "InPlaceOrRecreate" <3>
154153
----
155154
<1> The type of workload object you want this VPA CR to manage.
156155
<2> The name of the workload object you want this VPA CR to manage.
157-
<3> Set the mode to `Auto` or `Recreate`:
158-
* `Auto`. The VPA assigns resource requests on pod creation and updates the existing pods by terminating them when the requested resources differ significantly from the new recommendation.
159-
* `Recreate`. The VPA assigns resource requests on pod creation and updates the existing pods by terminating them when the requested resources differ significantly from the new recommendation. Use this mode rarely, only if you need to ensure that when the resource request changes the pods restart.
156+
<3> Set the mode to `InPlaceOrRecreate` or `Recreate`:
157+
+
158+
* `InPlaceOrRecreate`. The VPA attempts to update the workload object with the new resource requests without re-creating the pod. If the VPA is unable to update the object in place, the VPA re-creates it.
159+
* `Recreate`. The VPA assigns resource requests on pod creation and updates the existing pods by terminating them. Use this mode rarely, only if you need to ensure that when the resource request changes the pods restart.
160160

161161
[NOTE]
162162
====
@@ -258,15 +258,15 @@ spec:
258258
kind: Deployment <1>
259259
name: frontend <2>
260260
updatePolicy:
261-
updateMode: "Auto" <3>
261+
updateMode: "InPlaceOrRecreate" <3>
262262
resourcePolicy: <4>
263263
containerPolicies:
264264
- containerName: my-opt-sidecar
265265
mode: "Off"
266266
----
267267
<1> The type of workload object you want this VPA CR to manage.
268268
<2> The name of the workload object you want this VPA CR to manage.
269-
<3> Set the mode to `Auto`, `Recreate`, `Initial`, or `Off`. Use the `Recreate` mode rarely, only if you need to ensure that when the resource request changes the pods restart.
269+
<3> Set the mode to `InPlaceOrRecreate`, `Recreate`, `Initial`, or `Off`. Use the `Recreate` mode rarely. For example, use this mode to ensure that the pods restart when the resources are updated.
270270
<4> Specify the containers that you do not want updated by the VPA and set the `mode` to `Off`.
271271

272272
For example, a pod has two containers, the same resource requests and limits:

nodes/pods/nodes-pods-vertical-autoscaler.adoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ The VPA helps you to understand the optimal CPU and memory usage for your pods a
3030

3131
include::modules/nodes-pods-vertical-autoscaler-about.adoc[leveloffset=+1]
3232

33+
include::modules/nodes-pods-vertical-autoscaler-in-place.adoc[leveloffset=+2]
34+
35+
[role="_additional-resources"]
36+
.Additional resources
37+
* xref:../../nodes/pods/nodes-pods-vertical-autoscaler.adoc#nodes-pods-vertical-autoscaler-using-about_nodes-pods-vertical-autoscaler[About using the Vertical Pod Autoscaler Operator]
38+
* xref:../../nodes/pods/nodes-pods-adjust-resources-in-place.adoc#nodes-pods-adjust-resources-in-place[Adjust pod resource levels without pod disruption]
39+
3340
include::modules/nodes-pods-vertical-autoscaler-install.adoc[leveloffset=+1]
3441

3542
include::modules/nodes-pods-vertical-autoscaler-moving-vpa.adoc[leveloffset=+1]

0 commit comments

Comments
 (0)