Workflow Scaling and Disruption Protection
This document describes the different alternatives for scaling a workflow and how to configure horizontal pod autoscaling and pod disruption budgets.
Scaling a Workflow
The SonataFlow CRD exposes the Kubernetes scale subresource, which enables users and controllers (such as Horizontal Pod Autoscalers) to scale workflows using the standard Kubernetes API.
Below you can see different options for scaling an example-workflow workflow.
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:
flow:
# Only a fragment of the workflow is shown for simplicity
start: ExampleStartState
|
Workflows deployed with the |
Querying the workflow scale subresource
To query the workflow scale subresource you can use the following command:
kubectl get --subresource=scale example-workflow -n example-workflow-namespace -o yaml
You must get an output similar to the following:
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 (1)
status:
replicas: 1 (2)
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 (3)
| 1 | Number of configured replicas. |
| 2 | Number of currently available replicas. |
| 3 | Selector to query the observed Pods. |
Scaling the workflow
To scale the workflow you can use any of the following alternatives:
kubectl scale workflow example-workflow -n example-workflow-namespace --replicas=3
You must get an output similar to the following:
sonataflow.sonataflow.org/example-workflow scaled
SonataFlow CRapiVersion: 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 (1)
flow:
# Only a fragment of the workflow is shown for simplicity
start: ExampleStartState
| 1 | Use the field spec.podTemplate.replicas to configure the number of replicas. |
kubectl apply -f example-workflow.yaml -n example-workflow-namespace
You must get an output similar to the following:
sonataflow.sonataflow.org/example-workflow configured
spec.podTemplate.replicaskubectl patch workflow example-workflow -n example-workflow-namespace \
--type merge \
-p '{
"spec": {
"podTemplate": {
"replicas": 3
}
}
}'
You must get an output similar to the following:
sonataflow.sonataflow.org/example-workflow patched
Horizontal Pod Autoscaling configuration
Before configuring a HorizontalPodAutoscaler for a workflow, ensure that the resources you want the scaler to use as metrics are defined in the SonataFlow CR.
The following example shows how to configure such resources:
SonataFlow CRapiVersion: 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: (1)
resources:
requests:
cpu: 100m (2)
memory: 256Mi (3)
limits:
cpu: 500m
memory: 512Mi
flow:
# Only a fragment of the workflow is shown for simplicity
start: ExampleStartState
| 1 | The field spec.podTemplate.container supports most of the standard PodSpec configurations. For more information see. |
| 2 | Example of cpu request resource configuration. |
| 3 | Example of memory request resource configuration. |
|
|
The following example shows how to configure a HorizontalPodAutoscaler:
HorizontalPodAutoscaler configurationapiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: example-autoscaler
spec:
scaleTargetRef: (1)
apiVersion: sonataflow.org/v1alpha08
kind: SonataFlow
name: example-workflow
minReplicas: 3
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu (2)
target:
type: Utilization
averageUtilization: 70
| 1 | Refer the target workflow by configuring the apiVersion, kind and name. |
| 2 | Example of a metric based on the cpu resource utilization. |
|
Workflows deployed with |
For more information on configuring HorizonalPodAutoscalers you can refer to the Kubernetes documentation
Found an issue?
If you find an issue or any misleading information, please feel free to report it here. We really appreciate it!