Service Mesh (ASM) provides declarative circuit breaking through the ASMCircuitBreaker Custom Resource Definition (CRD). This reference covers every field in the ASMCircuitBreaker spec, along with configuration examples.
For a step-by-step setup guide, see Use route-level circuit breaking in ASM.
Full schema overview
The following YAML shows every available field and its nesting hierarchy:
apiVersion: istio.alibabacloud.com/v1 # v1beta1 for ASM < 1.15.3.105
kind: ASMCircuitBreaker
metadata:
name: <circuit-breaker-name>
spec:
workloadSelector: # Required. Labels to select target pods/VMs.
labels:
<label-key>: <label-value>
isGateway: false # Whether this applies to a gateway.
applyToTraffic: sidecar_outbound # ASM 1.25+. Traffic direction.
configs: # Required. One or more circuit breaking rules.
- name: <config-name>
target_services: # ASM 1.25+. Services to protect.
- kind: Service # Service | ServiceEntry | VirtualService
namespace: <namespace>
name: <service-name>
port: <port-number>
section_name: <route-name> # VirtualService only.
match: # Route-level match conditions.
vhost:
name: <virtual-host-name>
port: <port>
route:
name_match: <route-name>
header_match: # ASM 1.16+.
- name: <header-name>
exact_match: <value> # Choose one match type.
regex_match: <pattern>
prefix_match: <prefix>
suffix_match: <suffix>
present_match: true
invert_match: false
breaker_config: # Circuit breaking thresholds.
window_size: 10s # Statistics time window (max 12s).
break_duration: 30s # How long the circuit stays open.
slow_request_rt: <duration> # Slow request latency threshold.
average_request_rt: <duration> # Average response time.
max_slow_requests: <count> # Max slow requests before tripping.
error_percent: # 5xx error percentage threshold.
value: <0-100>
gateway_error_percent: # 502/503/504 error threshold. ASM 1.24.6.54+.
value: <0-100>
min_request_amount: 0 # Min requests before evaluating error_percent.
custom_response: # Response returned when circuit is open.
status_code: <http-status-code>
header_to_add:
<header-name>: <header-value>
body: <response-body>apiVersion
| ASM version | apiVersion |
|---|---|
| 1.15.3.105 or later | istio.alibabacloud.com/v1 |
| Earlier than 1.15.3.105 | istio.alibabacloud.com/v1beta1 |
If you previously deployed an ASMCircuitBreaker in a Container Service for Kubernetes (ACK) cluster using v1beta1, update the apiVersion field to istio.alibabacloud.com/v1 and redeploy.
spec
applyToTraffic
This field requires ASM 1.25 or later.
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| applyToTraffic | string | No | sidecar_outbound | Traffic direction for the circuit breaking policy. |
Valid values:
| Value | Description |
|---|---|
sidecar_inbound | Inbound traffic to a sidecar proxy. The application with the sidecar acts as a server. |
sidecar_outbound | Outbound traffic from a sidecar proxy. The application with the sidecar acts as a client. |
waypoint | Traffic processed by a waypoint proxy in Ambient mode. |
gateway | Gateway traffic. |
ASMCircuitBreakerSpec
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| workloadSelector | map<string, string> | Yes | -- | Labels to select pods or VMs. Scoped to the namespace of the resource. See WorkloadSelector. |
| isGateway | bool | No | false | When true, applies the configuration to a gateway. |
| configs | CircuitBreakerConfig[] | Yes | -- | One or more circuit breaking configurations. |
CircuitBreakerConfig
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| name | string | No | -- | Name of this circuit breaking configuration. |
| match | CircuitBreakerMatch | No | -- | Route-level match conditions. See CircuitBreakerMatch. |
| breaker_config | BreakerConfig | No | -- | Circuit breaking thresholds. See BreakerConfig. |
| target_services | TargetServiceRef[] | No | -- | Target services for the policy. ASM 1.25+ only. See TargetServiceRef. |
TargetServiceRef
These fields require ASM 1.25 or later.
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| kind | string | No | Service | Resource type. Valid values: Service, ServiceEntry, VirtualService. |
| name | string | Yes | -- | Name of the target service. |
| namespace | string | No | Same as the ASMCircuitBreaker resource | Namespace of the target service. |
| port | int32 | No | -- | Port of the target service. |
| section_name | string | No | -- | Name of a route defined in the VirtualService. Only valid when kind is VirtualService. |
TargetServiceRef examples
Target a Service
Apply circuit breaking to port 8000 of the httpbin Service in the default namespace:
target_services:
- kind: Service
namespace: default
name: httpbin
port: 8000Target a ServiceEntry
Given the following ServiceEntry:
apiVersion: networking.istio.io/v1
kind: ServiceEntry
metadata:
name: se-httpbin-external
spec:
hosts:
- httpbin.test.com
location: MESH_EXTERNAL
ports:
- name: http
number: 80
protocol: HTTP
- name: https
number: 443
protocol: HTTPS
resolution: DNSApply circuit breaking to port 80 of this ServiceEntry:
target_services:
- kind: ServiceEntry
namespace: default
name: se-httpbin-external
port: 80Target a VirtualService route
Given the following VirtualService:
apiVersion: networking.istio.io/v1
kind: VirtualService
metadata:
name: vs-httpbin
spec:
hosts:
- httpbin.test.com
http:
- name: default
route:
- destination:
host: httpbin
port:
number: 8000Apply circuit breaking to the HTTP route named default:
target_services:
- kind: VirtualService
namespace: default
name: vs-httpbin
section_name: defaultBreakerConfig
Circuit breaking thresholds fall into two categories:
Slow request detection:
slow_request_rt,max_slow_requests, andaverage_request_rtdefine when latency-based tripping occurs.Error rate detection:
error_percentandgateway_error_percentdefine when error-based tripping occurs.
Both categories share window_size, break_duration, and min_request_amount.
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| window_size | Duration | No | 10s | Time window for collecting request statistics. Maximum: 12s. |
| break_duration | Duration | No | 30s | Duration the circuit breaker stays open after tripping. |
| slow_request_rt | Duration | No | -- | Latency threshold for slow requests. Requests exceeding this response time are counted as slow. |
| average_request_rt | Duration | No (Required before ASM 1.14) | -- | Average response time for the service. Example: 0.01s. |
| max_slow_requests | uint32 | No | -- | Maximum number of slow requests allowed within the time window. This must be an integer, for example, 1000. The circuit breaker trips when this count is exceeded. |
| error_percent | Percent | No | -- | 5xx error rate threshold. The circuit breaker trips when the percentage of 5xx errors within the time window exceeds this value. |
| gateway_error_percent | Percent | No | -- | Gateway error rate threshold (502, 503, 504 only). ASM 1.24.6.54+ only. |
| min_request_amount | uint32 | No | 0 | Minimum number of requests required before error_percent is evaluated. Prevents tripping on a small sample size. |
| custom_response | CustomResponse | No | -- | Custom response returned to clients when the circuit breaker is open. See CustomResponse. |
CustomResponse
Defines the response returned to clients when the circuit breaker rejects a request.
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| status_code | int32 | No | -- | HTTP status code of the response. |
| header_to_add | map\[string\]string | No | -- | Headers to include in the response. |
| body | string | No | -- | Body of the response. |
CircuitBreakerMatch
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| vhost | VirtualHostMatch | No | -- | Virtual host match conditions. See VirtualHostMatch. |
VirtualHostMatch
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| name | string | No | -- | Virtual host name to match. |
| port | int | No | -- | Request port to match. |
| route | RouteMatch | Yes | -- | Routing rule to match. See RouteMatch. |
RouteMatch
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| name_match | string | Yes (gateway) / No (sidecar) | -- | Route name to match. Corresponds to a route name defined in a VirtualService. |
| header_match | HeaderMatcher[] | No | -- | Request header conditions. Multiple headers supported. ASM 1.16+ only. Requires the latest gateway and sidecar proxy versions. See Upgrade an ASM instance and Upgrade a sidecar proxy. |
HeaderMatcher
Specify exactly one match type per entry (regex_match, exact_match, prefix_match, suffix_match, or present_match).
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| name | string | No | -- | Header name. |
| regex_match | string | No | -- | Match the header value against a regular expression. |
| exact_match | string | No | -- | Match the header value exactly. |
| prefix_match | string | No | -- | Match header values that start with the specified string. |
| suffix_match | string | No | -- | Match header values that end with the specified string. |
| present_match | bool | No | -- | true: the header must be present (any value). false: the header must not be present. |
| invert_match | bool | No | false | true: invert the match result. false: use the original match result. |
Configuration examples
All examples use the applyToTraffic field to specify the traffic direction and breaker_config to set circuit breaking thresholds.
Client-side circuit breaking
Requires ASM 1.25.6.74 or later.
This configuration applies to outbound traffic from the sleep application to httpbin on port 8000. The circuit breaker trips when either condition is met within a 10-second window:
More than 60% of requests return 5xx errors.
More than 10 requests exceed the 100 ms response time threshold.
When the circuit breaker is open, clients receive a 499 status code with a custom response body and header.
apiVersion: istio.alibabacloud.com/v1
kind: ASMCircuitBreaker
metadata:
name: client-break
spec:
workloadSelector:
labels:
app: sleep
applyToTraffic: sidecar_outbound
configs:
- target_services:
- name: httpbin
port: 8000
breaker_config:
slow_request_rt: 0.1s
break_duration: 90s
window_size: 10s
max_slow_requests: 10
min_request_amount: 3
error_percent:
value: 60
custom_response:
header_to_add:
x-envoy-circuitbreak: "true"
body: "hello, break!"
status_code: 499Waypoint circuit breaking
Requires ASM 1.25.6.74 or later. Applies only to Ambient mode.
This configuration applies the same circuit breaking thresholds through a waypoint proxy named default:
apiVersion: istio.alibabacloud.com/v1
kind: ASMCircuitBreaker
metadata:
name: test
spec:
workloadSelector:
labels:
gateway.networking.k8s.io/gateway-name: default
applyToTraffic: waypoint
configs:
- target_services:
- name: httpbin
port: 8000
breaker_config:
slow_request_rt: 0.1s
break_duration: 90s
window_size: 10s
max_slow_requests: 10
min_request_amount: 3
error_percent:
value: 60
custom_response:
header_to_add:
x-envoy-circuitbreak: "true"
body: "hello, break!"
status_code: 499What's next
Use route-level circuit breaking in ASM: Step-by-step guide with deployment and verification.
Upgrade an ASM instance: Required for features that depend on specific ASM versions.
Upgrade a sidecar proxy: Keep sidecar proxies current for the latest circuit breaking capabilities.