安装socat

网络允许的话,可以使用yum install -y socat进行安装。

如果是在容器里面运行,建议使用静态链接的socat:

可以从此处下载: Release socat-v1.7.4.4 · ernw/static-toolbox · GitHub

确定网络接口地址和组播地址

#kubectl exec -it pod-node2 -- ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:00:00:F6:DE:E2
          inet addr:101.16.0.118  Bcast:101.16.255.255  Mask:255.255.0.0
          inet6 addr: fe80::200:ff:fef6:dee2/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1400  Metric:1
          RX packets:117 errors:0 dropped:0 overruns:0 frame:0
          TX packets:74 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:8063 (7.8 KiB)  TX bytes:4308 (4.2 KiB)


#kubectl exec -it pod-node3 -- ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:00:00:60:52:4B
          inet addr:101.16.0.119  Bcast:101.16.255.255  Mask:255.255.0.0
          inet6 addr: fe80::200:ff:fe60:524b/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1400  Metric:1
          RX packets:118 errors:0 dropped:0 overruns:0 frame:0
          TX packets:50 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:8090 (7.9 KiB)  TX bytes:2925 (2.8 KiB)

验证组播multicast

server侧运行命令行:

kubectl exec -it pod-node2 -- /usr/bin/socat-1.7.4.4-x86_64 -d UDP4-RECVFROM:6666,ip-add-membership=224.1.0.1:101.16.0.118,fork EXEC:hostname

client侧运行命令行:

kubectl exec -it pod-node3 -- /usr/bin/socat-1.7.4.4-x86_64 STDIO UDP4-DATAGRAM:224.1.0.1:6666,range=101.16.0.119/24

ip地址和rang需要从ifconfig命令中获取

实机运行效果

验证广播broadcast

server侧运行命令行:

kubectl exec -it pod-node2 -- /usr/bin/socat-1.7.4.4-x86_64 -dd UDP4-RECVFROM:6666,broadcast,fork EXEC:hostname

client侧运行命令行:

kubectl exec -it pod-node3 -- /usr/bin/socat-1.7.4.4-x86_64 -dd STDIO UDP4-DATAGRAM:101.16.255.255:6666,broadcast,range=101.16.0.119/16

ip地址和rang需要从ifconfig命令中获取

实机运行效果

server

client

官方操作文档

IP Multicasting with Socat

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐