1.新建job git下载 maven编译 上传镜像到私库

主要脚本:

#!/bin/sh
cat>Dockerfile<<EOF
FROM openjdk:8-jdk-alpine
RUN mkdir -p /data/ld-business-map/ld-business-map/lib /data/ld-business-map/ld-business-map/logs /data/ld-business-map/ld-business-map/config /data/ld-business-map/ld-business-map/bin /data/ops_script/
COPY ld-map-gis/ld-gis-provider/target/*.jar /data/ld-business-map/ld-business-map/lib/
COPY ld-map-gis/ld-gis-provider/target/lib/*.jar /data/ld-business-map/ld-business-map/lib/
COPY ./endpoint.sh /data/ld-business-map/ld-business-map/bin/
STOPSIGNAL SIGTERM
WORKDIR /data/ld-business-map/ld-business-map/
CMD [ "sh","/data/ld-business-map/ld-business-map/bin/endpoint.sh"]
EOF
cat>endpoint.sh<<EOF
#!/bin/sh
###Java进程启动脚本

        java -Djava.ext.dirs=/opt/java/openjdk/jre/lib/ext:lib         -XX:-UseGCOverheadLimit         -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=dump.bin         -verbose:gc -Xloggc:jvm-gc.log -XX:+PrintGCDateStamps -XX:+PrintGCDetails         -Dapollo.meta=http://apollo.test.xxxx.com:8071         -Denv=FAT         -Dapp.id=map-research-api         -Dapollo.bootstrap.enabled=true         -jar /data/ld-business-map/ld-business-map/lib/ld-gis-provider.jar
EOF
docker build -t feilong2483/map:latest .
docker login -u feilong2483 -p *********
docker push feilong2483/map:latest

上传成功截图

2. 详解jenkins部署文件

  apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: jenkins
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: jenkins
      template:
        metadata:
          labels:
            app: jenkins
        spec:
          nodeName: svn
          containers:
          - name: jenkins
            image: jenkins/jenkins:latest
            ports:
            - containerPort: 8080
              name: web
              protocol: TCP
            - containerPort: 50000
              name: agent
              protocol: TCP
            volumeMounts:
              - name: jenkins-home
                mountPath: /var/jenkins_home
              - name: docker
                mountPath: /var/run/docker.sock
              - name: dockerbin
                mountPath: /usr/bin/docker
              - name: libso
                mountPath: /usr/lib/x86_64-linux-gnu/libltdl.so.7
          volumes:
            - name: jenkins-home
              hostPath:
                path: /var/jenkins_home
            - name: dockerbin
              hostPath:
                path: /usr/bin/docker

           - name: libso
              hostPath:
                path: /usr/lib64/libltdl.so.7
            - name: docker
              hostPath:
                path: /var/run/docker.sock

3.遇到问题解决

a.  jenkins挂载目录权限不够 

解决命令:chmod 777 jenkins_home/

b.  docker not found

部署文件加入:

挂载路径: /var/run/docker.sock 和  /usr/bin/docker

c.  docker: error while loading shared libraries: libltdl.so.7: cannot open shared object file: No such file or directory

挂载路径: /usr/lib64/libltdl.so.7

d. Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock:

chmod 777 /var/run/docker.sock

e.jenks时区不对,容器时间与宿主机相差8小时,jenkins界面修改

system.setProperty('org.apache.commons.jelly.tags.fmt.timeZone', 'Asia/Shanghai')

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐