jenkins 部署到k8s中使用宿主机Docker及kubectl的配置方式记录
# jenkins使用官方yaml部署,记录在jenkins 容器中调用主机Docker 进行build
# 由于maven编译需要jdk,在jenkins中可以配置oracle账号选择jdk版本自动下载,但oracle网站有时不稳定造成jdk无法下载,所以以下为离线jdk部署方式 # 离线配置jdk方式:下载jdk包并解压到/mnt/data/jenkins_home/tools/hudson.model.JDK/jdk8/目录下,在jenkins中配置jdk相对路径/var/jenkins_home/tools/hudson.model.JDK/jdk8/jdk1.8.0_221(jdk8后面路径要和解压后的jdk路径一致) # jenkins使用主机vm docker时需要挂载宿主机docker的几个路径并设置宿主机docker.sock权限:chmod 777 /var/run/docker.sock
--- apiVersion: apps/v1 kind: StatefulSet metadata: namespace: monitor-app name: jenkins labels: name: jenkins spec: selector: matchLabels: name: jenkins serviceName: jenkins replicas: 1 updateStrategy: type: RollingUpdate template: metadata: name: jenkins labels: name: jenkins spec: terminationGracePeriodSeconds: 10 serviceAccountName: jenkins nodeSelector: jtype: jenkins containers: - name: jenkins command: - /sbin/tini - /usr/local/bin/jenkins.sh - --prefix=/jenkins image: jenkins/jenkins:lts-alpine imagePullPolicy: IfNotPresent ports: - containerPort: 8080 - containerPort: 50000 resources: limits: cpu: 1 memory: 2Gi requests: cpu: 0.5 memory: 500Mi env: - name: LIMITS_MEMORY valueFrom: resourceFieldRef: resource: limits.memory divisor: 1Mi - name: JAVA_OPTS # value: -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -XX:MaxRAMFraction=1 -XshowSettings:vm -Dhudson.slaves.NodeProvisioner.initialDelay=0 -Dhudson.slaves.NodeProvisioner.MARGIN=50 -Dhudson.slaves.NodeProvisioner.MARGIN0=0.85 value: -Xmx$(LIMITS_MEMORY)m -XshowSettings:vm -Dhudson.slaves.NodeProvisioner.initialDelay=0 -Dhudson.slaves.NodeProvisioner.MARGIN=50 -Dhudson.slaves.NodeProvisioner.MARGIN0=0.85 -D--prefix=/jenkins volumeMounts: - name: jenkins-home mountPath: /var/jenkins_home # - name: docker # mountPath: /usr/bin/docker # - name: docker-sock # mountPath: /var/run/docker.sock # - name: docker-login # mountPath: /root/.docker/config.json #将docker登录信息挂载到容器中 livenessProbe: httpGet: path: /jenkins/login port: 8080 initialDelaySeconds: 60 timeoutSeconds: 5 failureThreshold: 12 # ~2 minutes readinessProbe: httpGet: path: /jenkins/login port: 8080 initialDelaySeconds: 60 timeoutSeconds: 5 failureThreshold: 12 securityContext: fsGroup: 1000 volumes: - name: jenkins-home hostPath: path: /mnt/data/jenkins # - name: docker # hostPath: # path: /usr/bin/docker # - name: docker-sock # hostPath: # path: /var/run/docker.sock # - hostPath: # path: /root/.docker/config.json # name: docker-login
# - hostPath:
# path: /usr/bin/kubectl
# name: kubectl
--- apiVersion: v1 kind: Service metadata: name: jenkins namespace: monitor-app spec: selector: name: jenkins ports: - name: http port: 8066 targetPort: 8080 protocol: TCP - name: agent port: 50000 protocol: TCP