Skip to content

Instantly share code, notes, and snippets.

@LionelJouin
Last active October 11, 2024 14:44
Show Gist options
  • Save LionelJouin/e8fab6b11610d774d581658b65d2d909 to your computer and use it in GitHub Desktop.
Save LionelJouin/e8fab6b11610d774d581658b65d2d909 to your computer and use it in GitHub Desktop.
VLAN config

Install Multus:

helm install multus ./deployments/Multus --set registry=ghcr.io/lioneljouin/l-3-4-gateway-api-poc

VLAN

cat <<EOF | kubectl apply -f -
---
apiVersion: "k8s.cni.cncf.io/v1"
kind: NetworkAttachmentDefinition
metadata:
  name: vlan-255
spec:
  config: '{
    "cniVersion": "0.4.0",
    "type": "vlan",
    "name": "vlan-255",
    "master": "eth0",
    "vlanId": 255,
    "linkInContainer": false,
    "ipam": {
      "type": "static",
      "addresses": [
        {
          "address": "155.1.1.11/24"
        }
      ],
      "routes": [
        {
          "dst": "20.0.0.1/32",
          "gw": "155.1.1.12"
        }
      ]
    }
  }'
EOF

Example:

---
apiVersion: v1
kind: Pod
metadata:
  name: macvlan1-worker1
  annotations:
    k8s.v1.cni.cncf.io/networks: '[{"name": "vlan-255", "interface": "net1"}]'
  labels:
    app: macvlan
spec:
  containers:
    - name: macvlan-worker1
      image: docker.io/library/alpine:latest
      command: ["/bin/sleep", "10000"]

https://developers.redhat.com/blog/2018/10/22/introduction-to-linux-interfaces-for-virtual-networking#vlan Create a VLAN manually:

ip link add link eth0 name vlan255 type vlan id 255
ip addr add 155.1.1.12/24 dev vlan255
ip link set vlan255 up
# ip rule add from 20.0.0.1/32 table 2500
# ip route add table 2500 nexthop via 155.1.1.11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment