如何修复kubernetes中的dockernetworking?

我有一个kubernetes集群,并使用jenkins

pipe道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}") } } } 

当我在新build(创build)容器不工作的networking中运行“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的荚一切工作。

我该如何解决这个问题?

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

这是我的主机输出。

 # 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