|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * nodes/nodes-vertical-autoscaler.adoc |
| 4 | + |
| 5 | +:_content-type: PROCEDURE |
| 6 | +[id="nodes-pods-vertical-autoscaler-custom_{context}"] |
| 7 | += Using an alternative recommender |
| 8 | + |
| 9 | +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. |
| 10 | + |
| 11 | +For example, the default recommender might not accurately predict future resource usage when containers exhibit certain resource behaviors, such as 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 | + |
| 13 | +// intro paragraph based on https://github.com/kubernetes/autoscaler/tree/master/vertical-pod-autoscaler/enhancements/3919-customized-recommender-vpa |
| 14 | + |
| 15 | +[NOTE] |
| 16 | +==== |
| 17 | +Instructions for how to create a recommender are beyond the scope of this documentation, |
| 18 | +==== |
| 19 | + |
| 20 | +.Procedure |
| 21 | + |
| 22 | +To use an alternative recommender for your pods: |
| 23 | + |
| 24 | +. Create a service account for the alternative recommender and bind that service account to the required cluster role: |
| 25 | ++ |
| 26 | +[source,yaml] |
| 27 | +---- |
| 28 | +apiVersion: v1 <1> |
| 29 | +kind: ServiceAccount |
| 30 | +metadata: |
| 31 | + name: alt-vpa-recommender-sa |
| 32 | + namespace: <namespace_name> |
| 33 | +--- |
| 34 | +apiVersion: rbac.authorization.k8s.io/v1 <2> |
| 35 | +kind: ClusterRoleBinding |
| 36 | +metadata: |
| 37 | + name: system:example-metrics-reader |
| 38 | +roleRef: |
| 39 | + apiGroup: rbac.authorization.k8s.io |
| 40 | + kind: ClusterRole |
| 41 | + name: system:metrics-reader |
| 42 | +subjects: |
| 43 | +- kind: ServiceAccount |
| 44 | + name: alt-vpa-recommender-sa |
| 45 | + namespace: <namespace_name> |
| 46 | +--- |
| 47 | +apiVersion: rbac.authorization.k8s.io/v1 <3> |
| 48 | +kind: ClusterRoleBinding |
| 49 | +metadata: |
| 50 | + name: system:example-vpa-actor |
| 51 | +roleRef: |
| 52 | + apiGroup: rbac.authorization.k8s.io |
| 53 | + kind: ClusterRole |
| 54 | + name: system:vpa-actor |
| 55 | +subjects: |
| 56 | +- kind: ServiceAccount |
| 57 | + name: alt-vpa-recommender-sa |
| 58 | + namespace: <namespace_name> |
| 59 | +--- |
| 60 | +apiVersion: rbac.authorization.k8s.io/v1 <4> |
| 61 | +kind: ClusterRoleBinding |
| 62 | +metadata: |
| 63 | + name: system:example-vpa-target-reader-binding |
| 64 | +roleRef: |
| 65 | + apiGroup: rbac.authorization.k8s.io |
| 66 | + kind: ClusterRole |
| 67 | + name: system:vpa-target-reader |
| 68 | +subjects: |
| 69 | +- kind: ServiceAccount |
| 70 | + name: alt-vpa-recommender-sa |
| 71 | + namespace: <namespace_name> |
| 72 | +---- |
| 73 | +<1> Creates a service accocunt for the recommender in the namespace where the recommender is deployed. |
| 74 | +<2> Binds the recommender service account to the `metrics-reader` role. Specify the namespace where the recommender is to be deployed. |
| 75 | +<3> Binds the recommender service account to the `vpa-actor` role. Specify the namespace where the recommender is to be deployed. |
| 76 | +<4> Binds the recommender service account to the `vpa-target-reader` role. Specify the namespace where the recommender is to be deployed. |
| 77 | + |
| 78 | +. To add the alternative recommender to the cluster, create a Deployment object similar to the following: |
| 79 | ++ |
| 80 | +[source,yaml] |
| 81 | +---- |
| 82 | +apiVersion: apps/v1 |
| 83 | +kind: Deployment |
| 84 | +metadata: |
| 85 | + name: alt-vpa-recommender |
| 86 | + namespace: <namespace_name> |
| 87 | +spec: |
| 88 | + replicas: 1 |
| 89 | + selector: |
| 90 | + matchLabels: |
| 91 | + app: alt-vpa-recommender |
| 92 | + template: |
| 93 | + metadata: |
| 94 | + labels: |
| 95 | + app: alt-vpa-recommender |
| 96 | + spec: |
| 97 | + containers: <1> |
| 98 | + - name: recommender |
| 99 | + image: quay.io/example/alt-recommender:latest <2> |
| 100 | + imagePullPolicy: Always |
| 101 | + resources: |
| 102 | + limits: |
| 103 | + cpu: 200m |
| 104 | + memory: 1000Mi |
| 105 | + requests: |
| 106 | + cpu: 50m |
| 107 | + memory: 500Mi |
| 108 | + ports: |
| 109 | + - name: prometheus |
| 110 | + containerPort: 8942 |
| 111 | + securityContext: |
| 112 | + allowPrivilegeEscalation: false |
| 113 | + capabilities: |
| 114 | + drop: |
| 115 | + - ALL |
| 116 | + seccompProfile: |
| 117 | + type: RuntimeDefault |
| 118 | + serviceAccountName: alt-vpa-recommender-sa <3> |
| 119 | + securityContext: |
| 120 | + runAsNonRoot: true |
| 121 | +---- |
| 122 | ++ |
| 123 | +-- |
| 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. |
| 127 | +-- |
| 128 | ++ |
| 129 | +A new pod is created for the alternative recommender in the same namespace. |
| 130 | ++ |
| 131 | +[source,terminal] |
| 132 | +---- |
| 133 | +$ oc get pods |
| 134 | +---- |
| 135 | ++ |
| 136 | +.Example output |
| 137 | +[source,terminal] |
| 138 | +---- |
| 139 | +NAME READY STATUS RESTARTS AGE |
| 140 | +frontend-845d5478d-558zf 1/1 Running 0 4m25s |
| 141 | +frontend-845d5478d-7z9gx 1/1 Running 0 4m25s |
| 142 | +frontend-845d5478d-b7l4j 1/1 Running 0 4m25s |
| 143 | +vpa-alt-recommender-55878867f9-6tp5v 1/1 Running 0 9s |
| 144 | +---- |
| 145 | + |
| 146 | +. Configure a VPA CR that includes the name of the alternative recommender `Deployment` object. |
| 147 | ++ |
| 148 | +.Example VPA CR to include the alternative recommender |
| 149 | +[source,yml] |
| 150 | +---- |
| 151 | +apiVersion: autoscaling.k8s.io/v1 |
| 152 | +kind: VerticalPodAutoscaler |
| 153 | +metadata: |
| 154 | + name: vpa-recommender |
| 155 | + namespace: <namespace_name> |
| 156 | +spec: |
| 157 | + recommenders: |
| 158 | + - name: alt-vpa-recommender <1> |
| 159 | + targetRef: |
| 160 | + apiVersion: "apps/v1" |
| 161 | + kind: Deployment <2> |
| 162 | + name: frontend |
| 163 | +---- |
| 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. |
0 commit comments