1
votes

The following K8s implementation correctly creates an IngressRoute however the rate limiting is not applied.

kind: Deployment
apiVersion: apps/v1
metadata:
  name: whoami
  labels:
    app: containous
    name: whoami
  namespace: whoami
spec:
  replicas: 2
  selector:
    matchLabels:
      app: containous
      task: whoami
  template:
    metadata:
      labels:
        app: containous
        task: whoami
    spec:
      containers:
        - name: containouswhoami
          image: containous/whoami
          ports:
            - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: crd-traefik-test
  namespace: whoami
spec:
  ports:
    - name: http
      port: 80
  selector:
    app: containous
    task: whoami
--- 
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: rate-limiting-test
  namespace: whoami
spec:
  entryPoints: 
    - web
  routes:
     - middlewares: 
       - name: crd-service-rate-limiter
     - match: Path(`/bar`)
       kind: Rule
       services:
        - name: crd-traefik-test
          port: 80
---
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: crd-service-rate-limiter
  namespace: whoami
spec:
  rateLimit:
    average: 1
    period: 100

Can anyone help?

Cheers

1

1 Answers

0
votes

Here is my usage of a Middleware resource that defines a path prefix strip

yaml:

apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: auth-ingress-route
spec:
  entryPoints:
    - http
  routes:
    - match: Host(`stuff`) && PathPrefix(`/api/auth`)
      kind: Rule
      middlewares:
        - name: strip-auth-prefix
      services:
        - name: auth-srv
          port: 3000

json:

{
  "apiVersion": "traefik.containo.us/v1alpha1",
  "kind": "IngressRoute",
  "metadata": {
    "name": "auth-ingress-route"
  },
  "spec": {
    "entryPoints": [
      "http"
    ],
    "routes": [
      {
        "match": "Host(`ticketing`) && PathPrefix(`/api/auth`)",
        "kind": "Rule",
        "middlewares": [
          {
            "name": "strip-auth-prefix"
          }
        ],
        "services": [
          {
            "name": "auth-srv",
            "port": 3000
          }
        ]
      }
    ]
  }
}

And here is your version, in YAML and JSON

yaml:

apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: rate-limiting-test
  namespace: whoami
spec:
  entryPoints: 
    - web
  routes:
     - middlewares: 
       - name: crd-service-rate-limiter
     - match: Path(`/bar`)
       kind: Rule
       services:
        - name: crd-traefik-test
          port: 80

json:

{
  "apiVersion": "traefik.containo.us/v1alpha1",
  "kind": "IngressRoute",
  "metadata": {
    "name": "rate-limiting-test",
    "namespace": "whoami"
  },
  "spec": {
    "entryPoints": [
      "web"
    ],
    "routes": [
      {
        "middlewares": [
          {
            "name": "crd-service-rate-limiter"
          }
        ]
      },
      {
        "match": "Path(`/bar`)",
        "kind": "Rule",
        "services": [
          {
            "name": "crd-traefik-test",
            "port": 80
          }
        ]
      }
    ]
  }
}

I'll let you figure out why it might not work