Helm chart Keycloak Postgres database import not working with PV and PVC

4/6/2020

We're replacing Docker deployment with Kubernetes. Part of if this process, I'm using Helm chart for Keycloak that has Postgres bundled in.

I want to import existing Keycloak database into Postgres while the database is being created. I thought I should be able to achieve this using existing claim. I thought using the existing claim, where there is already Postgres data available, I should be able to mount it in /var/lib/postgresql/data. But for the life of me, I can't figure it out:

Here is the error I'm getting:

running "VolumeBinding" filter plugin for pod "keycloak-postgresql-0": pod has unbound immediate PersistentVolumeClaims

Here is part of my Helm chart that concerns with Postgres:

postgresql:
  ### PostgreSQL User to create.
  ##
  postgresqlUsername: keycloak

  ## PostgreSQL Password for the new user.
  ## If not set, a random 10 characters password will be used.
  ##
  postgresqlPassword: ""

  ## PostgreSQL Database to create.
  ##
  postgresqlDatabase: keycloak

  ## Persistent Volume Storage configuration.
  ## ref: https://kubernetes.io/docs/user-guide/persistent-volumes
  ##
  persistence:
    ## Enable PostgreSQL persistence using Persistent Volume Claims.
    ##
    enabled: true
    exitingClaim: "keycloak"
    mountPath: /var/lib/postgresql/data
    storageClass: "postgres"

Here is my PV:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: task-pv-postgres
  labels:
    type: local
spec:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  hostPath:
    path: "/mnt/disks/vol1/postgresql"
  storageClassName: "postgres"

Here is my PVC

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: keycloak
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi
  storageClassName: "postgres"

Many thanks in advance.

-- getITdone
kubernetes
kubernetes-helm
kubernetes-pvc
postgresql

0 Answers