Skip to content

Instantly share code, notes, and snippets.

@mitio
Last active November 15, 2018 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mitio/34052df217516797223437af86267d53 to your computer and use it in GitHub Desktop.
Save mitio/34052df217516797223437af86267d53 to your computer and use it in GitHub Desktop.

Kubernetes Networking Workshop

Goal

ns (10.192.10.200/24) -- veth pair -- cni0 bridge (10.192.10.1/24) -- flannel.1 vxlan (10.192.10.0/32) -- ec2 -- ec2 -- flannel.1 vxlan (10.192.11.0/32) -- cni0 bridge (10.192.11.1/24) -- veth pair -- ns (10.192.11.200/24)

Step 1: VXLAN

Machine 1: IP 172.31.16.42 flannel.1 MAC: 12:8e:23:42:22:1e

ip link add name flannel.1 type vxlan id 1 nolearning local 172.31.16.42 dstport 8472 dev eth0 # own EC2 private IP
ip a add 10.192.10.0/32 dev flannel.1
ip link set flannel.1 up
ip neigh add 10.192.11.0 dev flannel.1 lladdr  # mac address of flannel.1 on the other machine
bridge fdb add b2:80:39:5e:48:26 dev flannel.1 dst 172.31.22.64 # private EC2 IP of the other machine
ip r add 10.192.11.0/24 via 10.192.11.0 dev flannel.1 onlink

Machine 2: IP 172.31.22.64 flannel.1 MAC: b2:80:39:5e:48:26

ip link add name flannel.1 type vxlan id 1 nolearning local 172.31.22.64 dstport 8472 dev eth0 # own EC2 private IP
ip a add 10.192.11.0/32 dev flannel.1
ip link set flannel.1 up
ip neigh add 10.192.10.0 dev flannel.1 lladdr 12:8e:23:42:22:1e
bridge fdb add 12:8e:23:42:22:1e dev flannel.1 dst 172.31.16.42
ip r add 10.192.10.0/24 via 10.192.10.0 dev flannel.1 onlink

At this stage, ping 10.192.11.0 from machine 1 should work.

Step 2: NS

Machine 1:

sysctl net.ipv4.ip_forward=1 # Important

ip netns add mitio
ip link add nseth type veth peer name rootnseth
ip link set nseth netns mitio
ip link add cni0 type bridge
ip link set rootnseth master cni0
ip addr add 10.192.10.1/24 dev cni0
ip netns exec mitio ip a add 10.192.10.200/24 dev nseth
ip netns exec ip r add 10.192.10.0/32 dev cni0 scope link src 10.192.10.1
ip link set cni0 up
ip link set rootnseth up
ip netns exec mitio ip link set nseth up
ip netns exec mitio ip r add default via 10.192.10.1 dev nseth

Machine 2:

sysctl net.ipv4.ip_forward=1 # Important

ip netns add mitio
ip link add nseth type veth peer name rootnseth
ip link set nseth netns mitio
ip link add cni0 type bridge
ip link set rootnseth master cni0
ip addr add 10.192.11.1/24 dev cni0
ip netns exec mitio ip a add 10.192.11.200/24 dev nseth
ip link set cni0 up
ip link set rootnseth up
ip netns exec mitio ip link set nseth up
ip netns exec mitio ip r add default via 10.192.11.1 dev nseth

At this stage, ip netns exec mitio ping 10.192.11.200 from machine 1 should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment