gpt4 book ai didi

jenkins - docker build使用jenkins dind slave + kubernetes插件抛出java.net.AbstractPlainSocketImpl.connect UnknownHostException

转载 作者:行者123 更新时间:2023-12-02 11:56:41 25 4
gpt4 key购买 nike

因此,Jenkins使用此official helm chart安装在集群内部。这是我根据 Helm 发布值安装的插件:

  installPlugins:
- kubernetes:1.18.1
- workflow-job:2.33
- workflow-aggregator:2.6
- credentials-binding:1.19
- git:3.11.0
- blueocean:1.19.0

我的Jenkinsfile依靠以下pod模板启动奴隶:
kind: Pod
spec:
# dnsConfig:
# options:
# - name: ndots
# value: "1"
containers:
- name: dind
image: docker:19-dind
command:
- cat
tty: true
volumeMounts:
- name: dockersock
readOnly: true
mountPath: /var/run/docker.sock
resources:
limits:
cpu: 500m
memory: 512Mi
volumes:
- name: dockersock
hostPath:
path: /var/run/docker.sock

只要有新的Build,从站(pod / dind容器)就会按预期启动。

但是,它在(Jenkinsfile流水线
docker build -t ...)并在此处中断:
Step 16/24 : RUN      ../gradlew clean bootJar

---> Running in f14b6418b3dd

Downloading https://services.gradle.org/distributions/gradle-5.5-all.zip


Exception in thread "main" java.net.UnknownHostException: services.gradle.org

at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:220)

at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:403)

at java.base/java.net.Socket.connect(Socket.java:591)

at java.base/sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:285)

at java.base/sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:173)

at java.base/sun.net.NetworkClient.doConnect(NetworkClient.java:182)

at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:474)

at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:569)

at java.base/sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:265)

at java.base/sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:372)

at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)

at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1187)

at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1081)

at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)

at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1587)

at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1515)

at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:250)

at org.gradle.wrapper.Download.downloadInternal(Download.java:67)

at org.gradle.wrapper.Download.download(Download.java:52)

at org.gradle.wrapper.Install$1.call(Install.java:62)

at org.gradle.wrapper.Install$1.call(Install.java:48)

at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:69)

at org.gradle.wrapper.Install.createDist(Install.java:48)

at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:107)

at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:63)

The command '/bin/sh -c ../gradlew clean bootJar' returned a non-zero code:

乍一看,我认为这是从属容器( docker:19-dind)的DNS解析问题,因为它是 Alpine 的。
这就是为什么我通过在Jenkinsfile中添加 /etc/resolv.conf来调试其 sh "cat /etc/resolv.conf"的原因。

我有 :
nameserver 172.20.0.10
search cicd.svc.cluster.local svc.cluster.local cluster.local ap-southeast-1.compute.internal
options ndots:5

根据互联网上许多线程的建议,我删除了最后一行 options ndots:5

但这不能解决问题。 😔

我一再思考,我意识到造成此错误的容器不是Slave(docker:19-dind),而是打开了满足 docker build的中间容器。

结果,我将 RUN cat /etc/resolv.conf作为Dockerfile的另一层添加(以 FROM gradle:5.5-jdk11开头)。

现在, resolv.conf是不同的:
Step 15/24 : RUN cat /etc/resolv.conf

---> Running in 91377c9dd519

; generated by /usr/sbin/dhclient-script

search ap-southeast-1.compute.internal

options timeout:2 attempts:5

nameserver 10.0.0.2

Removing intermediate container 91377c9dd519

---> abf33839df9a

Step 16/24 : RUN ../gradlew clean bootJar

---> Running in f14b6418b3dd

Downloading https://services.gradle.org/distributions/gradle-5.5-all.zip

Exception in thread "main" java.net.UnknownHostException: services.gradle.org

基本上,它是与从属容器 10.0.0.2的名称服务器不同的名称服务器 172.20.0.10。此中间容器的resolv.conf中没有 ndots:5

经过所有这些调试步骤和许多尝试后,我感到困惑。

建筑
Jenkins Server (Container )
||
(spin up slaves)
||__ SlaveA (Container, image: docker:19-dind)
||
( run "docker build" )
||
||_ intermediate (container, image: gradle:5.5-jdk11 )

最佳答案

只需将--network=host添加到docker builddocker run即可。

 docker build --network=host foo/bar:latest .

找到了答案 here

关于jenkins - docker build使用jenkins dind slave + kubernetes插件抛出java.net.AbstractPlainSocketImpl.connect UnknownHostException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57883269/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com