Skip to content

Instantly share code, notes, and snippets.

@dougbtv
Last active December 21, 2022 19:42
Show Gist options
  • Save dougbtv/a1f2b40bb3e57429ab0dcd8ad4d96c42 to your computer and use it in GitHub Desktop.
Save dougbtv/a1f2b40bb3e57429ab0dcd8ad4d96c42 to your computer and use it in GitHub Desktop.
Multus runtime config (for IP / mac address)

all-in-one-example

---
apiVersion: "k8s.cni.cncf.io/v1"
kind: NetworkAttachmentDefinition
metadata:
  name: centos-runtimeconfig-def
spec:
  config: '{
      "cniVersion": "0.3.1",
      "name": "aioexample",
      "plugins": [{
          "type": "bridge",
          "bridge": "cnitest0",
          "name": "testbridge",
          "ipam": {
            "type": "static"
          }
        }, {
          "capabilities": { "mac": true, "ips": true },
          "type": "tuning"
        }]
    }'
---
apiVersion: v1
kind: Pod
metadata:
  name: staticippod
  annotations:
    k8s.v1.cni.cncf.io/networks: '[
      {
        "name": "centos-runtimeconfig-def",
        "ips": [ "192.168.2.205/24" ],
        "mac": "CA:FE:C0:FF:EE:00"
      }
    ]'
spec:
  containers:
  - name: staticippod
    command: ["/bin/ash", "-c", "trap : TERM INT; sleep infinity & wait"]
    image: alpine

net-attach-def used:

apiVersion: "k8s.cni.cncf.io/v1"
kind: NetworkAttachmentDefinition
metadata:
  name: centos-runtimeconfig-def
spec:
  config: '{
      "cniVersion": "0.3.1",
      "plugins": [{
          "type": "macvlan",
          "capabilities": { "ips": true },
          "master": "eth0",
          "mode": "bridge",
          "ipam": {
            "type": "static"
          }
        }, {
          "capabilities": { "mac": true },
          "type": "tuning"
        }]
    }'

pod spec used:

apiVersion: v1
kind: Pod
metadata:
  name: samplepod
  annotations:
    k8s.v1.cni.cncf.io/networks: '[
      {
        "name": "centos-runtimeconfig-def",
        "ips": [ "192.168.2.205/24" ],
        "mac": "CA:FE:C0:FF:EE:00"
      }
    ]'
spec:
  containers:
  - name: samplepod
    command: ["/bin/bash", "-c", "trap : TERM INT; sleep infinity & wait"]
    image: dougbtv/centos-network
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment