Kubernetes init container for throttling bandwidth with tc.
Currently, only egress bandwidth limits work (sending data out of the container).
...if you don't have to!
Kubernetes has annotations that should enable you to accomplish bandwidth limits without any help:
spec:
annotations:
- kubernetes.io/egress-bandwidth: 1M
- kubernetes.io/ingress-bandwidth: 10M
Unfortunately, I've found that many network implementations do not respect these annotations (as of kubernetes 1.8, anyway), so test if these more official annotations work before adopting tc-init.
Add tc-init to your containers as an initContainer.
It will run tc
and limit the egress bandwidth to EGRESS_BANDWIDTH.
The value is passed to tc,
e.g 10mbit
for ten megabits per second,
or 5mbps
for five megabytes per second.
For example:
spec:
initContainers:
- name: tc-init
image: minrk/tc-init
env:
- name: EGRESS_BANDWIDTH
value: 1mbit
securityContext:
capabilities:
add:
- NET_ADMIN