jenkins交付到k8s集群后,jenkins第一次构建dubbo提供者时,报错:
+ docker build -t harbor.od.com/app/dubbo-demo-service:master_200502_1625 . Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
反复多次构建,还会报如下错误,大体意思和上面的报错差不多:
+ docker build -t harbor.od.com/app/dubbo-demo-service:master_200503_0948 . time="2020-05-03T10:51:12+08:00" level=error msg="failed to dial gRPC: cannot connect to the Docker daemon. Is 'docker daemon' running on this host?: dial unix /var/run/docker.sock: connect: connection refused" Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
百度上的答案,都是重启docker。
由于jenkins pod运行在10.4.7.21上,我重启过这个节点的docker;由于docker push可能用到10.4.7.200,也重启过10.4.7.200。但是,都不管用。
在王导k8s答疑群把问题发出来后,有学员给出的建议是重新build一次jenkins镜像。
检查Dockerfile文件:
因为另1个Dockerfile是用于jenkins 2.176.2使用的。
[root@hdss7-200 jenkins]# pwd /data/dockerfile/jenkins [root@hdss7-200 jenkins]# ll -trh total 944M -rw-r--r-- 1 root root 944M Nov 18 18:19 jenkins-v2.176.2-with-docker.tar -rw------- 1 root root 151 Apr 21 13:52 config.json -rw------- 1 root root 1.7K Apr 21 13:54 id_rsa -rwxr-xr-x 1 root root 14K Apr 21 14:00 get-docker.sh -rw-r--r-- 1 root root 350 Apr 29 10:03 Dockerfile -rw-r--r-- 1 root root 317 Apr 29 10:05 Dockerfile.ori.176 [root@hdss7-200 jenkins]# cat Dockerfile FROM harbor.od.com/public/jenkins:v2.190.3 USER root RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime &&\ echo 'Asia/Shanghai' >/etc/timezone ADD id_rsa /root/.ssh/id_rsa ADD config.json /root/.docker/config.json ADD get-docker.sh /get-docker.sh RUN echo " StrictHostKeyChecking no" >> /etc/ssh/ssh_config &&\ /get-docker.sh
build镜像:
[root@hdss7-200 jenkins]# docker build . -t harbor.od.com/infra/jenkins:v2.190.3.20200503 Sending build context to Docker daemon 989.4MB Step 1/7 : FROM harbor.od.com/public/jenkins:v2.190.3 ---> 22b8b9a84dbe Step 2/7 : USER root ---> Using cache ---> f6345f239a6e Step 3/7 : RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone ---> Using cache ---> 9f3ee3ebf906 Step 4/7 : ADD id_rsa /root/.ssh/id_rsa ---> Using cache ---> 1274c52edb35 Step 5/7 : ADD config.json /root/.docker/config.json ---> Using cache ---> 69062560cff7 Step 6/7 : ADD get-docker.sh /get-docker.sh ---> Using cache ---> bf20ac214571 Step 7/7 : RUN echo " StrictHostKeyChecking no" >> /etc/ssh/ssh_config && /get-docker.sh ---> Using cache ---> 999989cba3be Successfully built 999989cba3be Successfully tagged harbor.od.com/infra/jenkins:v2.190.3.20200503
推送jenkins镜像到harbor仓库:
[root@hdss7-200 jenkins]# docker push harbor.od.com/infra/jenkins:v2.190.3.20200503 The push refers to repository [harbor.od.com/infra/jenkins] 6e27d031df7b: Layer already exists 004f4ad25d03: Layer already exists 45774a545354: Layer already exists fa272cd168be: Layer already exists 8542480a9979: Layer already exists e0485b038afa: Layer already exists 2950fdd45d03: Layer already exists cfc53f61da25: Layer already exists 29c489ae7aae: Layer already exists 473b7de94ea9: Layer already exists 6ce697717948: Layer already exists 0fb3a3c5199f: Layer already exists 23257f20fce5: Layer already exists b48320151ebb: Layer already exists 911119b5424d: Layer already exists 5051dc7ca502: Layer already exists a8902d6047fe: Layer already exists 99557920a7c5: Layer already exists 7e3c900343d0: Layer already exists b8f8aeff56a8: Layer already exists 687890749166: Layer already exists 2f77733e9824: Layer already exists 97041f29baff: Layer already exists v2.190.3.20200503: digest: sha256:a95ec23858fc06813b71ff6a874cc9e97729c4f61bca62a2086b75d8b596f3ed size: 5130
修改资源配置清单:
[root@hdss7-200 jenkins]# cd /data/k8s-yaml/jenkins/ [root@hdss7-200 jenkins]# cat dp.yaml kind: Deployment apiVersion: extensions/v1beta1 metadata: name: jenkins namespace: infra labels: name: jenkins spec: replicas: 1 selector: matchLabels: name: jenkins template: metadata: labels: app: jenkins name: jenkins spec: volumes: - name: data nfs: server: hdss7-200 path: /data/nfs-volume/jenkins_home - name: docker hostPath: path: /run/docker.sock type: '' containers: - name: jenkins image: harbor.od.com/infra/jenkins:v2.190.3.20200503 imagePullPolicy: IfNotPresent ports: - containerPort: 8080 protocol: TCP env: - name: JAVA_OPTS value: -Xmx512m -Xms512m volumeMounts: - name: data mountPath: /var/jenkins_home - name: docker mountPath: /run/docker.sock imagePullSecrets: - name: harbor securityContext: runAsUser: 0 strategy: type: RollingUpdate rollingUpdate: maxUnavailable: 1 maxSurge: 1 revisionHistoryLimit: 7 progressDeadlineSeconds: 600
任意k8s集群节点应用资源配置清单:
[root@hdss7-21 ~]# kubectl apply -f http://k8s-yaml.od.com/jenkins/dp.yaml deployment.extensions/jenkins configured
dashboard的jenkins pod已经启动:之前jenkins运行在10.4.7.21,现在被调度到10.4.7.22
即使在k8s里的jenkins pod已经启动,但是,浏览器上的web界面能够恢复打开,还是需要等待一段时间。
重新构建后:
出问题的地方已经通过:
构建成功:
学员帮我分析的原因:
因为原来那个镜像的socket文件是有问题的,所以需要重新构建。
感谢老男孩的王导k8s容器云课程。