Chapter 9. Workflow scaling and disruption protection
You can configure scaling and disruption protection for your OpenShift Serverless Logic workflows to handle varying workloads efficiently and maintain availability during cluster maintenance operations. This section describes how to scale workflows manually, configure horizontal pod autoscaling (HPA) for automatic scaling based on resource utilization metrics, and configure pod disruption budgets (PDB) to maintain availability during voluntary disruptions.
Proper scaling and disruption protection configuration helps ensure your workflows can handle increased load while optimizing resource usage and maintaining availability in your Red Hat OpenShift Serverless cluster.
The following features require OpenShift Serverless Logic 1.38 or later and are not available in earlier versions.
9.1. Scaling a workflow manually Copy linkLink copied to clipboard!
The SonataFlow custom resource definition (CRD) exposes the Kubernetes scale subresource, which enables you to scale workflows using the standard Kubernetes API. You can scale workflows manually using several methods.
The following feature requires OpenShift Serverless Logic 1.38 or later and is not available in earlier versions.
Workflows deployed with the dev profile are intended for development use and are not designed for scaling.
9.1.1. Querying the workflow scale subresource Copy linkLink copied to clipboard!
To query the workflow scale subresource, run the following command:
$ oc get sonataflow <workflow_name> -n <namespace> --subresource=scale -o yaml
apiVersion: autoscaling/v1
kind: Scale
metadata:
creationTimestamp: "2026-02-12T12:48:46Z"
name: example-workflow
namespace: example-workflow-namespace
resourceVersion: "38397"
uid: de53b549-dcb5-4b46-bb4e-9a576341e099
spec:
replicas: 1
status:
replicas: 1
selector: app=example-workflow,app.kubernetes.io/component=serverless-workflow,app.kubernetes.io/instance=example-workflow,app.kubernetes.io/managed-by=sonataflow-operator,app.kubernetes.io/name=example-workflow,app.kubernetes.io/version=main,sonataflow.org/workflow-app=example-workflow,sonataflow.org/workflow-namespace=example-workflow-namespace
The output displays the following information:
-
spec.replicas- Number of configured replicas. -
status.replicas- Number of currently available replicas. -
status.selector- Selector to query the observed pods.
9.1.2. Scaling methods Copy linkLink copied to clipboard!
You can scale a workflow using any of the following methods:
Scaling using the oc scale command
Run the following command:
$ oc scale sonataflow <workflow_name> -n <namespace> --replicas=<number>where:
<workflow_name>- Specifies the name of your workflow.
<namespace>- Specifies the namespace where your workflow is deployed.
<number>- Specifies the desired number of replicas.
$ oc scale sonataflow example-workflow -n example-workflow-namespace --replicas=3
sonataflow.sonataflow.org/example-workflow scaled
Scaling by configuring the SonataFlow custom resource
Edit your
SonataFlowCR to include thespec.podTemplate.replicasfield:apiVersion: sonataflow.org/v1alpha08 kind: SonataFlow metadata: name: example-workflow namespace: example-workflow-namespace annotations: sonataflow.org/description: Example Workflow sonataflow.org/version: 0.0.1 sonataflow.org/profile: preview spec: podTemplate: replicas: 3 flow: start: ExampleStartState # ...Use the
spec.podTemplate.replicasfield to configure the number of replicas.Apply the configuration:
$ oc apply -f example-workflow.yaml -n example-workflow-namespacesonataflow.sonataflow.org/example-workflow configured
Scaling by patching the SonataFlow custom resource
Run the following command:
$ oc patch sonataflow <workflow_name> -n <namespace> \ --type merge \ -p '{ "spec": { "podTemplate": { "replicas": <number> } } }'where:
<workflow_name>- Specifies the name of your workflow.
<namespace>- Specifies the namespace where your workflow is deployed.
<number>- Specifies the desired number of replicas.
$ oc patch sonataflow example-workflow -n example-workflow-namespace \ --type merge \ -p '{ "spec": { "podTemplate": { "replicas": 3 } } }'+
sonataflow.sonataflow.org/example-workflow patched
9.2. Configuring horizontal pod autoscaling for workflows Copy linkLink copied to clipboard!
By using a HorizontalPodAutoscaler (HPA), you can configure how a Kubernetes workload resource scales based on a set of metrics, such as CPU or memory usage.
Workload resources that support autoscaling expose the scale subresource, which allows Kubernetes to adjust the number of replicas dynamically. When you configure horizontal pod autoscaling for a workflow, the OpenShift Serverless Logic Operator automatically manages the coordination between the workflow scale subresource and the associated Kubernetes Deployment, making the workflow pods scale accordingly.
Before configuring an HPA for a workflow, you must define the resources to be used as scaling metrics in the SonataFlow CR.
The following feature requires OpenShift Serverless Logic 1.38 or later and is not available in earlier versions.
Prerequisites
- You have installed the OpenShift Serverless Logic Operator.
-
You have deployed a workflow using the
previeworgitopsprofile.
Procedure
Configure resource requests in your
SonataFlowCR:apiVersion: sonataflow.org/v1alpha08 kind: SonataFlow metadata: name: example-workflow namespace: example-workflow-namespace annotations: sonataflow.org/description: Example Workflow sonataflow.org/version: 0.0.1 sonataflow.org/profile: preview spec: podTemplate: container: resources: requests: cpu: 100m memory: 256Mi limits: cpu: 500m memory: 512Mi flow: start: ExampleStartState # ...This example configures the following resource settings:
-
The
spec.podTemplate.containerfield supports most of the standardPodSpecconfigurations. For more information, see Container in the Kubernetes documentation. -
The
resources.requests.cpufield specifies the CPU request for the workflow container. The
resources.requests.memoryfield specifies the memory request for the workflow container.NoteHorizontalPodAutoscalersuse the request resources for metrics calculations. The resource limits in the example are illustrative and are not used for scaling decisions.
-
The
Create a
HorizontalPodAutoscalerCR:apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler metadata: name: example-autoscaler namespace: example-workflow-namespace spec: scaleTargetRef: apiVersion: sonataflow.org/v1alpha08 kind: SonataFlow name: example-workflow minReplicas: 2 maxReplicas: 5 metrics: - type: Resource resource: name: cpu target: type: Utilization averageUtilization: 70This configuration includes the following settings:
-
The
scaleTargetReffield references the target workflow by specifying theapiVersion,kind, andname. -
The
metricsfield defines a metric based on CPU resource utilization.
-
The
Apply the
HorizontalPodAutoscalerconfiguration by running the following command:$ oc apply -f example-autoscaler.yaml -n example-workflow-namespace
Workflows deployed with spec.podTemplate.deploymentModel: knative cannot be scaled with a HorizontalPodAutoscaler because Knative Serving automatically controls the number of replicas. Additionally, workflows deployed using the dev profile are not designed to scale.
9.3. Configuring pod disruption budgets for workflows Copy linkLink copied to clipboard!
By using a PodDisruptionBudget (PDB), you can configure the required availability of a workflow during a voluntary disruption, such as a node drain, in the cluster.
A PDB limits the number of pods that can be unavailable simultaneously during such disruptions, ensuring that the workflow maintains the desired level of availability.
In general, any tool that needs to guarantee availability should respect the PDB by using the Kubernetes Eviction API instead of directly deleting pods or deployments. The Eviction API ensures that disruption constraints defined by the PDB are honored.
The OpenShift Serverless Logic Operator can automatically generate a PodDisruptionBudget for a workflow based on the SonataFlow CR configuration.
The following feature requires OpenShift Serverless Logic 1.38 or later and is not available in earlier versions.
Available fields for PDB configuration
To configure a PDB for a workflow, use the spec.podTemplate.podDisruptionBudget field in your SonataFlow CR:
# ...
spec:
podTemplate:
podDisruptionBudget:
minAvailable: 2
maxUnavailable: 1
# ...
This configuration includes the following fields:
-
minAvailable- Specifies the number of pods that must still be available after an eviction. This value can be either an absolute number or a percentage, for example2or50%. -
maxUnavailable- Specifies the number of pods that can be unavailable after an eviction. This value can be either an absolute number or a percentage, for example1or50%.
The minAvailable and maxUnavailable fields are mutually exclusive. You must configure only one of these fields. If both fields are specified, the minAvailable value takes precedence.
The semantics of these fields are aligned with the corresponding fields in the Kubernetes PodDisruptionBudget. For more information, see Pod Disruption Budgets in the Kubernetes documentation.
PodDisruptionBudget generation rules
The OpenShift Serverless Logic Operator applies the following rules to generate the PDB:
-
The PDB is generated only if the workflow has the
spec.podTemplate.podDisruptionBudgetfield properly configured. -
The PDB is generated only if the workflow has
spec.podTemplate.replicasconfigured with a value greater than 1. -
If the workflow has a configured
HorizontalPodAutoscaler(HPA), the HPAspec.minReplicasvalue takes precedence over the workflowspec.podTemplate.replicasvalue. -
When an HPA is configured, the PDB is generated only if the HPA
spec.minReplicasvalue is greater than 1. -
If the workflow is scaled to zero (that is,
spec.podTemplate.replicas = 0), no PDB is generated.
If any of the above conditions change after a PDB has been generated, for example, if the workflow is rescaled to 1, the previously generated PDB is automatically deleted.
Workflows deployed with spec.podTemplate.deploymentModel: knative cannot use a PodDisruptionBudget because Knative Serving automatically manages the number of replicas, and a PDB cannot reliably enforce minimum availability. Additionally, workflows deployed using the dev profile are not designed to scale.
Prerequisites
- You have installed the OpenShift Serverless Logic Operator.
-
You have deployed a workflow using the
previeworgitopsprofile.
Procedure
Configure a PDB in your
SonataFlowCR:apiVersion: sonataflow.org/v1alpha08 kind: SonataFlow metadata: name: example-workflow namespace: example-workflow-namespace annotations: sonataflow.org/description: Example Workflow sonataflow.org/version: 0.0.1 sonataflow.org/profile: preview spec: podTemplate: replicas: 2 podDisruptionBudget: minAvailable: 1 flow: start: ExampleStartState # ...This configuration includes the following settings:
-
replicas: 2- The workflow runs with 2 replicas. -
podDisruptionBudget.minAvailable: 1- The generated PDB ensures that 1 pod must remain available during a disruption.
-
Apply the configuration:
$ oc apply -f example-workflow.yaml -n example-workflow-namespace
Verification
Verify that the PDB was created:
$ oc get pdb -n example-workflow-namespaceNAME MIN AVAILABLE MAX UNAVAILABLE ALLOWED DISRUPTIONS AGE example-workflow 1 N/A 1 5m
Given this configuration, the OpenShift Serverless Logic Operator generates the following PDB for the workflow:
kind: PodDisruptionBudget
apiVersion: policy/v1
metadata:
name: example-workflow
namespace: example-workflow-namespace
ownerReferences:
- apiVersion: sonataflow.org/v1alpha08
kind: SonataFlow
name: example-workflow
uid: 5b7f96d4-1ddf-45f7-af38-555d93339cca
controller: true
blockOwnerDeletion: true
spec:
minAvailable: 1
selector:
matchLabels:
app: example-workflow
app.kubernetes.io/component: serverless-workflow
app.kubernetes.io/instance: example-workflow
app.kubernetes.io/managed-by: sonataflow-operator
app.kubernetes.io/name: example-workflow
sonataflow.org/workflow-app: example-workflow
sonataflow.org/workflow-namespace: example-workflow-namespace
This generated PDB has the following characteristics:
- The PDB has the same name as the workflow.
- The PDB is created in the same namespace as the workflow.
- The workflow is configured as the PDB owner.
-
The PDB
minAvailablefield is configured with the value fromspec.podTemplate.podDisruptionBudget.minAvailablein the workflow CR. - The PDB selector is configured to target the workflow pods.