Skip to content
Traffic shaping with Cilium

Traffic shaping with Cilium in Thalassa Cloud Kubernetes

Thalassa Cloud Kubernetes includes a managed Cilium CNI. You limit the network rate of a workload with Pod annotations. The managed Cilium agent enforces the limit. You do not install Cilium, edit the Cilium configuration, or change the Cilium DaemonSet.

This guide applies to clusters that use the managed Cilium CNI. That is the default. A cluster that uses a custom CNI does not include this bandwidth manager.

Egress pacing uses Earliest Departure Time (EDT) on the node. Ingress limiting uses an eBPF token bucket. The limit covers the whole Pod. Each replica has its own limit.

Prerequisites

  • A Thalassa Cloud Kubernetes cluster that uses the managed Cilium CNI.
  • kubectl access. Use tcloud kubernetes connect or a kubeconfig. See Getting Started.
  • Permission to create Pods in the target namespace.
  • Two Ready nodes for the rate test. Cilium enforces the egress limit on the node network device, so the two Pods must run on different nodes.

Set a Pod rate

Add the annotations to the Pod template. kubernetes.io/egress-bandwidth limits traffic that leaves the Pod. kubernetes.io/ingress-bandwidth limits traffic that enters the Pod. Set one annotation or both.

The value is a Kubernetes quantity in bits per second:

ValueRate
10M10 Mbit/s
100M100 Mbit/s
1G1 Gbit/s
10Mi10 mebibit/s

M is a decimal mega (1,000,000). Mi is a binary mebi (1,048,576).

apiVersion: apps/v1
kind: Deployment
metadata:
  name: api
  namespace: production
spec:
  replicas: 2
  selector:
    matchLabels:
      app: api
  template:
    metadata:
      labels:
        app: api
      annotations:
        kubernetes.io/egress-bandwidth: "50M"
        kubernetes.io/ingress-bandwidth: "100M"
    spec:
      containers:
        - name: api
          image: nginx:1.27

Change the Pod template and apply it. The Deployment creates Pods that use the new rate. The node machine type remains the upper bound for traffic on that node.

Test the limit

This test runs iperf3 between two Pods on the managed cluster network. The server Pod has a 10 Mbit/s egress limit and a 20 Mbit/s ingress limit. Delete the namespace when you finish. Keep port 5201 inside the cluster. Do not publish it with a Service.

apiVersion: v1
kind: Namespace
metadata:
  name: bandwidth-demo
---
apiVersion: v1
kind: Pod
metadata:
  name: netperf-server
  namespace: bandwidth-demo
  labels:
    app.kubernetes.io/name: netperf-server
  annotations:
    kubernetes.io/egress-bandwidth: "10M"
    kubernetes.io/ingress-bandwidth: "20M"
spec:
  containers:
    - name: netperf
      image: cilium/netperf
      args: ["iperf3", "-s"]
      ports:
        - containerPort: 5201
---
apiVersion: v1
kind: Pod
metadata:
  name: netperf-client
  namespace: bandwidth-demo
spec:
  affinity:
    podAntiAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        - labelSelector:
            matchLabels:
              app.kubernetes.io/name: netperf-server
          topologyKey: kubernetes.io/hostname
  containers:
    - name: netperf
      image: cilium/netperf
      args: ["sleep", "infinity"]

Wait until both Pods are Running. Measure egress from the server. -R makes the server send:

NETPERF_SERVER_IP=$(kubectl get pod -n bandwidth-demo netperf-server -o jsonpath='{.status.podIP}')
kubectl exec -n bandwidth-demo netperf-client -- iperf3 -R -c "${NETPERF_SERVER_IP}"

The receiver rate stays near 10 Mbit/s.

Measure ingress to the server. The client sends:

kubectl exec -n bandwidth-demo netperf-client -- iperf3 -c "${NETPERF_SERVER_IP}"

The rate settles near 20 Mbit/s. The first seconds can be higher. The ingress limiter is a token bucket, so a new flow can burst.

Remove the test:

kubectl delete namespace bandwidth-demo

When the measured rate stays far above the annotation, contact support through the Thalassa Cloud Console. The Cilium agent is part of the managed service.

Limitations

  • A Cilium Network Policy with Layer 7 rules selects a Pod on egress. Cilium then turns bandwidth enforcement off for that Pod.
  • The limit is per Pod. It is not per container and it is not per connection.
  • Pods on the same node do not show the egress limit in an iperf3 test. Run the two Pods on different nodes.

References