【问题标题】:How can I fix network for docker in kubernetes?如何在 Kubernetes 中为 docker 修复网络?
【发布时间】:2017-12-06 18:34:59
【问题描述】:

我有一个 kubernetes 集群并使用 Jenkins

管道詹金斯:

podTemplate(label: 'pod-golang', containers: [
    containerTemplate(name: 'golang', image: 'golang:latest', ttyEnabled: true, command: 'cat'),
    containerTemplate(name: 'docker', image: 'docker:17.11-dind', ttyEnabled: true, command: 'cat'),
  ],
  volumes: [hostPathVolume(hostPath: '/var/run/docker.sock', mountPath: '/var/run/docker.sock')]
) {
    node('pod-golang') {
        def app
        String applicationName = "auth"
        String buildNumber = "0.1.${env.BUILD_NUMBER}"

        stage 'Checkout'
            checkout scm
        container('docker') {
            stage 'Create docker image'
                app = docker.build("test/${applicationName}")
        }
    }
}

当我在新的(正在创建的)容器中运行“docker build”命令时网络不工作:

Step 1/6 : FROM alpine:latest
 ---> e21c333399e0
Step 2/6 : RUN apk --no-cache add ca-certificates
 ---> Running in 8483bb918ee8
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/community/x86_64/APKINDEX.tar.gz
[91mWARNING: Ignoring http://dl-cdn.alpinelinux.org/alpine/v3.7/main/x86_64/APKINDEX.tar.gz: operation timed out
[0mEXITCODE   0[91mWARNING: Ignoring http://dl-cdn.alpinelinux.org/alpine/v3.7/community/x86_64/APKINDEX.tar.gz: operation timed out

如果我在我看到的主机上使用“docker run”命令,它在“手动”启动的 docker 映像中无法正常工作网络:

root@node2:~/tmp# docker run --rm -it alpine ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes
^C
--- 8.8.8.8 ping statistics ---
14 packets transmitted, 0 packets received, 100% packet loss
root@node2:~/tmp# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=57 time=12.9 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=57 time=12.9 ms
^C
--- 8.8.8.8 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 12.927/12.943/12.960/0.114 ms

但是当我使用 kubectl 的 pod 时,一切正常。

我该如何解决这个问题?

【问题讨论】:

  • 你的 docker 网络配置是什么 `docker info |grep -i network` 给我Network: bridge host macvlan null overlay ping 我的主机。
  • @sfgroups 我看到网络:在主机上运行 docker info 后桥接主机 macvlan null 覆盖
  • 好的,我们可以看到流量正在流出您的服务器。

标签: docker jenkins kubernetes jenkins-plugins jenkins-pipeline


【解决方案1】:

打开另一个窗口运行tcpdump -vvv host 8.8.8.8 命令查看流量。

这是我的主机输出。

# tcpdump -vvv host 8.8.8.8
tcpdump: listening on enp0s3, link-type EN10MB (Ethernet), capture size 262144 bytes
18:36:35.142633 IP (tos 0x0, ttl 63, id 2091, offset 0, flags [DF], proto ICMP (1), length 84)
    webserver > google-public-dns-a.google.com: ICMP echo request, id 256, seq 0, length 64
18:36:35.170475 IP (tos 0x0, ttl 55, id 18270, offset 0, flags [none], proto ICMP (1), length 84)
    google-public-dns-a.google.com > webserver: ICMP echo reply, id 256, seq 0, length 64
18:36:36.146145 IP (tos 0x0, ttl 63, id 2180, offset 0, flags [DF], proto ICMP (1), length 84)
    webserver > google-public-dns-a.google.com: ICMP echo request, id 256, seq 1, length 64

# docker run --rm -it alpine ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes
64 bytes from 8.8.8.8: seq=0 ttl=54 time=30.720 ms
64 bytes from 8.8.8.8: seq=1 ttl=54 time=25.576 ms
64 bytes from 8.8.8.8: seq=2 ttl=54 time=28.464 ms
64 bytes from 8.8.8.8: seq=3 ttl=54 time=33.860 ms
64 bytes from 8.8.8.8: seq=4 ttl=54 time=25.525 ms

【讨论】:

  • 我看到了:22:52:19.370727 IP (tos 0x0, ttl 63, id 58429, offset 0, flags [DF], proto ICMP (1), length 84) 172.17.0.2 > google-public-dns-a.google.com: ICMP echo request, id 256, seq 0, length 644 packets transmitted, 0 packets received, 100% packet loss
  • 从输出我看到请求出去了,它没有回到服务器。可能是您的路由器丢弃了数据包。
  • 如何查看? ip add in this "docker image(build)" 172.17... 但在其他 docker contains(from kubernetes) 10.230...
  • 你可以从输出网关使用ip route get 8.8.8.8命令将通过8.8.8.8 via 10.0.2.2 dev eth0 src 10.0.2.15后的ip
  • 那么你需要检查路由器是否有丢包。还可以看到您有任何 iptables 规则阻止 icmp 回复。
猜你喜欢
  • 2019-06-07
  • 2022-01-03
  • 1970-01-01
  • 1970-01-01
  • 2018-08-27
  • 1970-01-01
  • 2020-01-21
  • 1970-01-01
  • 2019-05-04
相关资源
最近更新 更多