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

2 Answers 2

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" 
Sign up to request clarification or add additional context in comments.

5 Comments

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 did you check connectivity to the host/IP?
Yes I can connect to the host.
@shawon can you change to using IP?
Dear @user7294900 this server is in kubernetes cluster. It usually works with IP address.
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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.