Skip to content

For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.

Page as Markdown

    

Request Buffering

Managing the maximum allowed request size is a basic security requirement. NGINX uses the proxy-body-size annotation (equivalent to client_max_body_size). In kgateway, this is configured via the buffer field in a TrafficPolicy.

Before: Ingress with Max Body Size

Configuration for an Ingress that allows uploads up to 20MB:

cat <<'EOF' > upload-ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: upload-demo
  annotations:
    nginx.ingress.kubernetes.io/proxy-body-size: "20m"
spec:
  ingressClassName: nginx
  rules:
  - host: upload.example.com
    http:
      paths:
      - backend:
          service:
            name: upload-svc
            port:
              number: 8080
        path: /
        pathType: Prefix
EOF

Convert

ingress2gateway print --providers=ingress-nginx --emitter=kgateway \
  --input-file upload-ingress.yaml > upload-kgateway.yaml

After: TrafficPolicy with Buffer

The TrafficPolicy enforces the body size limit. buffer.maxRequestSize accepts a Kubernetes Quantity string.

NGINX’s m suffix uses binary multipliers (1024 × 1024), so proxy-body-size: 20m is identical to the Quantity 20Mi. If you copied a value with a decimal suffix (20M), keep in mind it is ~5% smaller (20 × 10^6 bytes).
apiVersion: gateway.kgateway.dev/v1alpha1
kind: TrafficPolicy
metadata:
  name: buffering-policy
spec:
  targetRefs:
  - group: gateway.networking.k8s.io
    kind: HTTPRoute
    name: upload-demo-upload-example-com
  buffer:
    maxRequestSize: "20Mi"

Apply and verify

kubectl apply -f upload-kgateway.yaml
kubectl get trafficpolicies
Was this page helpful?