|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * knative-serving/config-applications/configuring-revision-timeouts.adoc |
| 4 | + |
| 5 | +:_mod-docs-content-type: PROCEDURE |
| 6 | +[id="configuring-default-route-timeouts-globally_{context}"] |
| 7 | += Configuring the default route timeouts globally |
| 8 | + |
| 9 | +By configuring the route timeouts globally, you can ensure consistent timeout settings across all services, simplifying management for workloads that have similar timeout needs and reducing the need for individual adjustments. |
| 10 | + |
| 11 | +You can configure the route timeouts globally by updating the `ROUTE_HAPROXY_TIMEOUT` environment value in your `serverless-operator` subscription and updating the `max-revision-timeout-seconds` field in your `KnativeServing` custom resource (CR). This applies the timeout changes across all Knative services, and you can deploy services with specific timeouts up to the maximum value set. |
| 12 | + |
| 13 | +.Procedure |
| 14 | + |
| 15 | +. Set the value of `ROUTE_HAPROXY_TIMEOUT` in your subscription to your required timeout in seconds by running the following command: |
| 16 | ++ |
| 17 | +.Setting the `ROUTE_HAPROXY_TIMEOUT` value to 900 seconds |
| 18 | +[source,terminal] |
| 19 | +---- |
| 20 | +$ oc patch subscription.operators.coreos.com serverless-operator -n openshift-serverless --type='merge' -p '{"spec": {"config": {"env": [{"name": "ROUTE_HAPROXY_TIMEOUT", "value": "900"}]}}}' |
| 21 | +---- |
| 22 | ++ |
| 23 | +The `ROUTE_HAPROXY_TIMEOUT` environment variable is managed by the Serverless Operator and by default is set to `600`. Set the value of `ROUTE_HAPROXY_TIMEOUT` in your subscription to your required timeout in seconds by running the following command. Note that this causes pods to be redeployed in the `openshift-serverless` namespace. |
| 24 | ++ |
| 25 | +[NOTE] |
| 26 | +==== |
| 27 | +If you created your routes manually and disabled auto-generation with the `serving.knative.openshift.io/disableRoute` annotation, you can configure the timeouts directly in the route definitions. |
| 28 | +==== |
| 29 | + |
| 30 | +. Set the maximum revision timeout in your `KnativeServing` CR: |
| 31 | ++ |
| 32 | +.`KnativeServing` CR with `max-revision-timeout-seconds` set to 900 seconds |
| 33 | +[source,yaml] |
| 34 | +---- |
| 35 | +apiVersion: operator.knative.dev/v1beta1 |
| 36 | +kind: KnativeServing |
| 37 | +metadata: |
| 38 | + name: knative-serving |
| 39 | +spec: |
| 40 | + config: |
| 41 | + defaults: |
| 42 | + max-revision-timeout-seconds: "900" |
| 43 | +#... |
| 44 | +---- |
| 45 | ++ |
| 46 | +The Serverless Operator automatically adjusts the `terminationGracePeriod` value of the activator to the set maximum revision timeout value to avoid request termination in cases where activator pods are being terminated themselves. |
| 47 | ++ |
| 48 | +. Optional: Verify that the timeout has been set by running the following command: |
| 49 | ++ |
| 50 | +[source,terminal] |
| 51 | +---- |
| 52 | +$ oc get deployment activator -n knative-serving -o jsonpath="{.spec.template.spec.terminationGracePeriodSeconds}" |
| 53 | +---- |
| 54 | + |
| 55 | +. If necessary for your cloud provider, adjust the load balancer timeout by running the following command: |
| 56 | ++ |
| 57 | +.Load balancer timeout adjustment for AWS Classic LB |
| 58 | +[source,terminal] |
| 59 | +---- |
| 60 | +$ oc -n openshift-ingress-operator patch ingresscontroller/default --type=merge --patch=' \ |
| 61 | + {"spec":{"endpointPublishingStrategy": \ |
| 62 | + {"type":"LoadBalancerService", "loadBalancer": \ |
| 63 | + {"scope":"External", "providerParameters":{"type":"AWS", "aws": \ |
| 64 | + {"type":"Classic", "classicLoadBalancer": \ |
| 65 | + {"connectionIdleTimeout":"20m"}}}}}}}' |
| 66 | +---- |
| 67 | + |
| 68 | +. Deploy a Knative service with the desired timeouts less or equal to the `max-revision-timeout-seconds` variable: |
| 69 | ++ |
| 70 | +.A Service definition with timeouts set to 800 seconds |
| 71 | +[source,yaml] |
| 72 | +---- |
| 73 | +apiVersion: serving.knative.dev/v1 |
| 74 | +kind: Service |
| 75 | +metadata: |
| 76 | + name: example-service-name |
| 77 | +spec: |
| 78 | + template: |
| 79 | + spec: |
| 80 | + timeoutSeconds: 800 |
| 81 | + responseStartTimeoutSeconds: 800 |
| 82 | +---- |
| 83 | ++ |
| 84 | +[IMPORTANT] |
| 85 | +==== |
| 86 | +When using {SMProductShortName}, if the activator pod is stopped while a long-running request is in-flight, the request is interrupted. |
| 87 | +To avoid request interruptions, you must adjust the value of the `terminationDrainDuration` field in the `ServiceMeshControlPlane` CR: |
| 88 | +[source,yaml] |
| 89 | +---- |
| 90 | +apiVersion: maistra.io/v2 |
| 91 | +kind: ServiceMeshControlPlane |
| 92 | +#... |
| 93 | +spec: |
| 94 | + techPreview: |
| 95 | + meshConfig: |
| 96 | + defaultConfig: |
| 97 | + terminationDrainDuration: 1000s <1> |
| 98 | +#... |
| 99 | +---- |
| 100 | +<1> Ensure that the value exceeds the request duration to avoid the Istio proxy shutdown, which would interrupt the request. |
| 101 | +==== |
| 102 | + |
| 103 | +.Verification |
| 104 | + |
| 105 | +* If you are using Kourier, you can verify the current value of the timeout at the {ocp-product-title} route by running the following command: |
| 106 | ++ |
| 107 | +[source,terminal] |
| 108 | +---- |
| 109 | +$ oc get route <route_name> -n knative-serving-ingress ess -o jsonpath="{.metadata.annotations.haproxy\.router\.openshift\.io/timeout}" |
| 110 | +800s |
| 111 | +---- |
0 commit comments