From a256139b49d6dda3482037238a94eabf61b7779d Mon Sep 17 00:00:00 2001 From: ycz008 Date: Thu, 25 May 2023 16:28:06 +0800 Subject: [PATCH] add jenkins basic deployment --- jenkins-k8s/deployment-basic.yaml | 158 ++++++++++++++++++ ...{deployment.yaml => deployment-comon.yaml} | 131 +++++++++------ jenkins-k8s/serviceAccount.yaml | 30 ---- 3 files changed, 241 insertions(+), 78 deletions(-) create mode 100644 jenkins-k8s/deployment-basic.yaml rename jenkins-k8s/{deployment.yaml => deployment-comon.yaml} (82%) delete mode 100644 jenkins-k8s/serviceAccount.yaml diff --git a/jenkins-k8s/deployment-basic.yaml b/jenkins-k8s/deployment-basic.yaml new file mode 100644 index 0000000..7f9d1c0 --- /dev/null +++ b/jenkins-k8s/deployment-basic.yaml @@ -0,0 +1,158 @@ +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: jenkins-admin +rules: + - apiGroups: [""] + resources: ["*"] + verbs: ["*"] + +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: jenkins-admin + +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: jenkins-admin +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: jenkins-admin +subjects: +- kind: ServiceAccount + name: jenkins-admin + # ref: ServiceAccount + namespace: basic + +--- +apiVersion: storage.k8s.io/v1 +kind: StorageClass +metadata: + name: local-storage +provisioner: kubernetes.io/no-provisioner +volumeBindingMode: WaitForFirstConsumer + +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: jenkins-pvc-local +spec: + storageClassName: local-storage + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 3Gi + +--- +apiVersion: v1 +kind: PersistentVolume +metadata: + name: jenkins-pv-local + labels: + type: local +spec: + storageClassName: local-storage + claimRef: + name: jenkins-pvc-local + # ref: PersistentVolumeClaim + namespace: basic + capacity: + storage: 20Gi + accessModes: + - ReadWriteOnce + local: + path: /data/jenkins + nodeAffinity: + required: + nodeSelectorTerms: + - matchExpressions: + - key: kubernetes.io/hostname + operator: In + values: + - bfs-k8snode-10-2-0-10.hetzner.base.beaconfireinc.com + + + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: jenkins +spec: + replicas: 1 + selector: + matchLabels: + app: jenkins + template: + metadata: + labels: + app: jenkins + spec: + securityContext: + fsGroup: 1000 + runAsUser: 1000 + serviceAccountName: jenkins-admin + containers: + - name: jenkins + image: jenkins/jenkins:lts + resources: + limits: + memory: "2Gi" + cpu: "1000m" + requests: + memory: "500Mi" + cpu: "500m" + ports: + - name: httpport + containerPort: 8080 + - name: jnlpport + containerPort: 50000 + livenessProbe: + httpGet: + path: "/login" + port: 8080 + initialDelaySeconds: 90 + periodSeconds: 10 + timeoutSeconds: 5 + failureThreshold: 5 + readinessProbe: + httpGet: + path: "/login" + port: 8080 + initialDelaySeconds: 60 + periodSeconds: 10 + timeoutSeconds: 5 + failureThreshold: 3 + volumeMounts: + - name: jenkins-data + mountPath: /var/jenkins_home + volumes: + - name: jenkins-data + persistentVolumeClaim: + claimName: jenkins-pvc-local + +--- +apiVersion: v1 +kind: Service +metadata: + name: jenkins + annotations: + prometheus.io/scrape: 'true' + prometheus.io/path: / + prometheus.io/port: '8080' +spec: + selector: + app: jenkins + ports: + - port: 8080 + targetPort: 8080 + nodePort: 30080 + type: NodePort + diff --git a/jenkins-k8s/deployment.yaml b/jenkins-k8s/deployment-comon.yaml similarity index 82% rename from jenkins-k8s/deployment.yaml rename to jenkins-k8s/deployment-comon.yaml index 6cd7b9c..c0f9a9a 100644 --- a/jenkins-k8s/deployment.yaml +++ b/jenkins-k8s/deployment-comon.yaml @@ -1,9 +1,90 @@ +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: jenkins-admin +rules: + - apiGroups: [""] + resources: ["*"] + verbs: ["*"] + +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: jenkins-admin + +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: jenkins-admin +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: jenkins-admin +subjects: +- kind: ServiceAccount + name: jenkins-admin + # ref: ServiceAccount + namespace: common + +--- +apiVersion: storage.k8s.io/v1 +kind: StorageClass +metadata: + name: local-storage +provisioner: kubernetes.io/no-provisioner +volumeBindingMode: WaitForFirstConsumer + +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: jenkins-pvc-local +spec: + storageClassName: local-storage + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 3Gi + +--- +apiVersion: v1 +kind: PersistentVolume +metadata: + name: jenkins-pv-local + labels: + type: local +spec: + storageClassName: local-storage + claimRef: + name: jenkins-pvc-local + # ref: PersistentVolumeClaim + namespace: common + capacity: + storage: 20Gi + accessModes: + - ReadWriteOnce + local: + path: /data/jenkins + nodeAffinity: + required: + nodeSelectorTerms: + - matchExpressions: + - key: kubernetes.io/hostname + operator: In + values: + - bfs-k8snode-10-2-0-10.hetzner.base.beaconfireinc.com + + + --- apiVersion: apps/v1 kind: Deployment metadata: name: jenkins - namespace: common spec: replicas: 1 selector: @@ -62,7 +143,6 @@ apiVersion: v1 kind: Service metadata: name: jenkins - namespace: common annotations: prometheus.io/scrape: 'true' prometheus.io/path: / @@ -70,54 +150,9 @@ metadata: spec: selector: app: jenkins - type: NodePort ports: - port: 8080 targetPort: 8080 nodePort: 30080 -kind: StorageClass -apiVersion: storage.k8s.io/v1 -metadata: - name: local-storage -provisioner: kubernetes.io/no-provisioner -volumeBindingMode: WaitForFirstConsumer ---- -apiVersion: v1 -kind: PersistentVolume -metadata: - name: jenkins-pv-local - labels: - type: local -spec: - storageClassName: local-storage - claimRef: - name: jenkins-pvc-local - namespace: common - capacity: - storage: 20Gi - accessModes: - - ReadWriteOnce - local: - path: /data/jenkins - nodeAffinity: - required: - nodeSelectorTerms: - - matchExpressions: - - key: kubernetes.io/hostname - operator: In - values: - - bfs-k8snode-10-2-0-10.hetzner.base.beaconfireinc.com + type: NodePort ---- -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - name: jenkins-pvc-local - namespace: common -spec: - storageClassName: local-storage - accessModes: - - ReadWriteOnce - resources: - requests: - storage: 3Gi diff --git a/jenkins-k8s/serviceAccount.yaml b/jenkins-k8s/serviceAccount.yaml deleted file mode 100644 index 1747d74..0000000 --- a/jenkins-k8s/serviceAccount.yaml +++ /dev/null @@ -1,30 +0,0 @@ ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - name: jenkins-admin -rules: - - apiGroups: [""] - resources: ["*"] - verbs: ["*"] - ---- -apiVersion: v1 -kind: ServiceAccount -metadata: - name: jenkins-admin - namespace: common - ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRoleBinding -metadata: - name: jenkins-admin -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: ClusterRole - name: jenkins-admin -subjects: -- kind: ServiceAccount - name: jenkins-admin - namespace: common