├── network ├── none.yml ├── flannel.yml └── calico.yml ├── tools ├── ns │ ├── ns1 │ ├── ns │ ├── ns2 │ └── ns0 └── iftype ├── .gitignore ├── .travis.yml ├── join ├── install ├── vagrant ├── single │ └── Vagrantfile └── twin │ └── Vagrantfile ├── init ├── README.en.md └── README.md /network/none.yml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tools/ns/ns1: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ $EUID -ne 0 ]]; then echo "root required" 1>&2; exit 1; fi 4 | 5 | ./ns0 | sort -k 1n | uniq -w 20 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | vagrant/single/* 2 | vagrant/twin/* 3 | .vagrant/* 4 | *.log 5 | 6 | # direnv.net configs 7 | .envrc 8 | 9 | # temporary configs 10 | /Vagrantfile 11 | .kubeconfig 12 | 13 | # editor temporary files 14 | *.swp 15 | *~ 16 | -------------------------------------------------------------------------------- /tools/ns/ns: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # credits to 4 | # https://unix.stackexchange.com/questions/505112/how-do-i-find-all-interfaces-that-have-been-configured-in-linux-including-those/505978#505978 5 | 6 | if [[ $EUID -ne 0 ]]; then echo "root required" 1>&2; exit 1; fi 7 | 8 | ./ns1 | ./ns2 -------------------------------------------------------------------------------- /tools/ns/ns2: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ $EUID -ne 0 ]]; then echo "root required" 1>&2; exit 1; fi 4 | 5 | echo -n 'INIT NETWORK: ' ; stat -L -c %i /proc/1/ns/net 6 | echo '' 7 | 8 | while read -r inode reference; do 9 | echo "network $inode" 10 | if nsenter --net="$reference" ip -br address show 2>/dev/null; then 11 | echo '' 12 | fi 13 | done -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | dist: xenial 2 | language: generic 3 | addons: 4 | apt: 5 | packages: 6 | - iproute2 7 | install: 8 | - sudo ./install 9 | script: 10 | - sudo ./init $(ip r | grep '^default' | grep -o 'dev .*' | cut -d' ' -f2) 11 | - KUBECONFIG=/etc/kubernetes/admin.conf sudo kubectl apply -f network/$NETWORK.yml 12 | env: 13 | - NETWORK="flannel" 14 | - NETWORK="calico" -------------------------------------------------------------------------------- /tools/ns/ns0: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ $EUID -ne 0 ]]; then echo "root required" 1>&2; exit 1; fi 4 | 5 | lsns -n -u -t net -o NS,PATH | while read inode path; do printf '%20u %s\n' $inode "$path"; done 6 | 7 | awk '$3 == "nsfs" { print $2 }' /proc/mounts | while read -r mount; do 8 | stat -c '%20i %n' "$mount" 9 | done 10 | 11 | find /proc/ -mindepth 1 -maxdepth 1 -name '[1-9]*' | while read -r procpid; do 12 | find $procpid/fd -mindepth 1 | while read -r procfd; do 13 | if [ "$(stat -f -c %T $procfd)" = nsfs ]; then 14 | stat -L -c '%20i %n' $procfd 15 | fi 16 | done 17 | done 2>/dev/null -------------------------------------------------------------------------------- /join: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ $EUID -ne 0 ]]; then echo "root required" 1>&2; exit 1; fi 4 | 5 | if [ -z "$1" ] || [ -z "$2" ]; then 6 | echo "Usage: $0 , eg $0 eth0 192.168.56.110:6443" 7 | echo "Interfaces found (UP only):" 8 | ip a | grep --color=never UP 9 | 10 | exit 255; 11 | fi 12 | 13 | IP=$(ip -4 addr show $1 | grep -oP '(?<=inet\s)\d+(\.\d+){3}') 14 | 15 | if [ -z "$IP" ]; then 16 | echo "No IPv4 found on $1" 1>&2; 17 | exit 1; 18 | fi 19 | 20 | cat << EOF > /etc/default/kubelet 21 | KUBELET_EXTRA_ARGS="--node-ip=$IP" 22 | EOF 23 | 24 | kubeadm join $2 --token abcdef.k1s0static0token --discovery-token-unsafe-skip-ca-verification 25 | -------------------------------------------------------------------------------- /tools/iftype: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Credits to 4 | # https://unix.stackexchange.com/questions/272850/how-to-determine-the-logical-type-of-a-linux-network-device 5 | 6 | # Arguments: $1: Interface ('grep'-regexp). 7 | 8 | # Static list of types (from `ip link help`): 9 | TYPES=(bond bond_slave bridge dummy gre gretap ifb ip6gre ip6gretap ip6tnl ipip ipoib ipvlan macvlan macvtap nlmon sit vcan veth vlan vti vxlan tun tap) 10 | 11 | iface="$1" 12 | 13 | for type in "${TYPES[@]}"; do 14 | ip link show type "${type}" | grep -E '^[0-9]+:' | cut -d ':' -f 2 | sed 's|^[[:space:]]*||' | while read _if; do 15 | echo "${_if}:${type}" 16 | done | grep "^${iface}" 17 | done 18 | 19 | -------------------------------------------------------------------------------- /install: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ $EUID -ne 0 ]]; then echo "root required" 1>&2; exit 1; fi 4 | 5 | VERSION="${1:-1.25.5-00}" 6 | 7 | apt-get update 8 | 9 | apt-get install -qy containerd gnupg2 apt-transport-https curl 10 | 11 | curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - 12 | echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" | tee /etc/apt/sources.list.d/kubernetes.list 13 | 14 | apt-get update 15 | 16 | apt-get install -qy kubelet=${VERSION} kubeadm=${VERSION} kubectl=${VERSION} kubernetes-cni 17 | apt-mark hold kubelet kubeadm kubectl 18 | 19 | swapoff -a 20 | sed -i 's/\(.*swap.*\)/#\1/g' /etc/fstab 21 | 22 | modprobe br_netfilter 23 | echo "br_netfilter" | tee /etc/modules-load.d/br_netfilter.conf 24 | 25 | echo "net.ipv4.ip_forward = 1" | tee /etc/sysctl.d/9999-k8s.conf 26 | echo "net.bridge.bridge-nf-call-iptables = 1" | tee -a tee /etc/sysctl.d/9999-k8s.conf 27 | sysctl --system 28 | -------------------------------------------------------------------------------- /vagrant/single/Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | $network = ENV["NETWORK"] || "flannel" 5 | 6 | $ip = "192.168.33.110" 7 | 8 | $script = <