{"id":1763,"date":"2023-11-13T04:24:48","date_gmt":"2023-11-13T04:24:48","guid":{"rendered":"https:\/\/imesh.ai\/blog\/?p=1763"},"modified":"2024-01-12T06:09:53","modified_gmt":"2024-01-12T06:09:53","slug":"istio-rate-limiting-global","status":"publish","type":"post","link":"https:\/\/imesh.ai\/blog\/istio-rate-limiting-global\/","title":{"rendered":"How to Configure Istio Global Rate Limiting"},"content":{"rendered":"\n<p>In my last blog, we explored rate limiting, the types of Istio rate limiting, and I showed you how to set up an Istio local rate limiter per pod\/proxy and ingress gateway level.<\/p>\n\n\n\n<p>(I highly recommend you go through the blog if you are new to Istio rate limiting: <a href=\"https:\/\/imesh.ai\/blog\/istio-rate-limiting-local\/\">How to Configure Istio Local Rate Limiting<\/a>.)<\/p>\n\n\n\n<p>Here, we will see the other type of Istio rate limiting, i.e., Istio global rate limiting. I will explain what it is and how it works, and will show you how to configure Istio global rate limiting per client IP basis.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Istio global rate limiting<\/h2>\n\n\n\n<p>Rate limiting applied on an application or service in the Istio mesh, where the application\/Envoy proxy makes gRPC calls to a global rate limit service for request quota, is called Istio global rate limiting.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"960\" height=\"540\" src=\"https:\/\/imesh.ai\/blog\/wp-content\/uploads\/2023\/11\/Istio-global-rate-limiting-diagram.png\" alt=\"Istio global rate limiting workflow\" class=\"wp-image-1764\" srcset=\"https:\/\/imesh.ai\/blog\/wp-content\/uploads\/2023\/11\/Istio-global-rate-limiting-diagram.png 960w, https:\/\/imesh.ai\/blog\/wp-content\/uploads\/2023\/11\/Istio-global-rate-limiting-diagram-300x169.png 300w, https:\/\/imesh.ai\/blog\/wp-content\/uploads\/2023\/11\/Istio-global-rate-limiting-diagram-768x432.png 768w, https:\/\/imesh.ai\/blog\/wp-content\/uploads\/2023\/11\/Istio-global-rate-limiting-diagram-400x225.png 400w, https:\/\/imesh.ai\/blog\/wp-content\/uploads\/2023\/11\/Istio-global-rate-limiting-diagram-800x450.png 800w\" sizes=\"(max-width: 960px) 100vw, 960px\" \/><\/figure>\n<\/div>\n\n\n<p class=\"has-text-align-center\"><em>Istio global rate limiting workflow diagram<\/em><\/p>\n\n\n\n<p>Here is how Istio global rate limiting works:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>The client makes a request to the Istio ingress gateway or a service in Istio mesh.<br><\/li>\n\n\n\n<li>Envoy sidecar proxy of the service intercepts the request and makes a gRPC call to a Global rate limiter service to decide whether to rate limit the request.<br><\/li>\n\n\n\n<li>Global rate limiter service interacts with its Redis database, where the actual quota state and request counters are cached, and then takes the rate-limiting decision for the request.<br><\/li>\n\n\n\n<li>Global rate limiter service returns the decision to the sidecar Envoy proxy.<br><\/li>\n\n\n\n<li>Based on the decision, the proxy triggers the rate limiter and the service returns an HTTP 429 error code to the client, or it is not triggered and the service accepts the request and shows HTTP 200.<\/li>\n<\/ol>\n\n\n\n<p><strong>Istio global rate limiting helps DevOps and architects set rate limiting per IP or dynamic header values. They can apply a rate limiter at the service\/application level \u2014 instead of a service instance\/proxy level \u2014 using Istio global rate limiting.<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The difference in token bucket allocation between Istio global rate limiting and local rate limiting at the service level<\/h3>\n\n\n\n<p>Note that you can also set a rate limiter at the service level by configuring the appropriate <em>workloadSelector<\/em> in Istio local rate limiting. However, the token bucket quota will not be shared among the replica pods\/Envoy proxies, and each proxy will have its own token bucket.<\/p>\n\n\n\n<p>That is, if there is a service with 3 replicas and you set the rate limiter to 5 for the service, each pod will get a token bucket with a maximum of 5 tokens. It will accumulate to a maximum of 15 requests after which the rate limiter will be triggered.<\/p>\n\n\n\n<p>In global rate limiting the token bucket quota is shared, i.e. the service will only accept 5 requests in total, regardless of the number of replicas it has.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Steps to configure Istio global rate limiter<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"#configmap\">Step #1: Apply <em>ConfigMap <\/em>for the rate limit service<\/a><\/li>\n\n\n\n<li><a href=\"#ratelimit\">Step #2: Deploy rate limit service and Redis<\/a><\/li>\n\n\n\n<li><a href=\"#envoyfilter\">Step #3: Apply <em>EnvoyFilter<\/em> CRD<\/a><\/li>\n<\/ul>\n\n\n\n<p>Let us see the steps in action.<\/p>\n\n\n\n<h3 class=\"wp-block-heading configmap\" id=\"configmap\">Step #1: Apply <em>ConfigMap <\/em>for the rate limit service<\/h3>\n\n\n\n<p>In the local rate limiting, we configured the token bucket in the Envoy proxy\/pod itself. The proxy then rate-limited requests based on the configuration.<\/p>\n\n\n\n<p>Global rate limiting requires some extra components, including a <em>ConfigMap <\/em>for the global rate limit service.<\/p>\n\n\n\n<p>DevOps and architects can define the request quota for the service that needs rate limiting in the <em>ConfigMap <\/em>resource<em> <\/em>(sample <a href=\"https:\/\/github.com\/imesh-ai\/webinar\/blob\/main\/Rate%20Limiting%20With%20EnvoyFilter\/global\/cm-ratelimit.yaml\"><em>ConfigMap <\/em>YAML<\/a> below).<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code>apiVersion: v1\nkind: ConfigMap\nmetadata:\n&nbsp; name: ratelimit-config\n&nbsp; namespace: istio-system\ndata:\n&nbsp; config.yaml: |\n&nbsp; &nbsp; domain: productpage-ratelimit\n&nbsp; &nbsp; descriptors:\n&nbsp; - key: ratelimitheader\n&nbsp; &nbsp; &nbsp; descriptors:\n&nbsp; &nbsp; &nbsp; - key: PATH\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value: \"\/get\"\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rate_limit:\n&nbsp; &nbsp; &nbsp; &nbsp; unit: minute\n&nbsp; &nbsp; &nbsp; &nbsp; requests_per_unit: 5<\/code><\/pre>\n\n\n\n<p>(You can see that the <em>domain <\/em>value here is set to <em>productpage-ratelimit<\/em>. The value should be the same in the <em>EnvoyFilter <\/em>CRD, which you will see in step #3, for the rate limiter to work.)<\/p>\n\n\n\n<p>The way the reference implementation of the <em>ConfigMap<\/em> (i.e., the global rate limiting service) works is that each list of <a href=\"https:\/\/www.envoyproxy.io\/docs\/envoy\/latest\/configuration\/http\/http_filters\/local_rate_limit_filter#using-rate-limit-descriptors-for-local-rate-limiting\">descriptors<\/a> on the same level is treated as an OR operation, while the nested descriptors are ANDed together.<\/p>\n\n\n\n<p>The above configuration has nested descriptors. A request will be checked for any header value (since I haven\u2019t given a specific header value) and for the path <em>\/get<\/em>. Only the requests that satisfy both conditions will be rate-limited by 5 requests per minute.<\/p>\n\n\n\n<p>A key thing to note here is that the order and the number of the descriptors should be the same as defined for <a href=\"https:\/\/www.envoyproxy.io\/docs\/envoy\/latest\/configuration\/http\/http_filters\/local_rate_limit_filter#using-rate-limit-descriptors-for-local-rate-limiting\">rate limit actions<\/a> in the <em>EnvoyFilter <\/em>resource.<\/p>\n\n\n\n<p>Once you apply the <em>ConfigMap <\/em>YAML, you can proceed to step #2.<\/p>\n\n\n\n<h3 class=\"wp-block-heading ratelimit\" id=\"ratelimit\">Step #2: Deploy rate limit service and Redis<\/h3>\n\n\n\n<p>Istio provides a Redis-based, sample rate limit service to set up global rate limiting. The Redis database stores the request quota and caches the request count from the rate limit service.<\/p>\n\n\n\n<p><strong>So there are 2 deployments to apply: rate limit service and Redis.<\/strong> See their configurations <a href=\"https:\/\/github.com\/istio\/istio\/blob\/master\/samples\/ratelimit\/rate-limit-service.yaml\">here<\/a>.<\/p>\n\n\n\n<p>Note:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The <em>ConfigMap <\/em>applied in step #1 should be in the same namespace as the rate limit service. It is mounted by the deployment during <em>init<\/em>.<br><\/li>\n\n\n\n<li>Every time you change anything on <em>ConfigMap<\/em>, restart the rate limit service<strong> <\/strong>using the following command to take effect:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code>kubectl rollout restart deploy &#091;rate_limit_service_name] -n &#091;namespace]&nbsp;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading envoyfilter\" id=\"envoyfilter\">Step #3: Apply EnvoyFilter CRD<\/h3>\n\n\n\n<p>I have already explained most of the fields on an <em>EnvoyFilter <\/em>resource in the <a href=\"https:\/\/imesh.ai\/blog\/istio-rate-limiting-local\/\">Istio local rate limiting blog<\/a>. Please have a look at it if you haven\u2019t already.<\/p>\n\n\n\n<p>There are 2 <em>EnvoyFilters <\/em>in the <a href=\"https:\/\/github.com\/imesh-ai\/webinar\/blob\/main\/Rate%20Limiting%20With%20EnvoyFilter\/global\/httpbin-global-ratelimit.yaml\">sample <em>EnvoyFilter CRD here<\/em><\/a>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>The first <em>EnvoyFilter<\/em> sets the rate limit service\u2019s location for the <em>httpbin<\/em>.<\/strong> It is defined under the <em>rate_limi_service <\/em>field as <em>cluster_name: outbound|8081||ratelimit.istio-system.svc.cluster.local<\/em>.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code>...\ndomain: productpage-ratelimit\nfailure_mode_deny: true\ntimeout: 10s\nrate_limit_service:\n&nbsp; grpc_service:\n&nbsp; &nbsp; envoy_grpc:\n&nbsp; &nbsp; &nbsp; cluster_name: outbound|8081||ratelimit.istio-system.svc.cluster.local\n&nbsp; &nbsp; &nbsp; authority: ratelimit.istio-system.svc.cluster.local\n&nbsp; transport_api_version: V3\n...<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>The second <\/strong><strong><em>EnvoyFilter<\/em><\/strong><strong> defines the rate-limiting actions for <\/strong><strong><em>httpbin<\/em><\/strong><strong>.<\/strong> I have defined descriptor keys for request headers \u2014 one for the <a href=\"https:\/\/www.envoyproxy.io\/docs\/envoy\/latest\/configuration\/http\/http_conn_man\/headers#path\">pseudo-header path<\/a> and the other one to enable the rate limiter (<em>x-rate-limit-please<\/em>).<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code>...\npatch:\n&nbsp; operation: MERGE\n&nbsp; # Applies the rate limit rules.\n&nbsp; value:\n&nbsp; &nbsp; rate_limits:\n&nbsp; &nbsp; &nbsp; - actions: # any actions in here\n&nbsp; &nbsp; &nbsp; &nbsp; - request_headers:\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; header_name: \"x-rate-limit-please\"\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; descriptor_key: \"ratelimitheader\"\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; skip_if_absent: true\n&nbsp; &nbsp; &nbsp; &nbsp; - request_headers:\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; header_name: \":path\"\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; descriptor_key: \"PATH\"\n...<\/code><\/pre>\n\n\n\n<p>The Istio global rate limiter should work after you apply the <em>EnvoyFilter<\/em> CRD. You can test the configuration using <em>curl<\/em>:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code>curl -v &lt;url&gt;\/get -H \"x-rate-limit-please: true\"<\/code><\/pre>\n\n\n<!-- Ad space powered by WP AdCenter v2.5.7 - https:\/\/wpadcenter.com\/ --><div class=\"wpadcenter-ad-container\" ><div id=\"wpadcenter-ad-1841\" class=\"ad-970x250 wpadcenter-970x250 ad-placement  wpadcenter-alignnone alignnone\"><div class=\"wpadcenter-ad-inner\" ><a id=\"wpadcenter_ad\" data-value=1841 data-placement=\"\" href=\"https:\/\/imesh.ai\/istio-service-mesh-case-studies.html?utm_source=Click&utm_medium=banner-ebook&utm_campaign=Istio+Rate+limiting+global&utm_id=read-case-study&utm_term=download+ebook\" target=\"_self\" class=\"wpadcenter-ad-inner__item\" ><img decoding=\"async\" width=\"970\" height=\"250\" src=\"https:\/\/imesh.ai\/blog\/wp-content\/uploads\/2024\/01\/Mindtickle-case-study-1.png\" class=\"attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"Mindtickle case study\" srcset=\"https:\/\/imesh.ai\/blog\/wp-content\/uploads\/2024\/01\/Mindtickle-case-study-1.png 970w, https:\/\/imesh.ai\/blog\/wp-content\/uploads\/2024\/01\/Mindtickle-case-study-1-300x77.png 300w, https:\/\/imesh.ai\/blog\/wp-content\/uploads\/2024\/01\/Mindtickle-case-study-1-768x198.png 768w, https:\/\/imesh.ai\/blog\/wp-content\/uploads\/2024\/01\/Mindtickle-case-study-1-400x103.png 400w, https:\/\/imesh.ai\/blog\/wp-content\/uploads\/2024\/01\/Mindtickle-case-study-1-800x206.png 800w\" sizes=\"(max-width: 970px) 100vw, 970px\" \/><\/a><\/div><\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Istio rate limiting per IP<\/h2>\n\n\n\n<p>One of the crucial use cases of Istio global rate limiting is that it helps DevOps and architects set rate limiting per client IP. <strong>The global rate limiter is more suitable for IP address-based rate limiting since it supports dynamic rate limits, unlike the local rate limiting filter.<\/strong><\/p>\n\n\n\n<p>Dynamic rate limits mean that the global rate limiter will first check for specific values in the descriptor and give a token bucket accordingly \u2014 but if no values are defined then every value for that descriptor is given a separate token bucket.<\/p>\n\n\n\n<p>So if you add a descriptor entry for IP address without mentioning a specific remote address, requests from each IP will receive a token bucket. The requests from the IPs will be rate-limited once they exhaust their individual request quota (see the example below).<\/p>\n\n\n\n<p>With the local rate limiter, you cannot configure dynamic rate limits. You have to specify a value for every descriptor, which means you will end up having one entry per IP address.<\/p>\n\n\n\n<p>For example, you will have to configure a descriptor entry for the remote address 10.0.0.1, another one for 10.0.0.2, and so on. Requests from IPs not specified in the descriptor will not be rate-limited.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example for IP-based Istio global rate limiting at ingress<\/h3>\n\n\n\n<p>Let us see a sample Istio global rate limiting at ingress based on the client\u2019s remote address.<\/p>\n\n\n\n<p>The configuration is similar to how we set it up for the local rate limiter for the Ingress gateway in the <a href=\"https:\/\/imesh.ai\/blog\/istio-rate-limiting-local\/\">previous blog<\/a> (scroll down towards the end to see it). We changed the <em>workloadSelector <\/em>and <em>context <\/em>to<em> istio: ingressgateway <\/em>and <em>GATEWAY<\/em>, respectively.<\/p>\n\n\n\n<p>The change when configuring global rate limiting per IP is that you have to define an additional <em>remote_address <\/em>action in the <em>EnvoyFilter <\/em>CRD, where rate limiting actions for the service can be defined:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code>...\npatch:\n&nbsp; operation: MERGE\n&nbsp; # Applies the rate limit rules.\n&nbsp; value:\n&nbsp; &nbsp; rate_limits:\n&nbsp; &nbsp; &nbsp; - actions: # any actions in here\n&nbsp; &nbsp; &nbsp; &nbsp; - remote_address: {}\n&nbsp; &nbsp; &nbsp; &nbsp; - request_headers:\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; header_name: \":path\"\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; descriptor_key: \"PATH\"\n...<\/code><\/pre>\n\n\n\n<p>After that, you can configure the global rate limiter service to use a dedicated token bucket for each value of the remote address by <em>not specifying<\/em> any address at all.<\/p>\n\n\n\n<p>Since the configuration for the rate limiter service is configured in the <em>ConfigMap<\/em>, you can make that change under the <em>descriptors <\/em>field in the <em>ConfigMap<\/em> resource:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code>apiVersion: v1\nkind: ConfigMap\nmetadata:\n&nbsp; name: ratelimit-config\n&nbsp; namespace: istio-system\ndata:\n&nbsp; config.yaml: |\n&nbsp; &nbsp; domain: productpage-ratelimit\n&nbsp; &nbsp; descriptors:\n&nbsp; - key: remote_address\n&nbsp; &nbsp; &nbsp; descriptors:\n&nbsp; &nbsp; &nbsp; - key: PATH\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value: \"\/get\"\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rate_limit:\n&nbsp; &nbsp; &nbsp; &nbsp; unit: minute\n&nbsp; &nbsp; &nbsp; &nbsp; requests_per_unit: 5<\/code><\/pre>\n\n\n\n<p>Once you successfully configure and apply this, you can see that requests through the ingress gateway show up in the rate limit service log in the following format:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code>\"got descriptor: (remote_address=10.224.0.10),(PATH=\/get)<\/code><\/pre>\n\n\n\n<p>The key thing to note here is that we got the remote address, but it belongs to a node in the cluster, not the client.<\/p>\n\n\n\n<p>To get around this, we need to configure the load balancer or gateway service to preserve the client IP as mentioned in the <a href=\"https:\/\/istio.io\/latest\/docs\/tasks\/security\/authorization\/authz-ingress\/#source-ip-address-of-the-original-client\">Istio docs for the Istio ingress gateway<\/a>.<\/p>\n\n\n\n<p>You can use the following command and update the ingress gateway to set <em>externalTrafficPolicy: Local<\/em> to preserve the original client source IP on the ingress gateway:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code>kubectl patch svc istio-ingressgateway -n istio-system -p '{\"spec\":{\"externalTrafficPolicy\":\"Local\"}}'<\/code><\/pre>\n\n\n\n<p>A similar configuration can be done to rate limit per client IP if you are using Nginx ingress.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Advanced configurations with Istio global rate limiting<\/h2>\n\n\n\n<p>Setting dynamic values using Istio global rate limiting allows DevOps and architects to set up advanced rate-limiting configurations.<\/p>\n\n\n\n<p>For example, you can use a <a href=\"https:\/\/www.envoyproxy.io\/docs\/envoy\/latest\/configuration\/http\/http_filters\/header_to_metadata_filter\">header-to-metadata filter<\/a> in the <em>EnvoyFilter <\/em>resource and use regular expressions to get only the URL path that you need, without any query parameters:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code>...\npatch:\n&nbsp; operation: INSERT_BEFORE\n&nbsp; value:\n&nbsp; &nbsp; name: envoy.filters.http.header_to_metadata\n&nbsp; &nbsp; typed_config:\n&nbsp; &nbsp; &nbsp; \"@type\": type.googleapis.com\/envoy.extensions.filters.http.header_to_metadata.v3.Config\n&nbsp; &nbsp; &nbsp; request_rules:\n&nbsp; &nbsp; &nbsp; - header: \":path\"\n&nbsp; &nbsp; &nbsp; &nbsp; on_header_present:\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; metadata_namespace: ratelimiter\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; key: url\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; regex_value_rewrite:\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pattern:\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; google_re2: {}\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; regex: '^(\\\/&#091;\\\/\\d\\w-]+)(\\?)?.*'\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; substitution: '\\1'\n...<\/code><\/pre>\n\n\n\n<p>The above regular expression substitution gets only the URL path without any query parameters and creates metadata in the request under the key <em>url<\/em>, in the <em>ratelimiter<\/em> namespace.<\/p>\n\n\n\n<p>You can then match the inbound request on the desired port (I have used port 8000) by using the <em>url <\/em>metadata key in the <em>VIRTUAL_HOST <\/em>configuration:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background\"><code>...\n- applyTo: VIRTUAL_HOST\n&nbsp; match:\n&nbsp; &nbsp; context: SIDECAR_INBOUND\n&nbsp; &nbsp; routeConfiguration:\n&nbsp; &nbsp; &nbsp; vhost:\n&nbsp; &nbsp; &nbsp; &nbsp; name: \"inbound|http|8000\"\n&nbsp; patch:\n&nbsp; &nbsp; operation: MERGE\n&nbsp; &nbsp; value:\n&nbsp; &nbsp; &nbsp; rate_limits:\n&nbsp; &nbsp; &nbsp; - actions:\n&nbsp; &nbsp; &nbsp; &nbsp; - metadata:\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; descriptor_key: url\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; metadata_key:\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; key: ratelimiter\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; path:\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; - key: url\n...<\/code><\/pre>\n\n\n\n<p>The above configuration practically cleans up the URL by removing unnecessary query parameters from the request path, taking just the <em>url <\/em>value.<\/p>\n\n\n\n<p>Alternatively, you can use the header-to-metadata filter to pull any specific query parameter or cookies (user ID, for example) from the request path using regex and set a rate limiter based on that.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Istio global or local rate limiting: which one to use?<\/h2>\n\n\n\n<p>DevOps and architects may consider the following pointers while trying to decide which type of Istio rate limiting they want to implement:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If your goal is to reduce the load per pod\/Envoy proxy, then Istio local rate limiting is the way to go. It helps to set up the rate limiter per pod.<br><\/li>\n\n\n\n<li>Local rate limiter is also cheaper and more reliable since rate limiting happens at the proxy level without needing any extra components, such as a rate limiter service used in the global one.<br><\/li>\n\n\n\n<li>If your goal is to set up Istio rate limiting based on client IP, then choose global rate limiting. As of now, the local rate limiter filter cannot be used for rate limiting per IP address.<br><\/li>\n\n\n\n<li>Istio global rate limiting is also the obvious and easier choice to set up path or header-based rate limiters. You can match the path or header based on regex on the global one. For example, you can configure a path match on <em>\/api\/*<\/em>, and then each endpoint under <em>\/api<\/em> will have its own token bucket. Local rate limiter limits only to exact paths and headers.<br><\/li>\n\n\n\n<li>You can also configure local rate limiting in conjunction with the global one to reduce the load on a particular pod, for example. Whichever shows up first in the Envoy proxy configuration will get applied first and take effect.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Leverage Istio rate limiting to protect crucial services<\/h2>\n\n\n\n<p>If you are a DevOps engineer or architect using Istio, it is a given to protect services \u2014 such as login and payment \u2014 against DoS and brute force attacks using Istio rate limiting. It will also help you prevent service overload and maintain an available infrastructure all the time.<\/p>\n\n\n\n<p>At IMESH, we offer <a href=\"https:\/\/imesh.ai\/managed-istio.html\">managed Istio<\/a> and support DevOps and architects with setting Istio rate limiting for services, and our Istio experts help remove the operational complexities associated with managing Istio at scale in production.<\/p>\n\n\n\n<p>Feel free to check out our offering and pricing here: <a href=\"https:\/\/imesh.ai\/managed-istio.html\">https:\/\/imesh.ai\/managed-istio.html<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In my last blog, we explored rate limiting, the types of Istio<span class=\"excerpt-more\"><\/span><\/p>\n","protected":false},"author":10,"featured_media":1767,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32,38,118],"tags":[53,84,119],"class_list":["post-1763","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-istio-service-mesh","category-network","category-rate-limiting","tag-istio","tag-network","tag-rate-limiting"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Configure Istio Global Rate Limiting<\/title>\n<meta name=\"description\" content=\"Learn what Istio global rate limiting is and how to configure it. See how to set up Istio rate limiting per IP or client remote address.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/imesh.ai\/blog\/istio-rate-limiting-global\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Configure Istio Global Rate Limiting\" \/>\n<meta property=\"og:description\" content=\"Learn what Istio global rate limiting is and how to configure it. See how to set up Istio rate limiting per IP or client remote address.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/imesh.ai\/blog\/istio-rate-limiting-global\/\" \/>\n<meta property=\"og:site_name\" content=\"IMESH\" \/>\n<meta property=\"article:published_time\" content=\"2023-11-13T04:24:48+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-12T06:09:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/imesh.ai\/blog\/wp-content\/uploads\/2023\/11\/How-to-Configure-Istio-Global-Rate-Limiting.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t<meta property=\"og:image:height\" content=\"720\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Pulak Das\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Pulak Das\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/imesh.ai\/blog\/istio-rate-limiting-global\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/imesh.ai\/blog\/istio-rate-limiting-global\/\"},\"author\":{\"name\":\"Pulak Das\",\"@id\":\"https:\/\/imesh.ai\/blog\/#\/schema\/person\/13792df637b7c676b353e85f12d3f6c1\"},\"headline\":\"How to Configure Istio Global Rate Limiting\",\"datePublished\":\"2023-11-13T04:24:48+00:00\",\"dateModified\":\"2024-01-12T06:09:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/imesh.ai\/blog\/istio-rate-limiting-global\/\"},\"wordCount\":1946,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/imesh.ai\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/imesh.ai\/blog\/istio-rate-limiting-global\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/imesh.ai\/blog\/wp-content\/uploads\/2023\/11\/How-to-Configure-Istio-Global-Rate-Limiting.png\",\"keywords\":[\"istio\",\"network\",\"rate limiting\"],\"articleSection\":[\"Istio service mesh\",\"Network\",\"Rate Limiting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/imesh.ai\/blog\/istio-rate-limiting-global\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/imesh.ai\/blog\/istio-rate-limiting-global\/\",\"url\":\"https:\/\/imesh.ai\/blog\/istio-rate-limiting-global\/\",\"name\":\"How to Configure Istio Global Rate Limiting\",\"isPartOf\":{\"@id\":\"https:\/\/imesh.ai\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/imesh.ai\/blog\/istio-rate-limiting-global\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/imesh.ai\/blog\/istio-rate-limiting-global\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/imesh.ai\/blog\/wp-content\/uploads\/2023\/11\/How-to-Configure-Istio-Global-Rate-Limiting.png\",\"datePublished\":\"2023-11-13T04:24:48+00:00\",\"dateModified\":\"2024-01-12T06:09:53+00:00\",\"description\":\"Learn what Istio global rate limiting is and how to configure it. See how to set up Istio rate limiting per IP or client remote address.\",\"breadcrumb\":{\"@id\":\"https:\/\/imesh.ai\/blog\/istio-rate-limiting-global\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/imesh.ai\/blog\/istio-rate-limiting-global\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/imesh.ai\/blog\/istio-rate-limiting-global\/#primaryimage\",\"url\":\"https:\/\/imesh.ai\/blog\/wp-content\/uploads\/2023\/11\/How-to-Configure-Istio-Global-Rate-Limiting.png\",\"contentUrl\":\"https:\/\/imesh.ai\/blog\/wp-content\/uploads\/2023\/11\/How-to-Configure-Istio-Global-Rate-Limiting.png\",\"width\":1280,\"height\":720,\"caption\":\"How to Configure Istio Global Rate Limiting\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/imesh.ai\/blog\/istio-rate-limiting-global\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/imesh.ai\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Configure Istio Global Rate Limiting\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/imesh.ai\/blog\/#website\",\"url\":\"https:\/\/imesh.ai\/blog\/\",\"name\":\"IMESH Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/imesh.ai\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/imesh.ai\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/imesh.ai\/blog\/#organization\",\"name\":\"IMESH\",\"url\":\"https:\/\/imesh.ai\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/imesh.ai\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/imesh.ai\/blog\/wp-content\/uploads\/2023\/03\/IMESH-LOGO-scaled.jpg\",\"contentUrl\":\"https:\/\/imesh.ai\/blog\/wp-content\/uploads\/2023\/03\/IMESH-LOGO-scaled.jpg\",\"width\":2560,\"height\":1665,\"caption\":\"IMESH\"},\"image\":{\"@id\":\"https:\/\/imesh.ai\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.linkedin.com\/company\/imeshai\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/imesh.ai\/blog\/#\/schema\/person\/13792df637b7c676b353e85f12d3f6c1\",\"name\":\"Pulak Das\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/imesh.ai\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/imesh.ai\/blog\/wp-content\/uploads\/2023\/03\/IMG_20230222_170121-150x150.jpg\",\"contentUrl\":\"https:\/\/imesh.ai\/blog\/wp-content\/uploads\/2023\/03\/IMG_20230222_170121-150x150.jpg\",\"caption\":\"Pulak Das\"},\"description\":\"Pulak is the Istio and Envoy expert in IMESH. He is a front-end developer passionate about open-source software, design, and typography. His scientific interests as a computer science graduate are at the systems level: operating systems and programming languages.\",\"sameAs\":[\"https:\/\/imesh.ai\"],\"url\":\"https:\/\/imesh.ai\/blog\/author\/pulak-dasimesh-ai\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Configure Istio Global Rate Limiting","description":"Learn what Istio global rate limiting is and how to configure it. See how to set up Istio rate limiting per IP or client remote address.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/imesh.ai\/blog\/istio-rate-limiting-global\/","og_locale":"en_US","og_type":"article","og_title":"How to Configure Istio Global Rate Limiting","og_description":"Learn what Istio global rate limiting is and how to configure it. See how to set up Istio rate limiting per IP or client remote address.","og_url":"https:\/\/imesh.ai\/blog\/istio-rate-limiting-global\/","og_site_name":"IMESH","article_published_time":"2023-11-13T04:24:48+00:00","article_modified_time":"2024-01-12T06:09:53+00:00","og_image":[{"width":1280,"height":720,"url":"https:\/\/imesh.ai\/blog\/wp-content\/uploads\/2023\/11\/How-to-Configure-Istio-Global-Rate-Limiting.png","type":"image\/png"}],"author":"Pulak Das","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Pulak Das","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/imesh.ai\/blog\/istio-rate-limiting-global\/#article","isPartOf":{"@id":"https:\/\/imesh.ai\/blog\/istio-rate-limiting-global\/"},"author":{"name":"Pulak Das","@id":"https:\/\/imesh.ai\/blog\/#\/schema\/person\/13792df637b7c676b353e85f12d3f6c1"},"headline":"How to Configure Istio Global Rate Limiting","datePublished":"2023-11-13T04:24:48+00:00","dateModified":"2024-01-12T06:09:53+00:00","mainEntityOfPage":{"@id":"https:\/\/imesh.ai\/blog\/istio-rate-limiting-global\/"},"wordCount":1946,"commentCount":0,"publisher":{"@id":"https:\/\/imesh.ai\/blog\/#organization"},"image":{"@id":"https:\/\/imesh.ai\/blog\/istio-rate-limiting-global\/#primaryimage"},"thumbnailUrl":"https:\/\/imesh.ai\/blog\/wp-content\/uploads\/2023\/11\/How-to-Configure-Istio-Global-Rate-Limiting.png","keywords":["istio","network","rate limiting"],"articleSection":["Istio service mesh","Network","Rate Limiting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/imesh.ai\/blog\/istio-rate-limiting-global\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/imesh.ai\/blog\/istio-rate-limiting-global\/","url":"https:\/\/imesh.ai\/blog\/istio-rate-limiting-global\/","name":"How to Configure Istio Global Rate Limiting","isPartOf":{"@id":"https:\/\/imesh.ai\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/imesh.ai\/blog\/istio-rate-limiting-global\/#primaryimage"},"image":{"@id":"https:\/\/imesh.ai\/blog\/istio-rate-limiting-global\/#primaryimage"},"thumbnailUrl":"https:\/\/imesh.ai\/blog\/wp-content\/uploads\/2023\/11\/How-to-Configure-Istio-Global-Rate-Limiting.png","datePublished":"2023-11-13T04:24:48+00:00","dateModified":"2024-01-12T06:09:53+00:00","description":"Learn what Istio global rate limiting is and how to configure it. See how to set up Istio rate limiting per IP or client remote address.","breadcrumb":{"@id":"https:\/\/imesh.ai\/blog\/istio-rate-limiting-global\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/imesh.ai\/blog\/istio-rate-limiting-global\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/imesh.ai\/blog\/istio-rate-limiting-global\/#primaryimage","url":"https:\/\/imesh.ai\/blog\/wp-content\/uploads\/2023\/11\/How-to-Configure-Istio-Global-Rate-Limiting.png","contentUrl":"https:\/\/imesh.ai\/blog\/wp-content\/uploads\/2023\/11\/How-to-Configure-Istio-Global-Rate-Limiting.png","width":1280,"height":720,"caption":"How to Configure Istio Global Rate Limiting"},{"@type":"BreadcrumbList","@id":"https:\/\/imesh.ai\/blog\/istio-rate-limiting-global\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/imesh.ai\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Configure Istio Global Rate Limiting"}]},{"@type":"WebSite","@id":"https:\/\/imesh.ai\/blog\/#website","url":"https:\/\/imesh.ai\/blog\/","name":"IMESH Blog","description":"","publisher":{"@id":"https:\/\/imesh.ai\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/imesh.ai\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/imesh.ai\/blog\/#organization","name":"IMESH","url":"https:\/\/imesh.ai\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/imesh.ai\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/imesh.ai\/blog\/wp-content\/uploads\/2023\/03\/IMESH-LOGO-scaled.jpg","contentUrl":"https:\/\/imesh.ai\/blog\/wp-content\/uploads\/2023\/03\/IMESH-LOGO-scaled.jpg","width":2560,"height":1665,"caption":"IMESH"},"image":{"@id":"https:\/\/imesh.ai\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.linkedin.com\/company\/imeshai"]},{"@type":"Person","@id":"https:\/\/imesh.ai\/blog\/#\/schema\/person\/13792df637b7c676b353e85f12d3f6c1","name":"Pulak Das","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/imesh.ai\/blog\/#\/schema\/person\/image\/","url":"https:\/\/imesh.ai\/blog\/wp-content\/uploads\/2023\/03\/IMG_20230222_170121-150x150.jpg","contentUrl":"https:\/\/imesh.ai\/blog\/wp-content\/uploads\/2023\/03\/IMG_20230222_170121-150x150.jpg","caption":"Pulak Das"},"description":"Pulak is the Istio and Envoy expert in IMESH. He is a front-end developer passionate about open-source software, design, and typography. His scientific interests as a computer science graduate are at the systems level: operating systems and programming languages.","sameAs":["https:\/\/imesh.ai"],"url":"https:\/\/imesh.ai\/blog\/author\/pulak-dasimesh-ai\/"}]}},"jetpack_featured_media_url":"https:\/\/imesh.ai\/blog\/wp-content\/uploads\/2023\/11\/How-to-Configure-Istio-Global-Rate-Limiting.png","_links":{"self":[{"href":"https:\/\/imesh.ai\/blog\/wp-json\/wp\/v2\/posts\/1763","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/imesh.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/imesh.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/imesh.ai\/blog\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/imesh.ai\/blog\/wp-json\/wp\/v2\/comments?post=1763"}],"version-history":[{"count":4,"href":"https:\/\/imesh.ai\/blog\/wp-json\/wp\/v2\/posts\/1763\/revisions"}],"predecessor-version":[{"id":1854,"href":"https:\/\/imesh.ai\/blog\/wp-json\/wp\/v2\/posts\/1763\/revisions\/1854"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/imesh.ai\/blog\/wp-json\/wp\/v2\/media\/1767"}],"wp:attachment":[{"href":"https:\/\/imesh.ai\/blog\/wp-json\/wp\/v2\/media?parent=1763"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/imesh.ai\/blog\/wp-json\/wp\/v2\/categories?post=1763"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/imesh.ai\/blog\/wp-json\/wp\/v2\/tags?post=1763"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}