apiVersion: apps/v1
kind: Deployment
metadata:
  name: jenkins
  namespace: jenkins-stack
  labels:
    app.kubernetes.io/name: jenkins
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: jenkins
  template:
    metadata:
      labels:
        app.kubernetes.io/name: jenkins
    spec:
      affinity:
        podAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchLabels:
                  app.kubernetes.io/name: docker
              topologyKey: kubernetes.io/hostname
      securityContext:
        fsGroup: 1000
      containers:
        - name: jenkins
          image: ssbostan/jenkins:lts-slim
          env:
            - name: DOCKER_HOST
              value: tcp://docker:2376
            - name: DOCKER_TLS_VERIFY
              value: "1"
            - name: TZ
              value: UTC0
            - name: JAVA_OPTS
              value: -Duser.timezone=UTC0
          ports:
            - containerPort: 50000
            - containerPort: 8080
          resources:
            requests:
              cpu: 2
              memory: 2Gi
            limits:
              cpu: 4
              memory: 4Gi
          volumeMounts:
            - name: docker-client-certs
              mountPath: /var/jenkins_home/.docker
            - name: data
              mountPath: /var/jenkins_home
      volumes:
        - name: docker-client-certs
          persistentVolumeClaim:
            claimName: docker-certs-client
        - name: data
          persistentVolumeClaim:
            claimName: jenkins-data
