|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * nodes/nodes-pods-autoscaling-custom.adoc |
| 4 | + |
| 5 | +:_content-type: PROCEDURE |
| 6 | +[id="nodes-pods-autoscaling-custom-creating-job_{context}"] |
| 7 | += Adding a custom metrics autoscaler to a job |
| 8 | + |
| 9 | +You can create a custom metrics autoscaler for any `Job` object. |
| 10 | + |
| 11 | +.Prerequisites |
| 12 | + |
| 13 | +* The Custom Metrics Autoscaler Operator must be installed. |
| 14 | +
|
| 15 | +.Procedure |
| 16 | + |
| 17 | +. Create a YAML file similar to the following: |
| 18 | ++ |
| 19 | +[source,yaml,options="nowrap"] |
| 20 | +---- |
| 21 | +kind: ScaledJob |
| 22 | +apiVersion: keda.sh/v1alpha1 |
| 23 | +metadata: |
| 24 | + name: scaledjob |
| 25 | + namespace: my-namespace |
| 26 | +spec: |
| 27 | + failedJobsHistoryLimit: 5 |
| 28 | + jobTargetRef: |
| 29 | + activeDeadlineSeconds: 600 <1> |
| 30 | + backoffLimit: 6 <2> |
| 31 | + parallelism: 1 <3> |
| 32 | + completions: 1 <4> |
| 33 | + template: <5> |
| 34 | + metadata: |
| 35 | + name: pi |
| 36 | + spec: |
| 37 | + containers: |
| 38 | + - name: pi |
| 39 | + image: perl |
| 40 | + command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"] |
| 41 | + maxReplicaCount: 100 <6> |
| 42 | + pollingInterval: 30 <7> |
| 43 | + successfulJobsHistoryLimit: 5 <8> |
| 44 | + failedJobsHistoryLimit: 5 <9> |
| 45 | + envSourceContainerName <10> |
| 46 | + rolloutStrategy: gradual <11> |
| 47 | + scalingStrategy: <12> |
| 48 | + strategy: "custom" |
| 49 | + customScalingQueueLengthDeduction: 1 |
| 50 | + customScalingRunningJobPercentage: "0.5" |
| 51 | + pendingPodConditions: |
| 52 | + - "Ready" |
| 53 | + - "PodScheduled" |
| 54 | + - "AnyOtherCustomPodCondition" |
| 55 | + multipleScalersCalculation : "max" |
| 56 | + triggers: |
| 57 | + - type: prometheus <13> |
| 58 | + metadata: |
| 59 | + serverAddress: https://thanos-querier.openshift-monitoring.svc.cluster.local:9092 |
| 60 | + namespace: kedatest |
| 61 | + metricName: http_requests_total |
| 62 | + threshold: '5' |
| 63 | + query: sum(rate(http_requests_total{job="test-app"}[1m])) |
| 64 | + authModes: "bearer" |
| 65 | + - authenticationRef: <14> |
| 66 | + name: prom-triggerauthentication |
| 67 | + metadata: |
| 68 | + name: prom-triggerauthentication |
| 69 | + type: object |
| 70 | + - authenticationRef: <15> |
| 71 | + name: prom-cluster-triggerauthentication |
| 72 | + metadata: |
| 73 | + name: prom-cluster-triggerauthentication |
| 74 | + type: object |
| 75 | +---- |
| 76 | +<1> Specifies the maximum duration the job can run. |
| 77 | +<2> Specifies the number of retries for a job. The default is `6`. |
| 78 | +<3> Optional: Specifies how many pod replicas a job should run in parallel; defaults to `1`. |
| 79 | +* For non-parallel jobs, leave unset. When unset, the default is `1`. |
| 80 | +<4> Optional: Specifies how many successful pod completions are needed to mark a job completed. |
| 81 | +* For non-parallel jobs, leave unset. When unset, the default is `1`. |
| 82 | +* For parallel jobs with a fixed completion count, specify the number of completions. |
| 83 | +* For parallel jobs with a work queue, leave unset. When unset the default is the value of the `parallelism` parameter. |
| 84 | +<5> Specifies the template for the pod the controller creates. |
| 85 | +<6> Optional: Specifies the maximum number of replicas when scaling up. The default is `100`. |
| 86 | +<7> Optional: Specifies the interval in seconds to check each trigger on. The default is `30`. |
| 87 | +<8> Optional: Specifies the number of successful finished jobs should be kept. The default is `100`. |
| 88 | +<9> Optional: Specifies how many failed jobs should be kept. The default is `100`. |
| 89 | +<10> Optional: Specifies the name of the container in the target resource, from which the custom autoscaler gets environment variables holding secrets and so forth. The default is `.spec.template.spec.containers[0]`. |
| 90 | +<11> Optional: Specifies whether existing jobs are terminated whenever a scaled job is being updated: |
| 91 | ++ |
| 92 | +-- |
| 93 | +* `default`: The autoscaler terminates an existing job if its associated scaled job is updated. The autoscaler recreates the job with the latest specs. |
| 94 | +* `gradual`: The autoscaler does not terminate an existing job if its associated scaled job is updated. The autoscaler creates new jobs with the latest specs. |
| 95 | +-- |
| 96 | ++ |
| 97 | +<12> Optional: Specifies a scaling strategy: `default`, `custom`, or `accurate`. The default is `default`. For more information, see the link in the "Additional resources" section that follows. |
| 98 | +<13> Specifies the trigger to use as the basis for scaling, as described in the "Understanding the custom metrics autoscaler triggers" section. |
| 99 | +<14> Optional: Specifies a trigger authentication, as described in the "Creating a custom metrics autoscaler trigger authentication" section. |
| 100 | +<15> Optional: Specifies a cluster trigger authentication, as described in the "Creating a custom metrics autoscaler trigger authentication" section. |
| 101 | ++ |
| 102 | +[NOTE] |
| 103 | +==== |
| 104 | +It is not necessary to specify both a namespace trigger authentication and a cluster trigger authentication. |
| 105 | +==== |
| 106 | + |
| 107 | +. Create the custom metrics autoscaler: |
| 108 | ++ |
| 109 | +[source,terminal] |
| 110 | +---- |
| 111 | +$ oc create -f <file-name>.yaml |
| 112 | +---- |
| 113 | + |
| 114 | +.Verification |
| 115 | + |
| 116 | +* View the command output to verify that the custom metrics autoscaler was created: |
| 117 | ++ |
| 118 | +[source,terminal] |
| 119 | +---- |
| 120 | +$ oc get scaledjob <scaled_job_name> |
| 121 | +---- |
| 122 | ++ |
| 123 | +.Example output |
| 124 | +[source,terminal] |
| 125 | +---- |
| 126 | +NAME MAX TRIGGERS AUTHENTICATION READY ACTIVE AGE |
| 127 | +scaledjob 100 prometheus prom-triggerauthentication True True 8s |
| 128 | +---- |
| 129 | ++ |
| 130 | +Note the following fields in the output: |
| 131 | ++ |
| 132 | +* `TRIGGERS`: Indicates the trigger, or scaler, that is being used. |
| 133 | +* `AUTHENTICATION`: Indicates the name of any trigger authentication being used. |
| 134 | +* `READY`: Indicates whether the scaled object is ready to start scaling: |
| 135 | +** If `True`, the scaled object is ready. |
| 136 | +** If `False`, the scaled object is not ready because of a problem in one or more of the objects you created. |
| 137 | +* `ACTIVE`: Indicates whether scaling is taking place: |
| 138 | +** If `True`, scaling is taking place. |
| 139 | +** If `False`, scaling is not taking place because there are no metrics or there is a problem in one or more of the objects you created. |
| 140 | +
|
0 commit comments