OpenShift 4 with MacVLAN and whereabouts

About this tutorial

How do it works ?

Option 1 — Network Operator

# oc edit networks.operator.openshift.io cluster
# cat > cluster-macvlan-network.yaml << EOF
apiVersion: operator.openshift.io/v1
kind: Network
metadata:
name: cluster
spec:
additionalNetworks:
- name : net-test
namespace: openshift-multus
type: Raw
rawCNIConfig: |-
{ "cniVersion": "0.3.1",
"name": "test",
"type": "macvlan",
"master": "bond0.100",
"ipam": {
"type": "whereabouts",
"range": "10.10.10.0/24",
"exclude": [
"10.10.10.0/32",
"10.10.10.1/32",
"10.10.10.254/32"
],
"routes": [{"dst": "10.10.10.224/32"}]
}
}
EOF

Adding the Network

# oc apply -f cluster-macvlan-network.yaml

Option 2 — Network Attached definition

# cat > nad-macvlan-network.yaml << EOF
apiVersion: k8s.cni.cncf.io/v1
kind: NetworkAttachmentDefinition
metadata:
name: net-test
namespace: openshift-multus
spec:
config: |-
{ "cniVersion": "0.3.1",
"name": "test",
"type": "macvlan",
"master": "bond0.100",
"ipam": {
"type": "whereabouts",
"range": "10.10.10.0/24",
"exclude": [
"10.10.10.0/32",
"10.10.10.1/32",
"10.10.10.254/32"
],
"routes": [{"dst": "10.10.10.224/32"}]
}
}
EOF

Adding the Network

# oc apply -f nad-macvlan-network.yaml

Optional

"ipam": { 
"type": "whereabouts",
"range": "10.10.10.0/24",
....
"gateway": "10.10.10.254"
"routes": [{"dst": "192.168.4.0/24"}]
}
# oc get network-attachment-definitions -n openshift-multus
NAME AGE
net-test 14m

Pod Configuration

annotations:
k8s.v1.cni.cncf.io/networks: |-
[
{
"name": "net-test",
"namespace": "openshift-multus",
"default-route": ["10.10.10.254"]
}
]

--

--

Open Source contributer for the past 15 years

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store