Created
July 17, 2020 21:28
-
-
Save pandeybk/f5cd07d16b1cb87ccf783f3c90984712 to your computer and use it in GitHub Desktop.
multus-sample-application.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
# This net-attach-def defines macvlan-conf with | |
# + ips capabilities to specify ip in pod annotation and | |
# + mac capabilities to specify mac address in pod annotation | |
# default gateway is defined as well | |
apiVersion: "k8s.cni.cncf.io/v1" | |
kind: NetworkAttachmentDefinition | |
metadata: | |
name: macvlanpod-conf | |
spec: | |
config: '{ | |
"cniVersion": "0.3.1", | |
"plugins": [ | |
{ | |
"type": "macvlan", | |
"capabilities": { "ips": true }, | |
"master": "ens3.482", | |
"mode": "bridge", | |
"ipam": { | |
"type": "static", | |
"routes": [ | |
{ | |
"dst": "0.0.0.0/0", | |
"gw": "10.250.0.1" | |
} | |
] | |
} | |
}, { | |
"capabilities": { "mac": true }, | |
"type": "tuning" | |
} | |
] | |
}' | |
--- | |
# Define a pod with macvlan-conf, defined above, with ip address and mac, and | |
# "gateway" overrides default gateway to use macvlan-conf's one. | |
# without "gateway" in k8s.v1.cni.cncf.io/networks, default route will be cluster | |
# network interface, eth0, even tough macvlan-conf has default gateway config. | |
apiVersion: v1 | |
kind: Pod | |
metadata: | |
name: macvlan-samplepod | |
annotations: | |
k8s.v1.cni.cncf.io/networks: '[ | |
{ "name": "macvlanpod-conf", | |
"ips": [ "10.250.3.200/32" ], | |
"mac": "fa:16:3e:78:6d:08", | |
"gateway": [ "10.250.0.1" ] | |
}]' | |
spec: | |
nodeSelector: | |
beta.kubernetes.io/arch: amd64 | |
cni: multus | |
containers: | |
- name: samplepod | |
command: ["/bin/bash", "-c", "trap : TERM INT; sleep infinity & wait"] | |
image: dougbtv/centos-network | |
ports: | |
- containerPort: 80 | |
--- | |
apiVersion: v1 | |
kind: Pod | |
metadata: | |
name: macvlan-samplepod | |
annotations: | |
k8s.v1.cni.cncf.io/networks: macvlanpod-conf | |
spec: | |
containers: | |
- name: samplepod | |
command: ["/bin/ash", "-c", "trap : TERM INT; sleep infinity & wait"] | |
image: alpine | |
--- | |
cat <<EOF | kubectl create -f - | |
apiVersion: "k8s.cni.cncf.io/v1" | |
kind: NetworkAttachmentDefinition | |
metadata: | |
name: macvlan-conf-host | |
spec: | |
config: '{ | |
"cniVersion": "0.3.0", | |
"type": "macvlan", | |
"master": "ens3", | |
"mode": "bridge", | |
"ipam": { | |
"type": "host-local", | |
"subnet": "192.168.4.0/24", | |
"rangeStart": "192.168.4.200", | |
"rangeEnd": "192.168.4.216", | |
"routes": [ | |
{ "dst": "0.0.0.0/0" } | |
], | |
"gateway": "192.168.4.1" | |
} | |
}' | |
EOF | |
cat <<EOF | kubectl create -f - | |
apiVersion: v1 | |
kind: Pod | |
metadata: | |
name: samplepod-host | |
annotations: | |
k8s.v1.cni.cncf.io/networks: macvlan-conf-host | |
spec: | |
nodeSelector: | |
beta.kubernetes.io/arch: amd64 | |
cni: multus | |
containers: | |
- name: samplepod | |
command: ["/bin/ash", "-c", "trap : TERM INT; sleep infinity & wait"] | |
image: alpine | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment