2

I am facing this error from kubernetes cluster. Though it works perfectly from my local server. Here is my application.yml of SpringBoot App

spring:

datasource:
    dataSourceClassName: org.postgresql.ds.PGPoolingDataSource
    url: jdbc:postgresql://${POSTGRES_HOST}:5432/test_db
    databaseName: test_db
    poolName: SpringBootHikariCP
    username: ${POSTGRES_USER}
    password: ${POSTGRES_PASSWORD}
    testWhileIdle: true
    validationQuery: SELECT 1
jpa:
    database-platform: org.hibernate.dialect.PostgreSQL82Dialect
    openInView: false
    show_sql: true
    generate-ddl: true
    hibernate:
        ddl-auto: update
        naming-strategy: org.hibernate.cfg.ImprovedNamingStrategy
        use-new-id-generator-mappings: true
    properties:
        hibernate.cache.use_second_levelt_cache: false
        hibernate.cache.use_query_cache: false
        hibernate.generate_statistics: true
        hibernate.hbm2ddl.auto: validate

Here is my Hikari configuration.

            HikariConfig config = new HikariConfig();
            config.setDataSourceClassName(dataSourceClassName);
            config.addDataSourceProperty("url", url);
            config.addDataSourceProperty("user", user);
            config.addDataSourceProperty("password", password);

            return new HikariDataSource(config);

I have checked DB connectivity of kubernetes without Hikari and it works perfectly. So there is no issue with connectivity. Please help me regarding the issue. I am stuck with this for couple of days. Thank you

Community
  • 1
  • 1
shawon
  • 166
  • 2
  • 6

2 Answers2

2

${POSTGRES_HOST} is expecting a system environment variable that you probably missing in the specific machine, add it for example:

export POSTGRES_HOST="1.1.1.1"
Ori Marko
  • 56,308
  • 23
  • 131
  • 233
  • Unfortunately there is no issue regarding environment variable. I can see application can fetch information from environment variable. for example url is generating like `jdbc:postgresql://postgres:5432/postgres` . Don't know what's happening when I configure connection to hikaricp into kubernetes. Thank you – shawon Aug 28 '18 at 07:39
  • @shawon did you check connectivity to the host/IP? – Ori Marko Aug 28 '18 at 07:49
  • Yes I can connect to the host. – shawon Aug 28 '18 at 07:59
  • @shawon can you change to using IP? – Ori Marko Aug 28 '18 at 08:00
  • Dear @user7294900 this server is in kubernetes cluster. It usually works with IP address. – shawon Aug 28 '18 at 11:04
1

Change the url to jdbc:postgresql://localhost:5432/test_db or

jdbc:postgresql://<host ip>:5432/test_db

It looks like the problem with the placeholder ${POSTGRES_HOST}

Try with localhost

datasource:
    dataSourceClassName: org.postgresql.ds.PGPoolingDataSource
    url: jdbc:postgresql://localhost:5432/test_db;
    databaseName: test_db
    poolName: SpringBootHikariCP
    username: ${POSTGRES_USER}
    password: ${POSTGRES_PASSWORD}
    testWhileIdle: true
    validationQuery: SELECT 1

Might be you have not set the environment variable ${POSTGRES_HOST}, that also can be a reason.