Skip to content

Instantly share code, notes, and snippets.

@LionelJouin
Last active December 3, 2024 13:45
Show Gist options
  • Select an option

  • Save LionelJouin/e9808eea9f9f7716dc1f67cf8753ddfd to your computer and use it in GitHub Desktop.

Select an option

Save LionelJouin/e9808eea9f9f7716dc1f67cf8753ddfd to your computer and use it in GitHub Desktop.
nad-macvlan-vlan-100

Install Multus:

kubectl apply -f https://raw.githubusercontent.com/k8snetworkplumbingwg/multus-cni/master/e2e/templates/cni-install.yml.j2
kubectl apply -f https://raw.githubusercontent.com/k8snetworkplumbingwg/multus-cni/master/deployments/multus-daemonset-thick.yml
kubectl apply -f https://raw.githubusercontent.com/k8snetworkplumbingwg/whereabouts/refs/tags/v0.8.0/doc/crds/daemonset-install.yaml
kubectl apply -f https://raw.githubusercontent.com/k8snetworkplumbingwg/whereabouts/refs/tags/v0.8.0/doc/crds/whereabouts.cni.cncf.io_ippools.yaml
kubectl apply -f https://raw.githubusercontent.com/k8snetworkplumbingwg/whereabouts/refs/tags/v0.8.0/doc/crds/whereabouts.cni.cncf.io_overlappingrangeipreservations.yaml

Install demo

cat <<EOF | kubectl apply -f -
---
apiVersion: "k8s.cni.cncf.io/v1"
kind: NetworkAttachmentDefinition
metadata:
  name: vlan-100-macvlan
  namespace: default
spec:
  config: '{
        "cniVersion": "1.0.0",
        "name": "vlan-100-macvlan",
        "plugins": [
          {
            "type": "macvlan",
            "master": "eth0",
            "mode": "bridge",
            "linkInContainer": false
          },
          {
            "type": "vlan",
            "master": "net1",
            "name": "my-vlan",
            "vlanId": 100,
            "linkInContainer": true,
            "ipam": {
              "log_file": "/tmp/whereabouts.log",
              "type": "whereabouts",
              "ipRanges": [
                {
                  "range": "169.254.100.0/24",
                  "exclude": [
                    "169.254.100.150/32"
                  ]
                },
                {
                  "range": "100:100::/64",
                  "exclude": [
                    "100:100::150/128"
                  ]
                }
              ]
            }
          }
        ]
      }'
---
apiVersion: v1
kind: Pod
metadata:
  name: macvlan-vlan
  annotations:
    k8s.v1.cni.cncf.io/networks: '[{"name": "vlan-100-macvlan", "interface": "net1"}]'
  labels:
    app: macvlan
spec:
  containers:
    - name: macvlan-vlan
      image: docker.io/library/alpine:latest
      command: ["/bin/sleep", "10000"]
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment