You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Vertical Pod Autoscaler Operator (VPA) is implemented as an API resource and a custom resource (CR). The CR determines the actions for the VPA to take with the pods associated with a specific workload object, such as a daemon set, replication controller, and so forth, in a project.
9
+
[role="_abstract"]
10
+
To help you maintain the optimal CPU and memory usage for your pods, you can use the {product-title} Vertical Pod Autoscaler Operator (VPA).
11
+
12
+
The VPA is implemented as an API resource and a custom resource (CR). The CR determines the actions for the VPA to take with the pods associated with a specific workload object, such as a daemon set, replication controller, and so forth, in a project.
10
13
11
14
The VPA consists of three components, each of which has its own pod in the VPA namespace:
You can use the Vertical Pod Autoscaler Operator (VPA) by creating a VPA custom resource (CR). The CR indicates the pods to analyze and determines the actions for the VPA to take with those pods.
9
+
[role="_abstract"]
10
+
You can use the Vertical Pod Autoscaler Operator (VPA) to help you maintain the optimal CPU and memory usage for your pods by creating a VPA custom resource (CR). The CR indicates the pods to analyze and determines the actions for the VPA to take with those pods.
10
11
11
12
You can use the VPA to scale built-in resources such as deployments or stateful sets, and custom resources that manage pods. For more information, see "About using the Vertical Pod Autoscaler Operator".
12
13
14
+
The following procedure creates a VPA CR for a specific workload object.
15
+
13
16
.Prerequisites
14
17
15
18
* Ensure the workload object that you want to autoscale exists.
@@ -18,8 +21,6 @@ You can use the VPA to scale built-in resources such as deployments or stateful
18
21
19
22
.Procedure
20
23
21
-
To create a VPA CR for a specific workload object:
22
-
23
24
. Change to the location of the project for the workload object you want to scale.
24
25
25
26
.. Create a VPA CR YAML file:
@@ -33,26 +34,28 @@ metadata:
33
34
spec:
34
35
targetRef:
35
36
apiVersion: "apps/v1"
36
-
kind: Deployment <1>
37
-
name: frontend <2>
37
+
kind: Deployment
38
+
name: frontend
38
39
updatePolicy:
39
-
updateMode: "InPlaceOrRecreate" <3>
40
-
resourcePolicy: <4>
40
+
updateMode: "InPlaceOrRecreate"
41
+
resourcePolicy:
41
42
containerPolicies:
42
43
- containerName: my-opt-sidecar
43
44
mode: "Off"
44
-
recommenders: <5>
45
+
recommenders:
45
46
- name: my-recommender
46
47
----
47
-
<1> Specify the type of workload object you want this VPA to manage: `Deployment`, `StatefulSet`, `Job`, `DaemonSet`, `ReplicaSet`, or `ReplicationController`.
48
-
<2> Specify the name of an existing workload object you want this VPA to manage.
49
-
<3> Specify the VPA mode:
48
+
where:
49
+
50
+
`spec.targetRef.kind`:: Specifies the type of workload object you want this VPA to manage: `Deployment`, `StatefulSet`, `Job`, `DaemonSet`, `ReplicaSet`, or `ReplicationController`.
51
+
`spec.targetRef.name`:: Specifies the name of an existing workload object you want this VPA to manage.
52
+
`spec.updatePolicy.updateMode`:: Specifies the VPA mode:
50
53
* `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
54
* `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.
52
55
* `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.
53
56
* `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.
54
-
<4> Optional. Specify the containers you want to opt-out and set the mode to `Off`.
55
-
<5> Optional. Specify an alternative recommender.
57
+
`spec.resourcePolicy`:: Specifies the containers you want to opt-out and set the mode to `Off`. This parameter is optional.
58
+
`spec.recommenders`:: Specifies an alternative recommender. This parameter is optional.
56
59
57
60
.. Create the VPA CR:
58
61
+
@@ -85,16 +88,16 @@ status:
85
88
recommendation:
86
89
containerRecommendations:
87
90
- containerName: frontend
88
-
lowerBound: <1>
91
+
lowerBound:
89
92
cpu: 25m
90
93
memory: 262144k
91
-
target: <2>
94
+
target:
92
95
cpu: 25m
93
96
memory: 262144k
94
-
uncappedTarget: <3>
97
+
uncappedTarget:
95
98
cpu: 25m
96
99
memory: 262144k
97
-
upperBound: <4>
100
+
upperBound:
98
101
cpu: 262m
99
102
memory: "274357142"
100
103
- containerName: backend
@@ -113,7 +116,11 @@ status:
113
116
114
117
...
115
118
----
116
-
<1> `lowerBound` is the minimum recommended resource levels.
117
-
<2> `target` is the recommended resource levels.
118
-
<3> `upperBound` is the highest recommended resource levels.
119
-
<4> `uncappedTarget` is the most recent resource recommendations.
119
+
where:
120
+
121
+
`status.recommendation.containerRecommendations`:: Specifies the minimum and maximum recommended resource levels for the container:
122
+
* `containerName` is the container for the recommended resource levels.
123
+
* `lowerBound` is the minimum recommended resource levels.
124
+
* `target` is the recommended resource levels.
125
+
* `upperBound` is the highest recommended resource levels.
126
+
* `uncappedTarget` is the most recent resource recommendations.
= Example custom resources for the Vertical Pod Autoscaler
8
8
9
-
The Vertical Pod Autoscaler Operator (VPA) can update not only built-in resources such as deployments or stateful sets, but also custom resources that manage pods.
9
+
[role="_abstract"]
10
+
You can use the Vertical Pod Autoscaler Operator (VPA) to update custom resources that manage pods, not just built-in resources such as deployments or stateful sets.
10
11
11
12
To use the VPA with a custom resource when you create the `CustomResourceDefinition` (CRD) object, you must configure the `labelSelectorPath` field in the `/scale` subresource. The `/scale` subresource creates a `Scale` object. The `labelSelectorPath` field defines the JSON path inside the custom resource that corresponds to `status.selector` in the `Scale` object and in the custom resource. The following is an example of a `CustomResourceDefinition` and a `CustomResource` that fulfills these requirements, along with a `VerticalPodAutoscaler` definition that targets the custom resource. The following example shows the `/scale` subresource contract.
12
13
@@ -50,7 +51,7 @@ spec:
50
51
scale:
51
52
specReplicasPath: .spec.replicas
52
53
statusReplicasPath: .status.replicas
53
-
labelSelectorPath: .spec.selector <1>
54
+
labelSelectorPath: .spec.selector
54
55
scope: Namespaced
55
56
names:
56
57
plural: scalablepods
@@ -59,7 +60,9 @@ spec:
59
60
shortNames:
60
61
- spod
61
62
----
62
-
<1> Specifies the JSON path that corresponds to `status.selector` field of the custom resource object.
63
+
where:
64
+
65
+
`spec.subresources.scale.labelSelectorPath`:: Specifies the JSON path that corresponds to `status.selector` field of the custom resource object.
63
66
64
67
.Example custom CR
65
68
[source,yaml]
@@ -70,10 +73,12 @@ metadata:
70
73
name: scalable-cr
71
74
namespace: default
72
75
spec:
73
-
selector: "app=scalable-cr" <1>
76
+
selector: "app=scalable-cr"
74
77
replicas: 1
75
78
----
76
-
<1> Specify the label type to apply to managed pods. This is the field that the `labelSelectorPath` references in the custom resource definition object.
79
+
where:
80
+
81
+
`spec.selector`:: Specifies the label type to apply to managed pods. This is the field that the `labelSelectorPath` references in the custom resource definition object.
You can use your own recommender to autoscale based on your own algorithms. If you do not specify an alternative recommender, {product-title} uses the default recommender, which suggests CPU and memory requests based on historical usage. Because there is no universal recommendation policy that applies to all types of workloads, you might want to create and deploy different recommenders for specific workloads.
9
+
[role="_abstract"]
10
+
You can use your own recommender to autoscale based on your own algorithms. If you do not specify an alternative recommender, {product-title} uses the default recommender, which suggests CPU and memory requests based on historical usage.
11
+
12
+
Because there is no universal recommendation policy that applies to all types of workloads, you might want to create and deploy different recommenders for specific workloads.
10
13
11
14
For example, the default recommender might not accurately predict future resource usage when containers exhibit certain resource behaviors. Examples are cyclical patterns that alternate between usage spikes and idling as used by monitoring applications, or recurring and repeating patterns used with deep learning applications. Using the default recommender with these usage behaviors might result in significant over-provisioning and Out of Memory (OOM) kills for your applications.
12
15
@@ -17,21 +20,21 @@ For example, the default recommender might not accurately predict future resourc
17
20
Instructions for how to create a recommender are beyond the scope of this documentation.
18
21
====
19
22
20
-
.Procedure
23
+
The following procedure shows how to use an alternative recommender for your pods.
21
24
22
-
To use an alternative recommender for your pods:
25
+
.Procedure
23
26
24
27
. Create a service account for the alternative recommender and bind that service account to the required cluster role:
25
28
+
26
29
[source,yaml]
27
30
----
28
-
apiVersion: v1 <1>
31
+
apiVersion: v1
29
32
kind: ServiceAccount
30
33
metadata:
31
34
name: alt-vpa-recommender-sa
32
35
namespace: <namespace_name>
33
36
---
34
-
apiVersion: rbac.authorization.k8s.io/v1 <2>
37
+
apiVersion: rbac.authorization.k8s.io/v1
35
38
kind: ClusterRoleBinding
36
39
metadata:
37
40
name: system:example-metrics-reader
@@ -44,7 +47,7 @@ subjects:
44
47
name: alt-vpa-recommender-sa
45
48
namespace: <namespace_name>
46
49
---
47
-
apiVersion: rbac.authorization.k8s.io/v1 <3>
50
+
apiVersion: rbac.authorization.k8s.io/v1
48
51
kind: ClusterRoleBinding
49
52
metadata:
50
53
name: system:example-vpa-actor
@@ -57,7 +60,7 @@ subjects:
57
60
name: alt-vpa-recommender-sa
58
61
namespace: <namespace_name>
59
62
---
60
-
apiVersion: rbac.authorization.k8s.io/v1 <4>
63
+
apiVersion: rbac.authorization.k8s.io/v1
61
64
kind: ClusterRoleBinding
62
65
metadata:
63
66
name: system:example-vpa-target-reader-binding
@@ -70,10 +73,13 @@ subjects:
70
73
name: alt-vpa-recommender-sa
71
74
namespace: <namespace_name>
72
75
----
73
-
<1> Creates a service account for the recommender in the namespace that displays the recommender.
74
-
<2> Binds the recommender service account to the `metrics-reader` role. Specify the namespace for where to deploy the recommender.
75
-
<3> Binds the recommender service account to the `vpa-actor` role. Specify the namespace for where to deploy the recommender.
76
-
<4> Binds the recommender service account to the `vpa-target-reader` role. Specify the namespace for where to display the recommender.
76
+
+
77
+
--
78
+
* The `alt-vpa-recommender-sa` object creates a service account for the recommender in the namespace that displays the recommender.
79
+
* The `system:metrics-reader` object binds the recommender service account to the `metrics-reader` role. Specify the namespace for where to deploy the recommender.
80
+
* The `system:example-vpa-actor` object binds the recommender service account to the `vpa-actor` role. Specify the namespace for where to deploy the recommender.
81
+
* The `system:example-vpa-target-reader-binding` object binds the recommender service account to the `vpa-target-reader` role. Specify the namespace for where to display the recommender.
82
+
--
77
83
78
84
. To add the alternative recommender to the cluster, create a `Deployment` object similar to the following:
79
85
+
@@ -94,9 +100,9 @@ spec:
94
100
labels:
95
101
app: alt-vpa-recommender
96
102
spec:
97
-
containers: <1>
103
+
containers:
98
104
- name: recommender
99
-
image: quay.io/example/alt-recommender:latest <2>
105
+
image: quay.io/example/alt-recommender:latest
100
106
imagePullPolicy: Always
101
107
resources:
102
108
limits:
@@ -115,15 +121,16 @@ spec:
115
121
- ALL
116
122
seccompProfile:
117
123
type: RuntimeDefault
118
-
serviceAccountName: alt-vpa-recommender-sa <3>
124
+
serviceAccountName: alt-vpa-recommender-sa
119
125
securityContext:
120
126
runAsNonRoot: true
121
127
----
128
+
where:
122
129
+
123
130
--
124
-
<1> Creates a container for your alternative recommender.
125
-
<2> Specifies your recommender image.
126
-
<3> Associates the service account that you created for the recommender.
131
+
`spec.template.spec.containers`:: Specifies a container for your alternative recommender.
132
+
`spec.template.spec.containers.image`:: Specifies your recommender image.
133
+
`spec.template.spec.serviceAccountName`:: Specifies the service account that you created for the recommender.
127
134
--
128
135
+
129
136
A new pod is created for the alternative recommender in the same namespace.
@@ -155,11 +162,13 @@ metadata:
155
162
namespace: <namespace_name>
156
163
spec:
157
164
recommenders:
158
-
- name: alt-vpa-recommender <1>
165
+
- name: alt-vpa-recommender
159
166
targetRef:
160
167
apiVersion: "apps/v1"
161
-
kind: Deployment <2>
168
+
kind: Deployment
162
169
name: frontend
163
170
----
164
-
<1> Specifies the name of the alternative recommender deployment.
165
-
<2> Specifies the name of an existing workload object you want this VPA to manage.
171
+
where:
172
+
173
+
`spec.recommenders.name`:: Specifies the name of the alternative recommender deployment.
174
+
`spec.targetRef.kind`:: Specifies the name of an existing workload object you want this VPA to manage.
0 commit comments