Service Mesh (ASM) lets you declaratively define ASMGlobalRateLimiter configurations using a Custom Resource Definition (CRD) to implement global throttling. This topic describes the fields of the ASMGlobalRateLimiter CRD.
Configuration examples
Example 1: Server-side throttling
This example requires an ASM instance of version 1.25.6.74 or later.
The following example limits access to the httpbin application to once per minute.
Example 2: Client-side throttling
This example requires an ASM instance of version 1.25.6.74 or later.
The following example limits the sleep application to accessing the httpbin service only once per minute.
Example 3: Waypoint throttling
This example applies only to the Ambient mode and requires an ASM instance of version 1.25.6.74 or later.
This example configures a throttling rule for an application on the default waypoint. If a request contains the x-user request header, a bucket is allocated based on the header value to limit access to once per minute. If the request does not contain the header, access is limited to 20 times per minute.
spec
Field | Type | Required | Description |
workloadSelector | map<string, string> | Yes | One or more labels that specify a set of workloads on which the throttling rule takes effect. The scope of label-based search is restricted to the namespace in which the resources reside. For more information, see Workload Selector. |
isGateway | bool | No | Specifies whether the throttling rule takes effect on a gateway. Default value: false. |
rateLimitService | Yes | The configurations of the global throttling service. | |
configs | Yes | The global throttling rules. You can configure multiple rules. | |
applyToTraffic | string | No | The traffic type to which the rate limiting policy is applied. Optional parameters:
The default value is Note This field is supported only in ASM 1.25 and later versions. |
RateLimitServiceConfig
Field | Type | Required | Description |
host | string | Yes | The domain name of the cluster in which the global throttling service resides. |
port | int | Yes | The gRPC service port of the global throttling service. |
timeout | Duration | No | The timeout period for the mesh proxy to connect to the global throttling service. Examples: |
GlobalRateLimiterConfig
Field | Type | Required | Description |
name | string | Yes | The name of the throttling rule. |
match | Yes | The match criteria. | |
limit | Yes | The throttling threshold configurations. | |
limit_overrides | No | Specifies whether to override the configured throttling threshold. You can use this field to specify a throttling threshold individually for specific requests. You can configure multiple throttling threshold overrides. Note This field is supported only by ASM instances of V1.19.0 or later. | |
target_services | No | The service to which the throttling policy is applied. Note This field is supported only in ASM 1.25 and later versions. |
TargetServiceRef
This field is supported only in ASM 1.25 and later versions.
Field | Type | Required | Description |
kind | string | No | The kind of the service to which the rate limiting policy applies. Valid values:
The default value is |
name | string | Yes | The name of the service to which the rate limiting policy applies. |
namespace | string | No | The namespace where the service to which the rate limiting policy applies resides. The default value is the namespace where you define the rate limiting policy. |
port | int32 | No | The port of the service to which the rate limiting policy applies. |
section_name | string | No | Additional properties of the service. This field is valid only for
|
Example 1
The following example applies to port 8000 of the httpbin Service in the default namespace.
target_services:
- kind: Service
namespace: default
name: httpbin
port: 8000Example 2
Assume that the following ServiceEntry exists in the current instance.
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: DNSThe following policy applies to port 80 of this ServiceEntry.
target_services:
- kind: ServiceEntry
namespace: default
name: se-httpbin-external
port: 80Example 3
Assume that the following VirtualService exists in the current instance.
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: 8000The following policy applies to the routing rule named default in the VirtualService.
target_services:
- kind: VirtualService
namespace: default
name: vs-httpbin
section_name: defaultRatelimitMatch
Field | Type | Required | Description |
vhost | Yes | The match criteria for the virtual host. |
GlobalServiceLimitConfig
Field | Type | Required | Description |
unit | string | Yes | The unit of the throttling time. Valid values:
|
quota | int | Yes | The total number of requests allowed per unit time. |
GlobalRateLimitOverrideConfig
Field | Type | Required | Description |
request_match | Yes | The criteria that requests must match when a throttling threshold override configuration is applied. The throttling threshold specified in the override configuration is applied only to the requests that match the criteria. | |
limit | Yes | The throttling threshold specified in the throttling threshold override configuration. |
VirtualHostMatch
Field | Type | Required | Description |
name | string | Yes | The name of the virtual host to be matched. |
port | int | No | The request port to be matched. |
route | No | The name of the route corresponding to the request port to be matched. |
RouteMatch
Field | Type | Required | Description |
name_match | string | No | The name of the route to be matched. This field specifies a single route in a virtual service. |
header_match | No | The header of the service requests to be matched. You can configure multiple headers. Note In ASM instances of V1.19.0 and later, this field is deprecated. We recommend that you use GlobalRateLimitOverrideConfig to match requests. |
RequestMatcher
You can use multiple fields in the RequestMatcher section at the same time. If you do, a request is matched only if it meets the criteria of all specified fields.
Field | Type | Required | Description |
header_match | No | The header for matching requests. You can configure multiple headers. | |
remote_address | No | The source IP address for matching requests. | |
query_match | No | The query parameters for matching requests. You can configure multiple query parameters. |
RemoteAddressMatcher
Field | Type | Required | Description |
address | string | Yes | The source IP address for matching requests. |
v4_prefix_mask_len | uint32 | No | If you want to match an IPv4 address range, enter the subnet mask length of the IPv4 address in this field, and enter the IPv4 address in the address field. The address range calculated after the subnet mask is used will be matched. |
v6_prefix_mask_len | uint32 | No | If you want to match an IPv6 address range, enter the subnet mask length of the IPv6 address in this field, and enter the IPv6 address in the address field. The address range calculated after the subnet mask is used will be matched. |
HeaderMatcher
Field | Type | Required | Description | |
name | string | No | The name of the header. | |
Select one of the following | regex_match | string | No | The regular expression used to perform a header match. |
exact_match | string | No | The value used to perform an exact match. | |
prefix_match | string | No | The prefix used to perform a prefix match. | |
suffix_match | string | No | The suffix used to perform a suffix match. | |
present_match | bool | No |
| |
invert_match | bool | No | The default value is false.
| |
QueryParameterMatcher
Field | Type | Required | Description | |
name | string | Yes | The name of the query parameter. | |
Select one of the following | exact_match | string | No | The value used to perform an exact match on the query parameter. |
prefix_match | string | No | The prefix used to perform a prefix match on the query parameter. | |
suffix_match | string | No | The suffix used to perform a suffix match on the query parameter. | |
regex_match | string | No | The regular expression used to perform a regular expression match on the query parameter. | |
contains_match | string | No | The content used to perform a contains match on the query parameter. The value of the query parameter must contain the specified substring. | |
present_match | bool | No |
| |
ignore_case | bool | No | Specifies whether to ignore case sensitivity when you perform a query parameter match. | |
References
For more information, see Use ASMGlobalRateLimiter to configure global throttling for ingress gateways and inbound traffic to services.