apiVersion: apps/v1
kind: Deployment
metadata:
  name: keycloak
  namespace: bookstore
  labels:
    app: keycloak
spec:
  replicas: 1
  selector:
    matchLabels:
      app: keycloak
  template:
    metadata:
      labels:
        app: keycloak
    spec:
      containers:
      - name: keycloak
        image: quay.io/keycloak/keycloak:12.0.1
        resources:
          limits:
            memory: 1024Mi
            cpu: "2"
          requests:
            memory: 256Mi
            cpu: "0.2"
        env:
        - name: KEYCLOAK_USER
          value: keycloak
        - name: KEYCLOAK_PASSWORD
          value: keycloak
        - name: PROXY_ADDRESS_FORWARDING
          value: "true"
        - name: DB_VENDOR
          value: postgres
        - name: DB_ADDR
          value: postgres-service
        - name: DB_DATABASE
          value: postgresdb
        - name: DB_USER
          value: postgres
        - name: DB_PASSWORD
          value: postgres
        - name: KEYCLOAK_IMPORT
          value: /keycloak-import/keycloak-init/bookstore-realm.json
        ports:
        - name: http
          containerPort: 8080
        - name: https
          containerPort: 8443
        readinessProbe:
          httpGet:
            path: /auth/realms/master
            port: 8080
        volumeMounts:
          - name: keycloak-import
            mountPath: /keycloak-import
      initContainers:
        - name: init
          image: anitechcs/keycloak-init:latest
          command: ["sh", "-c", "cp -R /keycloak-init /keycloak-import"]
          volumeMounts:
          - name: keycloak-import
            mountPath: /keycloak-import
      volumes:
        - name: keycloak-import
          emptyDir: { }
            
    