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.
kubectlaccess. Usetcloud kubernetes connector 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:
| Value | Rate |
|---|---|
10M | 10 Mbit/s |
100M | 100 Mbit/s |
1G | 1 Gbit/s |
10Mi | 10 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.27Change 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-demoWhen 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
iperf3test. Run the two Pods on different nodes.