---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: &app splunk
  labels:
    app.kubernetes.io/name: *app
    app.kubernetes.io/instance: *app
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: *app
      app.kubernetes.io/instance: *app
  strategy:
    type: Recreate
  template:
    metadata:
      annotations:
        configmap.reloader.stakater.com/reload: splunk-config
      labels:
        app.kubernetes.io/name: *app
        app.kubernetes.io/instance: *app
    spec:
      containers:
        - name: *app
          env:
            - name: SPLUNK_HOME
              value: /opt/splunk
            - name: SPLUNK_PASSWORD
              value: "${SECRET_SPLUNK_ADMIN_PASSWORD}"
            - name: SPLUNK_ROLE
              value: splunk_standalone
            - name: SPLUNK_START_ARGS
              value: "--accept-license"
            - name: SPLUNK_ALLOW_UPGRADE
              value: "true"
            - name: SPLUNK_UPGRADE
              value: "true"
            - name: SPLUNK_HOSTNAME
              value: *app
          image: splunk/splunk:8.2.6
          imagePullPolicy: IfNotPresent
          livenessProbe:
            exec:
              command:
                - /sbin/checkstate.sh
            failureThreshold: 3
            initialDelaySeconds: 300
            periodSeconds: 30
            successThreshold: 1
            timeoutSeconds: 30
          ports:
            - name: http-splunkweb
              containerPort: 8000
              protocol: TCP
            - name: http-hec
              containerPort: 8088
              protocol: TCP
            - name: https-splunkd
              containerPort: 8089
              protocol: TCP
            - name: tcp-s2s
              containerPort: 9997
              protocol: TCP
          readinessProbe:
            exec:
              command:
                - /bin/grep
                - started
                - /opt/container_artifact/splunk-container.state
            failureThreshold: 3
            initialDelaySeconds: 10
            periodSeconds: 5
            successThreshold: 1
            timeoutSeconds: 5
          resources:
            limits:
              cpu: 1000m
              memory: 4Gi
            requests:
              cpu: 500m
              memory: 1Gi
          volumeMounts:
            - name: splunk-etc
              mountPath: /opt/splunk/etc
            - name: splunk-var
              mountPath: /opt/splunk/var
            - name: splunk-config
              mountPath: /opt/splunk-etc/apps/splunk-config/default
              readOnly: true
      hostname: splunk
      volumes:
        - name: splunk-etc
          persistentVolumeClaim:
            claimName: splunk-etc-v1
        - name: splunk-var
          persistentVolumeClaim:
            claimName: splunk-var-v1
        - name: splunk-config
          configMap:
            name: splunk-config
