apiVersion: apps/v1
kind: StatefulSet
metadata:
  labels:
    app: jenkins
  name: jenkins
  namespace: ci
spec:
  replicas: 1
  selector:
    matchLabels:
      app: jenkins
  serviceName: jenkins
  template:
    metadata:
      labels:
        app: jenkins
      name: jenkins
      annotations:
        #disable istio sidecar injection
        sidecar.istio.io/inject: "false"
    spec:
      securityContext:
        fsGroup: 1000
        sysctls:
          #kubernetes >= v1.11 and kernel version >= 4.15 needed
          #- name: kernel.msgmax
          #  value: "65536"
          - name: net.ipv4.tcp_syncookies
            value: "0"
          - name: net.ipv4.ip_local_port_range
            value: "1024 65535"
          - name: net.core.somaxconn
            value: "65535"
          - name: net.ipv4.ip_unprivileged_port_start
            value: "0"
          - name: net.ipv4.tcp_tw_reuse
            value: "2"
          - name: net.ipv4.tcp_fin_timeout
            value: "20"
          - name: net.ipv4.tcp_keepalive_intvl
            value: "10"
          - name: net.ipv4.tcp_keepalive_probes
            value: "2"
          - name: net.ipv4.tcp_keepalive_time
            value: "120"
          - name: net.ipv4.tcp_ecn
            value: "1"
          - name: net.ipv4.tcp_max_syn_backlog
            value: "65536"
          - name: net.ipv4.tcp_rfc1337
            value: "1"
          - name: net.ipv4.tcp_slow_start_after_idle
            value: "1"
          - name: net.ipv4.tcp_fack
            value: "1"
          - name: net.ipv4.tcp_max_tw_buckets
            value: "1048576"
          - name: net.ipv4.tcp_fastopen
            value: "3"
          - name: net.ipv4.icmp_ratelimit
            value: "100"
          - name: net.ipv4.tcp_abort_on_overflow
            value: "0"
          - name: net.ipv4.tcp_adv_win_scale
            value: "2"
          - name: net.ipv4.tcp_retries2
            value: "8"
          - name: net.ipv4.tcp_syn_retries
            value: "3"
          - name: net.ipv4.tcp_synack_retries
            value: "2"
          - name: net.unix.max_dgram_qlen
            value: "512"
          - name: net.ipv4.tcp_fwmark_accept
            value: "1"
          - name: net.ipv4.fwmark_reflect
            value: "1"
      containers:
      - image: slpcat/kube-jenkins-service:2.314-jdk11
        imagePullPolicy: Always
        livenessProbe:
          failureThreshold: 3
          httpGet:
            path: /login
            port: 8080
            scheme: HTTP
          initialDelaySeconds: 60
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 5
        name: jenkins
        ports:
        - containerPort: 8080
          name: web
          protocol: TCP
        - containerPort: 50000
          name: agent
          protocol: TCP
        readinessProbe:
          failureThreshold: 3
          httpGet:
            path: /login
            port: 8080
            scheme: HTTP
          initialDelaySeconds: 60
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 5
        resources:
          limits:
            cpu: "4"
            memory: 4Gi
          requests:
            cpu: 500m
            memory: 512Mi
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /var/jenkins_home
          name: jenkinshome
      #imagePullSecrets:
      #- name: myregistrykey
      restartPolicy: Always
      serviceAccount: jenkins
  volumeClaimTemplates:
  - metadata:
      name: jenkinshome
    spec:
      accessModes:
      - ReadWriteOnce
      #ceph rbd storageclass
      #storageClassName: rbd
      resources:
        requests:
          storage: 60Gi
