Skip to content

Instantly share code, notes, and snippets.

@brianthelion
Last active December 23, 2021 02:08
Show Gist options
  • Save brianthelion/ff6f322bcf46e363c64ed53dabc659a5 to your computer and use it in GitHub Desktop.
Save brianthelion/ff6f322bcf46e363c64ed53dabc659a5 to your computer and use it in GitHub Desktop.
Complete example of how to run multus on kind with limited shenanigans
set -ex
RND=$(openssl rand -hex 12)
NET=net-${RND}
IFACE=if-${RND}
CLUSTER=cl-${RND}
TMP=$(mktemp -d)
CFG=${TMP}/config.yaml
LOG=${TMP}/log
POD=${TMP}/pod
NAD=${TMP}/nad
URL="https://raw.githubusercontent.com/k8snetworkplumbingwg/multus-cni/master/deployments/multus-daemonset.yml"
SHA="5238fbb2767cbf6aae736ad97a7aa29167525dcd405196dfbc064672a730d3cf cni-plugins-linux-amd64-v1.0.1.tgz"
CNIS="https://github.com/containernetworking/plugins/releases/download/v1.0.1/cni-plugins-linux-amd64-v1.0.1.tgz"
KIND=$(which kind)
cat <<EOF > ${CFG}
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
EOF
${KIND} create cluster --name ${CLUSTER} --config ${CFG}
${KIND} load docker-image centos:latest --name ${CLUSTER}
kubectl cluster-info kind-${CLUSTER}
docker network create ${NET}
for NODE in $(${KIND} get nodes --name ${CLUSTER}); do
docker network connect ${NET} ${NODE}
docker exec -it ${NODE} bash -c "test -f /opt/cni/macvlan || curl -sL ${CNIS} | tar -xvz -C /opt/cni/bin"
done
kubectl apply -f ${URL}
kubectl get pods -A
sleep 90
kubectl get pods -A
cat <<EOF > ${NAD}
apiVersion: "k8s.cni.cncf.io/v1"
kind: NetworkAttachmentDefinition
metadata:
name: dlan-conf
spec:
config: '{
"cniVersion": "0.3.1",
"type": "macvlan",
"master": "eth1",
"mode": "bridge"
}'
EOF
cat <<EOF > ${POD}
apiVersion: v1
kind: Pod
metadata:
name: dlan-test
annotations:
k8s.v1.cni.cncf.io/networks: dlan-conf@dlan0
spec:
containers:
- name: dlan-test
image: centos:latest
command: ["/bin/sh", "-c"]
args: ["sleep infinity"]
nodeName: ${CLUSTER}-worker
EOF
kubectl apply -f ${NAD}
kubectl apply -f ${POD}
kubectl wait --for=condition=ready -f ${POD} --timeout=60s || \
kubectl cluster-info dump kind-${CLUSTER} > ${LOG}
kubectl exec -it dlan-test -- ip -br link show
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment