<p>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.</p>

<p>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.</p>

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

<p>Below is my Configuration</p>

<pre class="lang-sh prettyprint-override"><code>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
</code></pre>

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

<p>Thanks very much in advance for your help</p>

olibs
<p>Found the solution!</p>

<pre class="lang-sh prettyprint-override"><code>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
</code></pre>

<p>So set</p>

<pre><code>spring.cloud.consul.discovery.prefer-ip-address=false
spring.cloud.consul.discovery.prefer-agent-address=false
</code></pre>

<p>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.</p>
