Spring Cloud Consul on K8s - Health Check Issue

Hi,
We are running a Consul Cluster (v1.7.2) in an Openshift K8s cluster. We have many microservices written in Spring Boot/Cloud also in the K8s cluster.

My issue is with Spring Cloud Consul not getting the K8s service address to contact the microservice pods so Consul’s Health Checks fail as unreachable.

I know this isn’t strictly a Consul issue but any help of how to work around this would be gratefully received.

Below is my current config

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

Thanks very much in advance for any help.
Oliver

Hey @oliversalmon,

Which address are you seeing being registered with Consul, if any? Does this address correspond to the address that is reachable from the Consul server/client?

It looks like you are setting spring.cloud.consul.discovery.prefer-agent-address to true. I’m not very familiar with spring consul, but it sounds like it will use the address of where the Consul agent is running as the address of the service, which is usually the case when you’re running it in VMs. Is that how you’re running Consul on k8s?

Looking at some of the other properties, I see that you can also directly set spring.cloud.consul.discovery.ip-address to the pod IP, for example. You would then also have to set spring.cloud.consul.discovery.prefer-ip-address to true.

Hope this helps!

Hi,
Thanks for the response. The address we are seeing looks like the pod address which is unreachable what we need is the K8s service address.
We also have services in different Openshift namespaces that need to register so their pod ip addresses won’t be available for Consul so again we need the K8s service dns name.
You can see the issue below.

Thanks very much for your help,
Oliver

Hi,
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.

1 Like