项目中需要实现udp组播通信,查询StackOverflow得出解决方案:
StackOverflow链接
经测试两种模式都可以实现pod间组播通信
第一种在pod配置中只用添加hostNetwork: true就可以了
这里主要记录一下第二种如何实现
官方链接
根据官方的操作指南来,首先是创建一个daemonset来安装cni插件,这个插件可以兼容已有的cni插件
kubectl apply -f https://raw.githubusercontent.com/k8snetworkplumbingwg/multus-cni/master/deployments/multus-daemonset-thick.yml
里面的镜像是ghcr.io/k8snetworkplumbingwg/multus-cni:snapshot-thick,如果官方仓库拉不下来就想其他办法
然后创建后会多一个daemonset
然后创建一个类型是NetworkAttachmentDefinition的资源,注意我们这里的配置类型是macvlan
apiVersion: "k8s.cni.cncf.io/v1"
kind: NetworkAttachmentDefinition
metadata:
name: macvlan-conf
spec:
config: '{
"cniVersion": "0.3.0",
"type": "macvlan",
"master": "eth0",
"mode": "bridge",
"ipam": {
"type": "host-local",
"subnet": "192.168.1.0/24",
"rangeStart": "192.168.1.200",
"rangeEnd": "192.168.1.216",
"routes": [
{ "dst": "0.0.0.0/0" }
],
"gateway": "192.168.1.1"
}
}'
然后
kubectl apply -f nad.yaml
在原来的pod配置中加入
annotations:
k8s.v1.cni.cncf.io/networks: macvlan-conf
应用配置后pod里多了一张net1的网卡
查看pod之间udp组播通信
成功