---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: app
  namespace: spring-k8s-jpa
spec:
  replicas: 1
  selector:
    matchLabels:
      role: app
  template:
    metadata:
      labels:
        role: app
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/path: "/actuator/prometheus"
        prometheus.io/port: "8080"
    spec:
      containers:
        - name: app
          image: alexandreroman/spring-k8s-jpa-demo:latest
          imagePullPolicy: IfNotPresent
          resources:
            limits:
              memory: 1Gi
          env:
            # Read ConfigMap and Secret mounted as volumes under /etc/config.
            - name: SPRING_CONFIG_IMPORT
              value: configtree:/etc/config/*/
          ports:
            - name: http
              containerPort: 8080
          livenessProbe:
            httpGet:
              port: http
              path: /actuator/health/liveness
            initialDelaySeconds: 10
            failureThreshold: 3
            periodSeconds: 1
          readinessProbe:
            httpGet:
              port: http
              path: /actuator/health/readiness
            initialDelaySeconds: 10
            failureThreshold: 6
          volumeMounts:
            - mountPath: /etc/config/app
              name: app
            # The database secret is mounted as a single file,
            # using the name expected by Spring Data JPA (we're actually aliasing the secret key).
            - mountPath: /etc/config/db/spring.datasource.password
              name: db
              subPath: postgresql-password
      volumes:
        - name: app
          configMap:
            name: app
        - name: db
          secret:
            secretName: pgdb-postgresql
