apiVersion: "k8s.cni.cncf.io/v1"
kind: NetworkAttachmentDefinition
metadata:
name: macvlan8
namespace: multicast
spec:
config: '{
"cniVersion": "0.3.1",
"plugins": [
{
"type": "macvlan",
"capabilities": { "ips": true },
"master": "eth1",
"mode": "bridge",
"ipam": {
"type": "static",
"addresses": [
{
"address": "192.168.25.62/22",
"gateway": "192.168.27.254"
}
],
"routes": [
{ "dst": "192.168.24.0/22", "gw": "192.168.27.254" },
{ "dst": "192.168.5.0/24" }
]
}
}
]
}'
示例负载:
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: demo8
name: demo8
namespace: multicast
spec:
replicas: 1
selector:
matchLabels:
app: demo8
template:
metadata:
annotations:
k8s.v1.cni.cncf.io/networks: macvlan8
labels:
app: demo8
spec:
containers:
- name: demo8
command:
- /bin/sh
args:
- '-c'
- "while true; do echo 1;sleep 10; done"
image: '192.168.25.9/hello_multicast_iperf:1_aarch64'
imagePullPolicy: Always
resources:
limits:
cpu: '2'
requests:
cpu: '2'
测试效果:
[root@node1 multus]# kubectl -n multicast exec -it demo8-578986878b-6m5nr -- sh
/ # ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
3: eth0@if75: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1430 qdisc noqueue state UP
link/ether 02:0c:78:14:6e:f9 brd ff:ff:ff:ff:ff:ff
inet 10.233.71.42/32 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::c:78ff:fe14:6ef9/64 scope link
valid_lft forever preferred_lft forever
4: net1@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
link/ether ca:35:41:d3:92:3e brd ff:ff:ff:ff:ff:ff
inet 192.168.25.62/22 brd 192.168.27.255 scope global net1
valid_lft forever preferred_lft forever
inet6 fe80::c835:41ff:fed3:923e/64 scope link
valid_lft forever preferred_lft forever
/ # ip r
default via 169.254.1.1 dev eth0
169.254.1.1 dev eth0 scope link
192.168.5.0/24 via 192.168.27.254 dev net1
192.168.24.0/22 via 192.168.27.254 dev net1
192.168.24.0/22 dev net1 scope link src 192.168.25.62
References
- 为基于 VM 的 Oracle Container Engine for Kubernetes 节点使用 Multus 为 pod 配置 SR-IOV 接口
- [ Could not assign static IP to pod with Multus plugin #684 ](https://github.com/k8snetworkplumbingwg/multus-cni/issues/684
- [static IP address management plugin](https://www.cni.dev/plugins/current/ipam/static/
- [Use a specific IP address with a pod](https://docs.tigera.io/calico/latest/networking/ipam/use-specific-ip
- Could not assign static IP to pod with Multus plugin #684
- Container v1 core - Kuberentes API
1 条评论
虫洞来的,留个名儿~