Search code examples
postgresqlopenshiftkeycloakopenshift-originkeycloak-services

keycloak and postgresql on openshift


I tried to deploy keycloak with POSTGRESQL on openshift. I used this image, jboss/keycloak-openshift image for keycloak and rhscl/postgresql-95-rhel7 for postgresql.

I then I added environment variables in keycloak deployment

  • DB_DATABASE : keycloak
  • DB_USER : postgresl-secret-database-user
  • DB_PASSWORD : postgresl-secret-database-password
  • DB_VENDOR : POSTGRES

I thought this is what I needed to do to make keycloak work with postgresql. These are the errors and warning I am seeing in the pod logs.

IOException occurred while connecting to postgres:5432: java.net.UnknownHostException: postgres

Connection error: : org.postgresql.util.PSQLException: The connection attempt failed.

But it is not working this way. The keycloak pod fails. Do I need to do anything else as well?


Solution

  • What is the name of your database service?

    If not the default of postgres that Keycloak expects, you need to set DB_ADDR. I use the following in my template:

                                    {
                                        "name": "KEYCLOAK_USER",
                                        "value": "${KEYCLOAK_USER}"
                                    },
                                    {
                                        "name": "KEYCLOAK_PASSWORD",
                                        "value": "${KEYCLOAK_PASSWORD}"
                                    },
                                    {
                                        "name": "DB_VENDOR",
                                        "value": "postgres"
                                    },
                                    {
                                        "name": "DB_ADDR",
                                        "value": "${KEYCLOAK_NAME}-db"
                                    },
                                    {
                                        "name": "DB_PORT",
                                        "value": "5432"
                                    },
                                    {
                                        "name": "DB_DATABASE",
                                        "value": "keycloak"
                                    },
                                    {
                                        "name": "DB_USER",
                                        "value": "keycloak"
                                    },
                                    {
                                        "name": "DB_PASSWORD",
                                        "value": "${DATABASE_PASSWORD}"
                                    },
    

    Suggest setting them all.

    Further details in: