apiVersion: apps/v1
kind: Deployment
metadata:
  name: RELEASE-NAME-jenkins
  namespace: default
  labels:
    "app.kubernetes.io/name": 'jenkins'
    "helm.sh/chart": "jenkins-1.10.1"
    "app.kubernetes.io/managed-by": "Helm"
    "app.kubernetes.io/instance": "RELEASE-NAME"
    "app.kubernetes.io/component": "jenkins-master"
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      "app.kubernetes.io/component": "jenkins-master"
      "app.kubernetes.io/instance": "RELEASE-NAME"
  template:
    metadata:
      labels:
        "app.kubernetes.io/name": 'jenkins'
        "helm.sh/chart": "jenkins-1.10.1"
        "app.kubernetes.io/managed-by": "Helm"
        "app.kubernetes.io/instance": "RELEASE-NAME"
        "app.kubernetes.io/component": "jenkins-master"
      annotations:
        checksum/config: 5e98154b950c9481d238267a4ba68dc7271f8658683911fa0054f77294b32a72
    spec:
      securityContext:
        runAsUser: 0
      serviceAccountName: "RELEASE-NAME-jenkins"
      initContainers:
        - name: "copy-default-config"
          image: "jenkins/jenkins:lts"
          imagePullPolicy: "Always"
          command: [ "sh", "/var/jenkins_config/apply_config.sh" ]
          env:
            - name: ADMIN_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: RELEASE-NAME-jenkins
                  key: jenkins-admin-password
            - name: ADMIN_USER
              valueFrom:
                secretKeyRef:
                  name: RELEASE-NAME-jenkins
                  key: jenkins-admin-user
          resources:
            limits:
              cpu: 2000m
              memory: 4096Mi
            requests:
              cpu: 50m
              memory: 256Mi
          volumeMounts:
            - mountPath: /tmp
              name: tmp
            - mountPath: /var/jenkins_home
              name: jenkins-home
            - mountPath: /var/jenkins_config
              name: jenkins-config
            - mountPath: /usr/share/jenkins/ref/secrets/
              name: secrets-dir
            - mountPath: /usr/share/jenkins/ref/plugins
              name: plugins
            - mountPath: /var/jenkins_plugins
              name: plugin-dir
      containers:
        - name: jenkins
          image: "jenkins/jenkins:lts"
          imagePullPolicy: "Always"
          args: [ "--argumentsRealm.passwd.$(ADMIN_USER)=$(ADMIN_PASSWORD)",  "--argumentsRealm.roles.$(ADMIN_USER)=admin", "--httpPort=8080"]
          env:
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: JAVA_OPTS
              value: >


            - name: JENKINS_OPTS
              value: ""
            - name: JENKINS_SLAVE_AGENT_PORT
              value: "50000"
            - name: ADMIN_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: RELEASE-NAME-jenkins
                  key: jenkins-admin-password
            - name: ADMIN_USER
              valueFrom:
                secretKeyRef:
                  name: RELEASE-NAME-jenkins
                  key: jenkins-admin-user
          ports:
            - containerPort: 8080
              name: http
            - containerPort: 50000
              name: slavelistener
          livenessProbe:
            httpGet:
              path: "/login"
              port: http
            initialDelaySeconds: 90
            periodSeconds: 10
            timeoutSeconds: 5
            failureThreshold: 5
          readinessProbe:
            httpGet:
              path: "/login"
              port: http
            initialDelaySeconds: 60
            periodSeconds: 10
            timeoutSeconds: 5
            failureThreshold: 3

          resources:
            limits:
              cpu: 2000m
              memory: 4096Mi
            requests:
              cpu: 50m
              memory: 256Mi
          volumeMounts:
            - mountPath: /tmp
              name: tmp
            - mountPath: /var/jenkins_home
              name: jenkins-home
              readOnly: false
            - mountPath: /var/jenkins_config
              name: jenkins-config
              readOnly: true
            - mountPath: /usr/share/jenkins/ref/secrets/
              name: secrets-dir
              readOnly: false
            - mountPath: /usr/share/jenkins/ref/plugins/
              name: plugin-dir
              readOnly: false

      volumes:
        - name: plugins
          emptyDir: {}
        - name: tmp
          emptyDir: {}
        - name: jenkins-config
          configMap:
            name: RELEASE-NAME-jenkins
        - name: secrets-dir
          emptyDir: {}
        - name: plugin-dir
          emptyDir: {}
        - name: jenkins-home
          persistentVolumeClaim:
            claimName: RELEASE-NAME-jenkins