Spring Cloud Consul - Service Not Registering a Contactable Address on K8s

4/20/2020

I've seen a few questions around this, but not been able to get a clear answer. I have a Consul cluster running on an Openshift K8s cluster. I also have a set of services that need to register with and use Consul, also running in the same K8s cluster.

My issue is that the services register themselves with non-contactable addresses, which look like the Pod addresses, rather that the address of the K8s Service for the pod.

Consequently the service registers itself, but the health checks fail and the service isn't contactable via Consul.

Below is my Configuration

spring.cloud.consul.host=myserver
spring.cloud.consul.port=8500
spring.cloud.consul.discovery.prefer-ip-address=false
spring.cloud.consul.discovery.prefer-agent-address=true
spring.cloud.consul.serviceName=${spring.application.name}
spring.cloud.consul.discovery.healthCheckPath=/actuator/health
spring.cloud.consul.discovery.healthCheckInterval=15s
spring.cloud.consul.discovery.health-check-critical-timeout=30m
spring.cloud.consul.discovery.tags=app-type=spring

spring.cloud.inetutils.ignoredInterfaces=docker0

What do I need to do to get the service to register a contactable address, i.e. the address of the K8s service?

Thanks very much in advance for your help

-- olibs
consul
kubernetes
spring-cloud
spring-cloud-consul

1 Answer

4/21/2020

Found the solution!

spring.cloud.consul.discovery.health-check-url=http://${spring.application.name}-my-openshift-route-url/actuator/health
spring.cloud.consul.discovery.hostname=${spring.application.name}-my-openshift-route-url
spring.cloud.consul.discovery.port=80
spring.cloud.consul.discovery.scheme=http

So set

spring.cloud.consul.discovery.prefer-ip-address=false
spring.cloud.consul.discovery.prefer-agent-address=false

both to false and add the lines from the top block and you should be golden. Please note that spring.application.name needs to be the same as your OpenShift service name.

-- olibs
Source: StackOverflow