Add container option to tc to apply docker container-level traffic control#331
Add container option to tc to apply docker container-level traffic control#331mininny wants to merge 2 commits intoethpandaops:masterfrom
Conversation
|
This is nice. Thanks @mininny ! But there's a problem if we recreate containers, which would require the script to be rerun due to changing PIDs. |
@skylenet Thank you! Yea, that is a problem... I looked up some things, and it seems like docker offers system events, so we could use that in the script like this: docker events --filter 'event=start' --filter 'container=container' | while read event; do
echo "Detected start event for container"
container_pid=$(docker inspect -f '{{.State.Pid}}' container)
rm -f /var/run/netns/container_ns
ln -sfT /proc/$container_pid/ns/net /var/run/netns/container_ns
echo "Updated network namespace for container"
done &Since we're running the script in systemd, stopping the systemd will also stop this event process. |
I think this could work. But we have to make sure that we resubscribe to the event stream if the connection is dropped for whatever reason. (e.g. docker engine restart) |
This change allows the traffic-control setup to apply changes to a specific container:
Linking the Container’s Network Namespace:
The script retrieves the container’s PID using
docker inspectand then creates a symbolic link (in/var/run/netns/) that points to the container’s network namespace. This allows us to run network commands inside the container’s namespace viaip netns exec.Conditional Creation of a Virtual Interface:
I've noticed that in the original script, if the helper interface (here,
ifbeth0) already exists in the container’s network namespace, it errors. So I added a check to make sure it doesn't exist before adding the interface.This option can be enabled like:
I've tested the setup locally and verified that the tc is applied to the specific container