# Copyright (C) 2021  Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: kbs-deployment
  namespace: isecl
  labels:
    env: demo
    app: kbs
spec:
  replicas: 1
  selector:
    matchLabels:
      app: kbs
  template:
    metadata:
      labels:
        app: kbs
    spec:
      securityContext:
        fsGroup: 1001
      initContainers:
        - image: busybox:1.32
          imagePullPolicy: Always
          name: chown-config-data
          command:
            - /bin/chown
            - -R
            - "1001"
            - /etc/kbs
            - /var/log/kbs
            - /opt/kbs
          volumeMounts:
            - name: kbs-config-volume
              mountPath: /etc/kbs
            - name: kbs-logs-volume
              mountPath: /var/log/kbs
            - name: kbs-opt-volume
              mountPath: /opt/kbs
      containers:
        - name: kbs
          image: <image-name>:<image-tag>
          imagePullPolicy: Always
          securityContext:
            runAsUser: 1001
            runAsGroup: 1001
          ports:
            - containerPort: 9443
          envFrom:
            - configMapRef:
                name: kbs-config
          volumeMounts:
            - name: kbs-config-volume
              mountPath: /etc/kbs
            - name: kbs-logs-volume
              mountPath: /var/log/kbs
            - name: kbs-opt-volume
              mountPath: /opt/kbs
            - name: kbs-kmip-volume
              mountPath: /etc/kmip
            - mountPath: /etc/secrets/
              name: kbs-secrets
              readOnly: true              
      volumes:
        - name: kbs-logs-volume
          hostPath:
            path: /var/log/kbs/
            type: DirectoryOrCreate
        - name: kbs-config-volume
          hostPath:
            path: /etc/kbs
            type: DirectoryOrCreate
        - name: kbs-opt-volume
          hostPath:
            path: /opt/kbs
            type: DirectoryOrCreate
        - name: kbs-kmip-volume
          secret:
            secretName: kmip-certs
        - name: kbs-secrets
          projected:
            sources:
              - secret:
                  name: kbs-credentials
              - secret:
                  name: bearer-token