apiVersion: v1
kind: List
items:
  - apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: data-keycloak-postgres-0
      namespace: keycloak
    spec:
      accessModes: [ReadWriteOnce]
      resources:
        requests:
          storage: 5Gi
  - apiVersion: v1
    kind: Service
    metadata:
      name: keycloak-postgres
      namespace: keycloak
      labels:
        app.kubernetes.io/name: keycloak-postgres
        hwlab.pikastech.local/service-id: keycloak-postgres
    spec:
      type: ClusterIP
      selector:
        app.kubernetes.io/name: keycloak-postgres
      ports:
        - name: postgres
          port: 5432
          targetPort: postgres
  - apiVersion: apps/v1
    kind: StatefulSet
    metadata:
      name: keycloak-postgres
      namespace: keycloak
      labels:
        app.kubernetes.io/name: keycloak-postgres
        hwlab.pikastech.local/service-id: keycloak-postgres
    spec:
      serviceName: keycloak-postgres
      replicas: 1
      selector:
        matchLabels:
          app.kubernetes.io/name: keycloak-postgres
      template:
        metadata:
          labels:
            app.kubernetes.io/name: keycloak-postgres
            hwlab.pikastech.local/service-id: keycloak-postgres
        spec:
          containers:
            - name: postgres
              image: postgres:16-alpine
              ports:
                - name: postgres
                  containerPort: 5432
              env:
                - name: POSTGRES_DB
                  value: keycloak
                - name: POSTGRES_USER
                  value: keycloak
                - name: POSTGRES_PASSWORD
                  valueFrom:
                    secretKeyRef:
                      name: keycloak-postgres
                      key: password
              volumeMounts:
                - name: data
                  mountPath: /var/lib/postgresql/data
              readinessProbe:
                exec:
                  command: ["pg_isready", "-U", "keycloak"]
                initialDelaySeconds: 5
                periodSeconds: 5
      volumeClaimTemplates:
        - metadata:
            name: data
            namespace: keycloak
          spec:
            accessModes: [ReadWriteOnce]
            resources:
              requests:
                storage: 5Gi
