apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: keycloak-data-volume-claim
spec:
  storageClassName: azure-managed-standardssd-retain
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
---
apiVersion: v1
kind: Service
metadata:
  name: keycloak
  labels:
    app: keycloak
spec:
  ports:
    - name: http
      port: 8080
      targetPort: 8080
  selector:
    app: keycloak
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: keycloak
  labels:
    app: keycloak
spec:
  replicas: 1
  selector:
    matchLabels:
      app: keycloak
  template:
    metadata:
      labels:
        app: keycloak
    spec:
      initContainers:
        - name: init-myservice
          image: busybox
          command: [ 'sh', '-c', 'chmod 777 /opt/keycloak/data/' ]
          volumeMounts:
            - mountPath: "/opt/keycloak/data/"
              name: keycloak-data
      containers:
        - name: keycloak
          image: quay.io/keycloak/keycloak:23.0.6
          args: [ "start-dev", "--features=preview" ]
          env:
            - name: KEYCLOAK_ADMIN
              value: "admin"
            - name: KEYCLOAK_ADMIN_PASSWORD
              value: "admin"
            - name: KC_PROXY
              value: "edge"
          ports:
            - name: http
              containerPort: 8080
          readinessProbe:
            httpGet:
              path: /realms/master
              port: 8080
          volumeMounts:
            - mountPath: "/opt/keycloak/data/"
              name: keycloak-data
      volumes:
        - name: keycloak-data
          persistentVolumeClaim:
            claimName: keycloak-data-volume-claim
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: keycloak-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
    cert-manager.io/cluster-issuer: letsencrypt-prod
spec:
  tls:
    - hosts:
        - keycloak.demo.walt.id
      secretName: keycloak-tls-secret
  rules:
    - host: keycloak.demo.walt.id
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: keycloak
                port:
                  number: 8080
