簡體   English   中英

Docker Swarm 工作節點未訪問互聯網

[英]Docker Swarm worker node not accessing the internet

按照官方教程,我有一個由 1 個經理和 1 個工人組成的群體,每個人都在不同的主機上。 我也使用 Traefik,按照dockerswarm.rocks上的這些說明,使用簡單的覆蓋網絡創建:

docker network create --driver=overlay traefik-public

現在我部署了我的一個服務,它必須訪問 Internet。

雖然這在服務部署在管理節點上時效果很好,但在工作節點上卻失敗了。

docker-compose.yml

version: '3.5'
services:
  export-phyc:
    image: my.docker.registry/my/image
    networks:
      - traefik-public
    deploy:
      labels:
        - traefik.enable=true
        - traefik.docker.network=traefik-public
        - traefik.constraint-label=traefik-public
        - traefik.http.routers.myservice-http.rule=Host(`my.domain`)
        - traefik.http.routers.myservice-http.entrypoints=http
        - traefik.http.routers.myservice-http.middlewares=https-redirect
        - traefik.http.routers.myservice-https.rule=Host(`my.domain`)
        - traefik.http.routers.myservice-https.entrypoints=https
        - traefik.http.routers.myservice-https.tls=true
        - traefik.http.routers.myservice-https.tls.certresolver=le
        - traefik.http.services.myservice.loadbalancer.server.port=80    
networks:
  traefik-public:
    external: true

兩台主機具有相同的 DNS 配置:

# cat /etc/resolv.conf
domain openstacklocal
search openstacklocal
nameserver 213.186.xx.xx

這兩個任務也具有相同的 DNS 配置(但與主機不同):

# docker container exec <my-container-id> cat /etc/resolv.conf
search openstacklocal
nameserver 127.0.0.xx
options ndots:0

然而,管理器上的任務可以到達互聯網:

# docker container exec <my-container-id> wget google.com
Connecting to google.com (216.58.215.46:80)
Connecting to www.google.com (216.58.206.228:80)
saving to 'index.html'
index.html           100% |********************************| 13848  0:00:00 ETA
'index.html' saved

工人的任務不能:

# docker container exec <my-container-id> wget google.com
wget: bad address 'google.com'
# docker container exec <my-container-id> wget 216.58.204.142
Connecting to 216.58.204.142 (216.58.204.142:80)
wget: can't connect to remote host (216.58.204.142): Operation timed out

我最困惑。 如何讓我的工作節點上的任務訪問互聯網?

所以問題在於我的防火牆(iptables)弄亂了 Docker 設置的規則。 我確實需要實現自己的規則(在重新啟動時啟動),並且 Docker 必須設置其內部通信規則(每次 docker 守護程序重新啟動時設置)。

我不是 iptables 的鑒賞家,我只是得到了一個應該可以很好地處理 Docker Swarm,但其中缺少一行:

-A DOCKER-USER -j RETURN

iptables 規則示例:

*filter
:INPUT ACCEPT [0:0]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [0:0]
:FILTERS - [0:0]
:DOCKER-USER - [0:0]

-F INPUT
-F DOCKER-USER
-F FILTERS

-A INPUT -i lo -j ACCEPT
-A INPUT -j FILTERS

-A DOCKER-USER -i eno1 -j FILTERS
-A DOCKER-USER -j RETURN

-A FILTERS -m state --state ESTABLISHED,RELATED -j ACCEPT

#allow 80 and 443
-A FILTERS -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A FILTERS -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT

###### System

# Allow SSH connections
-A FILTERS -p tcp --dport 22 -j ACCEPT

# Docker SWARM cluster connections
-A FILTERS -p tcp --dport 2377 -j ACCEPT
-A FILTERS -p tcp --dport 7946 -j ACCEPT
-A FILTERS -p udp --dport 7946 -j ACCEPT
-A FILTERS -p udp --dport 4789 -j ACCEPT

###### Rules home

# ...

###### end

-A FILTERS -j REJECT --reject-with icmp-host-prohibited

COMMIT

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM