解决 docker swarm 节点容器无法获取客户端真实IP

下载工具

https://github.com/sangbobo/docker-ingress-routing-daemon

下载代码

将docker-ingress-routing-daemon放到/usr/bin下

bash 复制代码
mv docker-ingress-routing-daemon
chmod +x docker-ingress-routing-daemon

设置开启自启

bash 复制代码
vi /etc/systemd/system/dird.service

填入内容

bash 复制代码
[Unit]
Description=Docker Ingress Routing Daemon
After=sysinit.target dockerd.service
StartLimitIntervalSec=0

[Service]
ExecStart=/usr/bin/docker-ingress-routing-daemon --install --preexisting --ingress-gateway-ips "10.0.0.2 10.0.0.3 10.0.0.4 10.0.0.5 10.0.0.6 10.0.0.7 10.0.0.8 10.0.0.9"
Restart=always

[Install]
WantedBy=multi-user.target

开机自启

bash 复制代码
systemctl enable dird

启动

bash 复制代码
systemctl start dird

其他

1、正常在swarm有主节点和多个子节点,需要在每个主节点和子节点上都运行以上操作

2、--ingress-gateway-ips 后面的ip列表需要涵盖所有主节点和子节点的ip

可以直接运行

bash 复制代码
docker-ingress-routing-daemon

命令查看当前节点的IP,在主机上运行以上命令得到

bash 复制代码
Docker Ingress Routing Daemon v4.2.0

Usage: /usr/bin/docker-ingress-routing-daemon [--install [OPTIONS] | --uninstall | --help]

         --services <services>   - service names to whitelist (i.e. disable masquerading for)
           --tcp-ports <ports>   - TCP ports to whitelist (i.e. disable masquerading for)
           --udp-ports <ports>   - UDP ports to whitelist (i.e. disable masquerading for)
   --ingress-gateway-ips <ips>   - specify load-balancer ingress IPs
                 --preexisting   - optionally install rules where needed
                                   on preexisting containers (recommended)

               --iptables-wait   - pass '--wait' option to iptables
   --iptables-wait-seconds <n>   - pass '--wait <n>' option to iptables

              --no-performance   - disable performance optimisations
                 --indexed-ids   - use sequential ids for load balancers
                                   (forced where ingress subnet larger than /24)

Notes:
- <services>, <ports> and <ips> may be comma-separated, space-separated,
  or the relevant option specified multiple times;
- an IP of 'null' will be skipped, allowing old IPs to be retired without
  changing the indexes of serving IPs.

Detected ingress subnet and node IP:
- Ingress subnet: 10.0.0.0/24
- This node's ingress network IP: 10.0.0.2

This node's ingress network IP: 10.0.0.2

这里的内容就是当前节点的ip,收集所有ip后,填入到--ingress-gateway-ips后的ip集合中

参考

https://github.com/newsnowlabs/docker-ingress-routing-daemon

https://github.com/moby/moby/issues/25526

https://eyehere.net/2019/在docker-swarm-mode中获得真实的客户ip/

相关推荐
martian6654 小时前
大模型部署:AI大模型在医学影像分类中的ONNX、TensorRT和Docker应用
人工智能·docker·分类·ai大模型·hugging face
007php0077 小时前
使用 Docker、Jenkins、Harbor 和 GitLab 构建 CI/CD 流水线
数据库·ci/cd·docker·容器·golang·gitlab·jenkins
退役小学生呀11 小时前
十九、云原生分布式存储 CubeFS
分布式·docker·云原生·容器·kubernetes·k8s
deeper_wind15 小时前
k8s-容器化部署论坛和商城服务(小白的“升级打怪”成长之路)
linux·运维·容器·kubernetes
UtopianCoding15 小时前
MinerU:重新定义PDF智能提取的开源利器
docker·pdf·开源
wdxylb16 小时前
云原生俱乐部-k8s知识点归纳(8)
云原生·容器·kubernetes
007php00718 小时前
Jenkins+docker 微服务实现自动化部署安装和部署过程
运维·数据库·git·docker·微服务·自动化·jenkins
hello_ world.19 小时前
k8s笔记04-常用部署命令
笔记·容器·kubernetes
{⌐■_■}21 小时前
【ElasticSearch】使用docker compose,通过编写yml安装es8.15和kibana可视化界面操作,go连接es
elasticsearch·docker·golang
dxt_snow21 小时前
docker在自定义网络中安装ElasticSearch和Kibana
网络·elasticsearch·docker