diff --git a/README.md b/README.md index 26ab198..630bc6f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ # Kubernetes Manifests for Jenkins Deployment -Refer https://devopscube.com/setup-jenkins-on-kubernetes-cluster/ for step by step process to use these manifests. \ No newline at end of file +Refer to https://devopscube.com/setup-jenkins-on-kubernetes-cluster/ for step-by-step process to use these manifests. + +A variant is maintained as https://www.jenkins.io/doc/book/installing/kubernetes/ instructions. diff --git a/jenkins-00-namespace.yaml b/jenkins-00-namespace.yaml new file mode 100644 index 0000000..b16f0c3 --- /dev/null +++ b/jenkins-00-namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: devops-tools diff --git a/jenkins-01-serviceAccount.yaml b/jenkins-01-serviceAccount.yaml new file mode 100644 index 0000000..75245c1 --- /dev/null +++ b/jenkins-01-serviceAccount.yaml @@ -0,0 +1,30 @@ +--- +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: devops-tools + +--- +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: devops-tools \ No newline at end of file diff --git a/jenkins-02-volume.yaml b/jenkins-02-volume.yaml new file mode 100644 index 0000000..edbaf33 --- /dev/null +++ b/jenkins-02-volume.yaml @@ -0,0 +1,47 @@ +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-volume + labels: + type: local +spec: + storageClassName: local-storage + claimRef: + name: jenkins-pv-claim + namespace: devops-tools + capacity: + storage: 10Gi + accessModes: + - ReadWriteOnce + local: + path: /mnt + nodeAffinity: + required: + nodeSelectorTerms: + - matchExpressions: + - key: kubernetes.io/hostname + operator: In + values: + - worker-node01 + +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: jenkins-pv-claim + namespace: devops-tools +spec: + storageClassName: local-storage + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 3Gi \ No newline at end of file diff --git a/jenkins-03-deployment.yaml b/jenkins-03-deployment.yaml new file mode 100644 index 0000000..e2cdf8b --- /dev/null +++ b/jenkins-03-deployment.yaml @@ -0,0 +1,59 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: jenkins + namespace: devops-tools +spec: + replicas: 1 + selector: + matchLabels: + app: jenkins-server + template: + metadata: + labels: + app: jenkins-server + spec: + securityContext: + fsGroup: 1000 + runAsUser: 1000 + serviceAccountName: jenkins-admin + containers: + - name: jenkins + image: jenkins/jenkins:lts + # OPTIONAL: check for new floating-tag LTS releases whenever the pod is restarted: + imagePullPolicy: Always + 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-pv-claim \ No newline at end of file diff --git a/jenkins-04-service.yaml b/jenkins-04-service.yaml new file mode 100644 index 0000000..8a37798 --- /dev/null +++ b/jenkins-04-service.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 +kind: Service +metadata: + name: jenkins-service + namespace: devops-tools + annotations: + prometheus.io/scrape: 'true' + prometheus.io/path: / + prometheus.io/port: '8080' +spec: + selector: + app: jenkins-server + type: NodePort + ports: + - port: 8080 + targetPort: 8080 + nodePort: 32000 \ No newline at end of file