How to apply rate limiting using CRDs
This page explains how to apply rate limiting to APIs using CRDs.
Before you begin¶
Before getting started, make sure to read our API rate limiting overview docs to learn about rate limiting with Traefik Hub.
Custom Resource Definitions¶
Examples
The following examples showcase two CRDs using different rate limiting strategies.
apiVersion: hub.traefik.io/v1alpha1
kind: APIRateLimit
metadata:
name: my-rate-limit
spec:
# Rate limit configuration, this config allows 100 requests/minute.
limit: 100 # 100 requests
period: 1m # One minute
groups:
- support
apiSelector:
matchLabels:
module: crm
apiVersion: hub.traefik.io/v1alpha1
kind: APIRateLimit
metadata:
name: my-rate-limit
spec:
# Rate limit configuration, this config allows 100 requests/minute.
limit: 100 # 100 requests
period: 1m # One minute
strategy: distributed
groups:
- support
apiSelector:
matchLabels:
module: crm
You must configure either anyGroups
or groups
for rate limiting, please check the APIRateLimit CRD for more information.
Without setting one of them, rate limiting will not be applied.
In Traefik Hub groups are used to configure permissions.
What's next¶
- Check out the CRD reference about rate limiting.
- Learn how to configure and enable distributed rate limiting in Traefik Hub.