1
0
mirror of https://github.com/openshift/openshift-docs.git synced 2026-02-05 12:46:18 +01:00
Files
openshift-docs/modules/nodes-pods-vertical-autoscaler-custom.adoc
2025-09-11 18:43:49 +00:00

166 lines
5.4 KiB
Plaintext

// Module included in the following assemblies:
//
// * nodes/nodes-vertical-autoscaler.adoc
:_mod-docs-content-type: PROCEDURE
[id="nodes-pods-vertical-autoscaler-custom_{context}"]
= Using an alternative recommender
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.
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.
// intro paragraph based on https://github.com/kubernetes/autoscaler/tree/master/vertical-pod-autoscaler/enhancements/3919-customized-recommender-vpa
[NOTE]
====
Instructions for how to create a recommender are beyond the scope of this documentation.
====
.Procedure
To use an alternative recommender for your pods:
. Create a service account for the alternative recommender and bind that service account to the required cluster role:
+
[source,yaml]
----
apiVersion: v1 <1>
kind: ServiceAccount
metadata:
name: alt-vpa-recommender-sa
namespace: <namespace_name>
---
apiVersion: rbac.authorization.k8s.io/v1 <2>
kind: ClusterRoleBinding
metadata:
name: system:example-metrics-reader
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:metrics-reader
subjects:
- kind: ServiceAccount
name: alt-vpa-recommender-sa
namespace: <namespace_name>
---
apiVersion: rbac.authorization.k8s.io/v1 <3>
kind: ClusterRoleBinding
metadata:
name: system:example-vpa-actor
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:vpa-actor
subjects:
- kind: ServiceAccount
name: alt-vpa-recommender-sa
namespace: <namespace_name>
---
apiVersion: rbac.authorization.k8s.io/v1 <4>
kind: ClusterRoleBinding
metadata:
name: system:example-vpa-target-reader-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:vpa-target-reader
subjects:
- kind: ServiceAccount
name: alt-vpa-recommender-sa
namespace: <namespace_name>
----
<1> Creates a service account for the recommender in the namespace that displays the recommender.
<2> Binds the recommender service account to the `metrics-reader` role. Specify the namespace for where to deploy the recommender.
<3> Binds the recommender service account to the `vpa-actor` role. Specify the namespace for where to deploy the recommender.
<4> Binds the recommender service account to the `vpa-target-reader` role. Specify the namespace for where to display the recommender.
. To add the alternative recommender to the cluster, create a `Deployment` object similar to the following:
+
[source,yaml]
----
apiVersion: apps/v1
kind: Deployment
metadata:
name: alt-vpa-recommender
namespace: <namespace_name>
spec:
replicas: 1
selector:
matchLabels:
app: alt-vpa-recommender
template:
metadata:
labels:
app: alt-vpa-recommender
spec:
containers: <1>
- name: recommender
image: quay.io/example/alt-recommender:latest <2>
imagePullPolicy: Always
resources:
limits:
cpu: 200m
memory: 1000Mi
requests:
cpu: 50m
memory: 500Mi
ports:
- name: prometheus
containerPort: 8942
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
seccompProfile:
type: RuntimeDefault
serviceAccountName: alt-vpa-recommender-sa <3>
securityContext:
runAsNonRoot: true
----
+
--
<1> Creates a container for your alternative recommender.
<2> Specifies your recommender image.
<3> Associates the service account that you created for the recommender.
--
+
A new pod is created for the alternative recommender in the same namespace.
+
[source,terminal]
----
$ oc get pods
----
+
.Example output
[source,terminal]
----
NAME READY STATUS RESTARTS AGE
frontend-845d5478d-558zf 1/1 Running 0 4m25s
frontend-845d5478d-7z9gx 1/1 Running 0 4m25s
frontend-845d5478d-b7l4j 1/1 Running 0 4m25s
vpa-alt-recommender-55878867f9-6tp5v 1/1 Running 0 9s
----
. Configure a Vertical Pod Autoscaler Operator (VPA) custom resource (CR) that includes the name of the alternative recommender `Deployment` object.
+
.Example VPA CR to include the alternative recommender
[source,yml]
----
apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
name: vpa-recommender
namespace: <namespace_name>
spec:
recommenders:
- name: alt-vpa-recommender <1>
targetRef:
apiVersion: "apps/v1"
kind: Deployment <2>
name: frontend
----
<1> Specifies the name of the alternative recommender deployment.
<2> Specifies the name of an existing workload object you want this VPA to manage.