post image :date_long | 1 min Read

CKS Kubernetes CNI

Container infor passed by kubelet to stdin of CNI bash plugin

CNI_CONTAINERID=b552f9...
CNI_IFNAME=eth0
CNI_COMMAND=ADD
CNI_NETNS=/proc/6137/ns/net

...

# interesting fact
ls -sfT $CNI_NETNS /var/run/netns/$CNI_CONTAINERID

How to create client/server namespace and run python webserver

https://www.redhat.com/sysadmin/net-namespaces

export namespace1=client
export namespace2=server
export command='python3 -m http.server'
export ip_address1="10.10.10.10/24"
export ip_address2='10.10.10.20/24'
export interface1=veth-client
export interface2=veth-server

ip netns add $namespace1
ip netns add $namespace2
ip link add ptp-$interface1 type veth peer name ptp-$interface2
ip link set ptp-$interface1 netns $namespace1
ip link set ptp-$interface2 netns $namespace2
ip netns exec $namespace1 ip addr add $ip_address1 dev ptp-$interface1
ip netns exec $namespace2 ip addr add $ip_address2 dev ptp-$interface2
ip netns exec $namespace1 ip link set dev ptp-$interface1 up
ip netns exec $namespace2 ip link set dev ptp-$interface2 up
ip netns exec $namespace2 $command &
ip netns pids $namespace2
ip netns ls
ls -ltr /proc/*/ns/net | grep 15035

root@tf-srv-gallant-shaw:~# ip netns exec $namespace1 curl 10.10.10.20:8000

author image

Jan Toth

I have been in DevOps related jobs for past 6 years dealing mainly with Kubernetes in AWS and on-premise as well. I spent quite a lot …

comments powered by Disqus