Jenkins Master运行在Kubernetes集群的一个node上,并且数据存储到volume上去,Jenkins Slave会按照需求动态的创建并且自动删除。

部署
首先需要nfs storageclass动态创建pv,参考这篇文章:https://1335402049.github.io/2020/09/16/Kubernetes%E4%B8%AD%E4%BD%BF%E7%94%A8NFS%E7%9A%84StorageClass/
应用 namespace
应用 rbac
apiVersion: v1 kind: ServiceAccount metadata: name: jenkins-sa namespace: devops --- apiVersion: rbac.authorization.k8s.io/v1beta1 kind: ClusterRoleBinding metadata: name: jenkins-crd roleRef: kind: ClusterRole name: cluster-admin apiGroup: rbac.authorization.k8s.io subjects: - kind: ServiceAccount name: jenkins-sa namespace: devops
|
应用 pvc
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: jenkins-pvc namespace: devops annotations: volume.beta.kubernetes.io/storage-class: "managed-nfs-storage" spec: volumeMode: Filesystem accessModes: - ReadWriteMany resources: requests: storage: 3Gi
|
应用 deployment
apiVersion: apps/v1 kind: Deployment metadata: name: jenkins namespace: devops spec: replicas: 1 selector: matchLabels: app: jenkins template: metadata: labels: app: jenkins spec: terminationGracePeriodSeconds: 10 serviceAccountName: jenkins-sa containers: - name: jenkins image: jenkins/jenkins:lts imagePullPolicy: IfNotPresent env: - name: JAVA_OPTS value: -XshowSettings:vm -Dhudson.slaves.NodeProvisioner.initialDelay=0 -Dhudson.slaves.NodeProvisioner.MARGIN=50 -Dhudson.slaves.NodeProvisioner.MARGIN0=0.85 -Duser.timezone=Asia/Shanghai ports: - name: web containerPort: 8080 protocol: TCP - name: agent containerPort: 50000 protocol: TCP resources: limits: cpu: 1000m memory: 1Gi requests: cpu: 500m memory: 512Mi livenessProbe: httpGet: path: /login port: 8080 initialDelaySeconds: 60 timeoutSeconds: 5 failureThreshold: 12 readinessProbe: httpGet: path: /login port: 8080 initialDelaySeconds: 60 timeoutSeconds: 5 failureThreshold: 12 volumeMounts: - name: jenkinshome mountPath: /var/jenkins_home volumes: - name: jenkinshome persistentVolumeClaim: claimName: jenkins-pvc
|
应用 svc
apiVersion: v1 kind: Service metadata: name: jenkins namespace: devops labels: app: jenkins spec: selector: app: jenkins type: NodePort ports: - name: web port: 8080 targetPort: web nodePort: 30002 - name: agent port: 50000 targetPort: agent
|
登录
通过node:NodePort登录jenkins
密码可以通过 cat /nfs/devops-jenkins-pvc-pvc-14c9df34-833b-47ce-b423-45b16a66b9b6/secrets/initialAdminPassword 查看
