Sliding window 5 requests per minutev3.9+
Configure the plugin to set a rate limit of 5 requests per minute.
Add this section to your declarative configuration file:
_format_version: "3.0"
plugins:
- name: service-protection
config:
window_size:
- 60
window_type: sliding
limit:
- 5
namespace: example_namespace
Make the following request:
curl -i -X POST http://localhost:8001/plugins/ \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data '
{
"name": "service-protection",
"config": {
"window_size": [
60
],
"window_type": "sliding",
"limit": [
5
],
"namespace": "example_namespace"
}
}
'
Make the following request:
curl -X POST https://{region}.api.konghq.com/v2/control-planes/{controlPlaneId}/core-entities/plugins/ \
--header "accept: application/json" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $KONNECT_TOKEN" \
--data '
{
"name": "service-protection",
"config": {
"window_size": [
60
],
"window_type": "sliding",
"limit": [
5
],
"namespace": "example_namespace"
}
}
'
Make sure to replace the following placeholders with your own values:
-
region
: Geographic region where your Kong Konnect is hosted and operates. -
controlPlaneId
: Theid
of the control plane. -
KONNECT_TOKEN
: Your Personal Access Token (PAT) associated with your Konnect account.
See the Konnect API reference to learn about region-specific URLs and personal access tokens.
echo "
apiVersion: configuration.konghq.com/v1
kind: KongClusterPlugin
metadata:
name: service-protection
namespace: kong
annotations:
kubernetes.io/ingress.class: kong
labels:
global: 'true'
config:
window_size:
- 60
window_type: sliding
limit:
- 5
namespace: example_namespace
plugin: service-protection
" | kubectl apply -f -
Prerequisite: Configure your Personal Access Token
terraform {
required_providers {
konnect = {
source = "kong/konnect"
}
}
}
provider "konnect" {
personal_access_token = "$KONNECT_TOKEN"
server_url = "https://us.api.konghq.com/"
}
Add the following to your Terraform configuration to create a Konnect Gateway Plugin:
resource "konnect_gateway_plugin_service_protection" "my_service_protection" {
enabled = true
config = {
window_size = [60]
window_type = "sliding"
limit = [5]
namespace = "example_namespace"
}
control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
}
Add this section to your declarative configuration file:
_format_version: "3.0"
plugins:
- name: service-protection
service: serviceName|Id
config:
window_size:
- 60
window_type: sliding
limit:
- 5
namespace: example_namespace
Make sure to replace the following placeholders with your own values:
-
serviceName|Id
: Theid
orname
of the service the plugin configuration will target.
Make the following request:
curl -i -X POST http://localhost:8001/services/{serviceName|Id}/plugins/ \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data '
{
"name": "service-protection",
"config": {
"window_size": [
60
],
"window_type": "sliding",
"limit": [
5
],
"namespace": "example_namespace"
}
}
'
Make sure to replace the following placeholders with your own values:
-
serviceName|Id
: Theid
orname
of the service the plugin configuration will target.
Make the following request:
curl -X POST https://{region}.api.konghq.com/v2/control-planes/{controlPlaneId}/core-entities/services/{serviceId}/plugins/ \
--header "accept: application/json" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $KONNECT_TOKEN" \
--data '
{
"name": "service-protection",
"config": {
"window_size": [
60
],
"window_type": "sliding",
"limit": [
5
],
"namespace": "example_namespace"
}
}
'
Make sure to replace the following placeholders with your own values:
-
region
: Geographic region where your Kong Konnect is hosted and operates. -
controlPlaneId
: Theid
of the control plane. -
KONNECT_TOKEN
: Your Personal Access Token (PAT) associated with your Konnect account. -
serviceId
: Theid
of the service the plugin configuration will target.
See the Konnect API reference to learn about region-specific URLs and personal access tokens.
echo "
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: service-protection
namespace: kong
annotations:
kubernetes.io/ingress.class: kong
config:
window_size:
- 60
window_type: sliding
limit:
- 5
namespace: example_namespace
plugin: service-protection
" | kubectl apply -f -
Next, apply the KongPlugin
resource by annotating the service
resource:
kubectl annotate -n kong service SERVICE_NAME konghq.com/plugins=service-protection
Prerequisite: Configure your Personal Access Token
terraform {
required_providers {
konnect = {
source = "kong/konnect"
}
}
}
provider "konnect" {
personal_access_token = "$KONNECT_TOKEN"
server_url = "https://us.api.konghq.com/"
}
Add the following to your Terraform configuration to create a Konnect Gateway Plugin:
resource "konnect_gateway_plugin_service_protection" "my_service_protection" {
enabled = true
config = {
window_size = [60]
window_type = "sliding"
limit = [5]
namespace = "example_namespace"
}
control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
service = {
id = konnect_gateway_service.my_service.id
}
}