apiVersion: v1
kind: List
items:
  - apiVersion: v1
    kind: Service
    metadata:
      name: keycloak
      namespace: keycloak
      labels:
        app.kubernetes.io/name: keycloak
        hwlab.pikastech.local/service-id: keycloak
    spec:
      type: ClusterIP
      selector:
        app.kubernetes.io/name: keycloak
      ports:
        - name: http
          port: 8080
          targetPort: http
        - name: management
          port: 9000
          targetPort: management
  - apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: keycloak
      namespace: keycloak
      labels:
        app.kubernetes.io/name: keycloak
        hwlab.pikastech.local/service-id: keycloak
    spec:
      replicas: 1
      strategy:
        type: Recreate
      selector:
        matchLabels:
          app.kubernetes.io/name: keycloak
      template:
        metadata:
          labels:
            app.kubernetes.io/name: keycloak
            hwlab.pikastech.local/service-id: keycloak
        spec:
          containers:
            - name: keycloak
              image: quay.io/keycloak/keycloak:25.0
              args:
                - start
                - --http-enabled=true
                - --http-port=8080
                - --hostname-strict=false
                - --proxy-headers=xforwarded
                - --features=preview
                - --db=postgres
                - --db-url=jdbc:postgresql://keycloak-postgres.keycloak.svc.cluster.local:5432/keycloak
                - --db-username=keycloak
                - --health-enabled=true
              ports:
                - name: http
                  containerPort: 8080
                - name: management
                  containerPort: 9000
              env:
                - name: KEYCLOAK_ADMIN
                  value: admin
                - name: KEYCLOAK_ADMIN_PASSWORD
                  valueFrom:
                    secretKeyRef:
                      name: keycloak-admin
                      key: password
                - name: KC_DB
                  value: postgres
                - name: KC_DB_URL
                  value: jdbc:postgresql://keycloak-postgres.keycloak.svc.cluster.local:5432/keycloak
                - name: KC_DB_USERNAME
                  value: keycloak
                - name: KC_DB_PASSWORD
                  valueFrom:
                    secretKeyRef:
                      name: keycloak-postgres
                      key: password
              readinessProbe:
                httpGet:
                  path: /health/ready
                  port: 9000
                initialDelaySeconds: 30
                periodSeconds: 10
              livenessProbe:
                httpGet:
                  path: /health/live
                  port: 9000
                initialDelaySeconds: 60
                periodSeconds: 30
