0
点赞
收藏
分享

微信扫一扫

k8s中pod添加多网卡实现组播通信

八怪不姓丑 2024-05-29 阅读 8

项目中需要实现udp组播通信,查询StackOverflow得出解决方案: image.png 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 image.png 然后创建一个类型是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

image.png

在原来的pod配置中加入 annotations: k8s.v1.cni.cncf.io/networks: macvlan-conf image.png 应用配置后pod里多了一张net1的网卡 image.png 查看pod之间udp组播通信 image.png image.png 成功

举报

相关推荐

K8s Pod 进阶

Kubernetes(K8s) pod

【k8s】pod进阶

k8s 终止pod

k8s中实现pod自动扩缩容

0 条评论