Last active
May 29, 2023 21:44
-
-
Save alexeldeib/37f64ebafa053b2579e60797bcd70a8a to your computer and use it in GitHub Desktop.
CNI fiddling with 6rd/teredo/6to4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# n.b.: nodes are in 172.18.0.0/16 | |
# hash subnet range with sha256 -> first 10 digit for prefix | |
hash_prefix=$(ip r | grep -E "\/[0-9]+ dev eth0" | cut -d' ' -f1 | sha256sum | head -c 10) | |
# prepend with fd for unique local address predix for 6rd routing | |
rd_prefix="fd${hash_prefix}" | |
# add colons between each 4 hex chars | |
rd_prefix_formatted=$(echo "${rd_prefix}" | fold -w4 | paste -sd:) | |
local_addr=$(ip a show dev eth0 | grep -E 'inet ' | cut -d' ' -f6 | cut -d'/' -f1) | |
# get local IPv4 subnet as XX.XX.XX.XX/XX | |
local_subnet=$(ip r | grep -E "\/[0-9]+ dev eth0" | head -n 1 |cut -d' ' -f1) | |
# get 16 lower bits from IPv4 address | |
# TODO: should convert from hex, and also calculate how many bits dynamically | |
subnet_suffix=$(ip a show dev eth0 | grep -E 'inet ' | head -n 1 | cut -d' ' -f6 | cut -d'/' -f1 | cut -d. -f3- | tr -d . | xargs printf '%04d\n' | head -n 1) | |
# configure tunnel with kernel native translation/routing | |
ip tunnel add kubetunnel0 mode sit local $local_addr ttl 64 | |
# we use ourselves as the relay. many online demos use ISP relays. | |
ip tunnel 6rd dev kubetunnel0 6rd-prefix "${rd_prefix_formatted}::/48" 6rd-relay_prefix "${local_subnet}" | |
# append this nodes 16 lower bits to the ULA prefix for this nodes unique IPv6 pod range | |
ip -6 addr add "${rd_prefix_formatted}:${subnet_suffix}::1/48" dev kubetunnel0 | |
ip link set kubetunnel0 up | |
# delete the default address for the device with the node IP | |
ip -6 addr delete "::${local_addr}/96" dev kubetunnel0 | |
# enable foo over UDP (makes ICMP6 and other goodness work in Azure) | |
ip link set name kubetunnel0 type sit encap fou encap-sport auto encap-dport 3544 | |
ip addr show dev kubetunnel0 | |
mkdir -p /etc/cni.d | |
tee /etc/cni.d/10-kubernetes-overlay.conflist >/dev/null <<EOF | |
{ | |
"cniVersion": "0.3.1", | |
"name": "kubenet", | |
"type": "bridge", | |
"bridge": "kubebridge0", | |
"hairpinMode": true, | |
"ipam": { | |
"type": "host-local", | |
"ranges": [ | |
[ { "subnet": "${rd_prefix_formatted}:${subnet_suffix}::1/48" } ], | |
], | |
"routes": [ | |
{ "dst": "0.0.0.0/0" }, | |
{ "dst": "${rd_prefix_formatted}:${subnet_suffix}::/48" } | |
], | |
"dataDir": "/var/run/cni/networks/kubernetes-overlay" | |
} | |
} | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment