Run a Script When a New Veth Interface Is Added

run a script when a new veth interface is added

You should write a custom udev rule that runs a script of yours each time a new interface is added. This is what Debian does for handling interface "hotplug".

/etc/udev/rules.d/90-my-networking.rules:

SUBSYSTEM=="net",           RUN+="/usr/local/bin/my-networking-agent.sh"

/usr/local/bin/my-networking-agent.sh:

#!/bin/sh
logger "hey I just got interface ${INTERFACE} with action ${ACTION}"

EDIT

Here is how you can test it:

# modprobe dummy0
# ifconfig dummy0 up
# tail -n1 /var/log/syslog
May 3 01:48:06 ernst logger: hey I just got interface dummy0 with action add

How to identify orphaned veth interfaces and how to delete them?

Fixed by upgrade docker to last version.
New version:

root@hostname ~ # docker version
Client:
Version: 1.8.1
API version: 1.20
Go version: go1.4.2
Git commit: d12ea79
Built: Thu Aug 13 02:35:49 UTC 2015
OS/Arch: linux/amd64

Server:
Version: 1.8.1
API version: 1.20
Go version: go1.4.2
Git commit: d12ea79
Built: Thu Aug 13 02:35:49 UTC 2015
OS/Arch: linux/amd64

Now interfaces remove together with containers. Old orphaned interfaces were deleted manually by following command:

# ip link delete <ifname>

docker-compose fails at adding veth (virtual interface) to bridge docker0

It was an issue with the network interface on the machine.

eth0 was not set as the default, instead docker0 was the default interface causing errors.

Read more here: https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/3/html/Reference_Guide/s1-networkscripts-interfaces.html

To fix this issue, changes were made to the files contained in /etc/sysconfig/network-scripts/ which specify how the network interfaces are configured.

how to see the pod and veth relationship in kubernetes

is there anyway to see the relationship of kubernetes v1.15.2 pod and veth?

TL;DR :
Yes.

There is a bunch of similar topics on StackOverflow and even some scripts on Github.

Explanation:

There is a very good article on Kubernetes (K8s) networking.

Oversimplified, "K8s networking" handled by Linux’s network namespaces and virtual interfaces.

Below console output has been taken on my GKE cluster, but shall be applicable to standalone cluster as well.

$ sudo ip link show | egrep "veth|docker" | awk -F":" '{print $1": "$2}'
3: docker0
5: vethcf35c1bb@if3
6: veth287168da@if3
7: veth5c70f15b@if3
11: veth62f193f7@if3
12: vetha38273b3@if3
14: veth240a8f81@if3

sudo docker ps --format '{{.ID}} {{.Names}} {{.Image}}' "$@" | wc -l
25

As you can see, I have 6 veth's serving traffic for 25 docker containers. Let's find the veth that serves traffic for one of the pods.

$ kubectl get pods 
NAME READY STATUS RESTARTS AGE
server-go-7b57857cfb-p6m62 1/1 Running 0 7m41s
  1. Lets find the docker container id for the pod.
$ sudo docker ps --format '{{.ID}} {{.Pid}} {{.Names}} {{.Image}}' "$@" | grep POD_server
6aa1d952a9f3 k8s_POD_server-go-7b57857cfb-p6m62_default_02206a28-42e1-43a5-adb8-f6ab13258fb1_0 k8s.gcr.io/pause:3.1

  1. Checking a pid for it:
$ sudo docker inspect --format '{{.State.Pid}}' 6aa1d952a9f3
4012085

  1. Allowing system tools accessing the namespace of that pid:
$ sudo ln -sf /proc/${pid}/ns/net /var/run/netns/ns-${pid}
#in my case the commands were :
$ if [ ! -d /var/run/netns ]; then sudo mkdir -p /var/run/netns; fi
$ sudo ln -sf /proc/4012085/ns/net /var/run/netns/ns-4012085
$ sudo ip netns exec "ns-4012085" ip link show type veth | grep "eth0"
3: eth0@if14: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1460 qdisc noqueue state UP mode DEFAULT group default

  1. Checking exact interface that serves traffic for the container.

From that output (eth0@if14) we can say that the eth0 for the 6aa1d952a9f3 docker container is linked to the interface 14: veth240a8f81@if3 on host machine.

Based on this example you can write your own script to match veth interfaces to Pods, containers, etc.

Hope that helps.



Related Topics



Leave a reply



Submit