Unable to load consul config - spring-boot

I'm trying to build sample microservice app using this tutorial Tutorial. jhipster v5.2.1 So I've created a gateway and an armory started consul using this command:
docker-compose -f src/main/docker/consul.yml up
While I've pointed into the armory folder writing this command :
./gradlew
I got this error :
2018-09-03 13:20:11.235 WARN 7224 --- [ restartedMain] o.s.c.c.c.ConsulPropertySourceLocator : Unable to load consul config from config/armory-swagger/
com.ecwid.consul.transport.TransportException: org.apache.http.conn.HttpHostConnectException: Connect to localhost:8600 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect
Could you please help me

If you are using the toolbox you have to replace localhost by the IP of your Docker machine vm. You will have to ajust the bootstrap.yml properties to point to this adress.
You should also be able to apply this trick : https://www.jhipster.tech/tips/020_tip_using_docker_containers_as_localhost_on_mac_and_windows.html

I just changed fail-fast to false in bootstrap-prod.yml
You can disable Spring Cloud Config this way.
fail-fast: false
Otherwise you have to provide proper configuration as stated above.
Or you can run this command if you have already installed consul on your development machine.
consul agent -dev

Related

Spring cloud client trying to run on server port 8888

The config server is up and the client is able to fetch the properties from config server.
HTTP GET http://localhost:8888/account-service/dev/config
Accept=[application/json, application/*+json]
Response 200 OK
But the problem is, client service is trying to start on config server port 8888. I have set server.port=8080 in the client but still not working.
***************************
APPLICATION FAILED TO START
***************************
Description:
Web server failed to start. Port 8888 was already in use.
Am I missing any configuration here? Highly appreciate any help.
Config server application.properties,
spring.application.name=config-server
spring.cloud.config.profiles=dev
spring.cloud.config.server.git.uri=REPO_URL
server.port=8888
Finally, I was able to find the solution. When I was trying to start client service, server.port was also getting overridden with config server port. I added server.port=8080 in the properties file for the client service profile in config repo (account-service.properties) and it worked.

Spring boot keycloak dockerization not work : Failed to load URLs from http://localhost:8180/auth/realms/heroes/.well-known/openid-configuration

I have dockerize my keycloak and spring boot application but i have an warn like :
Failed to load URLs from http://localhost:8180/auth/realms/heroes/.well-known/openid-configuratio
java.net.ConnectException: Connection refused (Connection refused)
and an error like :
ERROR 1 --- [nio-9090-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] threw exception
If both, keycloak and your spring application, are running inside docker, you can't connect to http://localhost:8180 from within the spring-container
Instead make sure the keycloak container already has a name (e.g. keycloak) or start it with a name docker run --name keycloak ...
Then use this name for the keycloak configuration in your spring booot app.
http://keycloak:8080/auth/
Please make sure that you use the internal (!) port of the keycloak container. I'm not sure about this 8180 port, but usually 8080 is the default port for keycloack running in docker
Probably your spring boot application cannot access your dockerized keycloak because you forgot to expose the port to your host with -p 8180:8180 flag
try to run your dockerizes keycloak with the following command:
docker run -p 8180:8180 -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin quay.io/keycloak/keycloak:12.0.4 -Djboss.http.port=8180

Openshift container health probe connection refused

Hi openshift community,
I am currently migrating an app to Openshift and has encountered failed health probes due to connection refused. What I find strange is that if I ssh into the pod and use
curl localhost:10080/xxx-service/info
It returns HTTP 200 but if I use the IP address then it fails with
This is the details:
POD status
Logs in Openshift saying Spring boot started successfully
Openshift events saying probes failed due to connection refused
Tried SSH to pod to check using localhost which works
Not sure why the IP address is not resolving at the POD level.... Does anyone know the answer or have encountered it?
It is hard to say in your case what exactly the issue is, as it is environment specific.
In general, you should avoid using IP addresses when working with Kubernetes, as these will change whenever a Pod is restarted (which may be the root cause for the issue you are seeing).
When defining readiness and liveness probes for your container, I would recommend that you always use the following syntax to define your checks (note that it does not specify the host):
...
readinessProbe:
httpGet:
path: /xxx-service/info
port: 10080
initialDelaySeconds: 15
timeoutSeconds: 1
...
See also the Kubernetes or OpenShift documentation for more information:
https://docs.openshift.com/container-platform/3.11/dev_guide/application_health.html
https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-a-liveness-http-request
I found the root cause, it turns out it was Spring related.
It was a Spring Boot app that was being packaged as WAR file and deployed to Tomcat server. In the application.properties, it had this field:
server.address=127.0.0.1
Removing it has fixed this issue.
https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-application-properties.html#common-application-properties-server

Unable to connect to redis sentinel running on docker in my local Spring boot

I'm using Spring boot 2.2.5 and Spring data redis and bitnami/redis-sentinel
sentinel docker image.
bitnami/redis-sentinel docker image works fine with docker compose.
I can connect to the redis with redis-cli. (cli shows 127.0.0.1:6379 connected)
But in my local Spring boot application, it doesn't work.
Error trace is like:
org.springframework.data.redis.connection.PoolException: Could not get a resource from the pool; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to 172.28.0.2:6379
at org.springframework.data.redis.connection.lettuce.LettucePoolingConnectionProvider.getConnection(LettucePoolingConnectionProvider.java:109) ~[spring-data-redis-2.2.5.RELEASE.jar:2.2.5.RELEASE]
Caused by: io.lettuce.core.RedisConnectionException: Unable to connect to 172.28.0.2:6379
at io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:78) ~[lettuce-core-5.2.2.RELEASE.jar:5.2.2.RELEASE]
Caused by: io.netty.channel.ConnectTimeoutException: connection timed out: /172.28.0.2:6379
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe$1.run(AbstractNioChannel.java:261) ~[netty-transport-4.1.45.Final.jar:4.1.45.Final]
the IP address 172.28.0.2 is redis master ip in the docker image.
My sentinel host configuration is like below,
127.0.0.1:26379,127.0.0.1:26379,127.0.0.1:26379
I guess my application gets well the master info via localhost sentinel configuration.
Then Why is my application finding 172.28.0.2:6379 for master instead of 127.0.0.1:6379 ?
Do I need to change the address in that docker image or Should I run my app on the docker also?
Any help would be appreciated!
I just solved my problem by adding REDIS_MASTER_HOST=127.0.0.1 (thatw was 'redis' originally) at environment in docker-compose.
I figured out that there is 172.28.0.2 6379 set for monitor reids master in redis-sentinel.conf of running container and it didn't changed with container name 'redis'.
After that, my springb boot application with lettuce client can connect to redis without any problem in local machine.

Spring Cloud Config Server-GITLAB SSH Connection

After going the number of SO threads and blogs and Spring cloud config documentation still, I couldn't find on how I can connect to remote GITLAB repository as I'm getting below error while starting the spring-cloud-config server.
Caused by: com.jcraft.jsch.JSchException: Auth fail
spring:
cloud:
config:
server:
git:
uri: git#private_gitlab_repo:project
search-paths: '{application}'
skip-ssl-validation: true
strict-host-key-checking: false
known-hosts-file: C:\Users\myname\.ssh\known_hosts
spring-boot :2.1.2.RELEASE
spring-cloud.version: Greenwich.RELEASE
OS: Windows-7
With the command prompt, I could able to interact with the GITLAB repository. I do have the SSH key generated and added the public key in GITLAB settings. Also, I do not have the option to use username and password to connect to GITLAB.
Any pointers on where I'm missing the configuration or steps?
Found that this is my IntelliJ idea IDE issue and when I try running the same project in command prompt it worked without any issues.

Resources