spring-bootgoogle-cloud-platformspring-cloud-consul

Spring Cloud Consul health check and status configuration on GCP


We are trying to register a spring-cloud-consul application with consul on GCP compute engine, where it is able to register the application with the consul, but there are two problems we are facing with the application. Below is bootstrap.yaml and server.yaml for the application,

application.yaml

server:
  port: 10003
spring:
  application:
    name: hello-service
  cloud:
    consul:
      enabled: true
    inetutils:
      useOnlySiteLocalInterfaces: true
  endpoints:
    actuator:
      sensitive: false

bootstrap.yaml

spring:
  cloud:
    consul:
      enabled: true
      host: 10.160.0.18
      port: 8500
      discovery:
        prefer-ip-address: true
  1. Consul is not able to call health-check on compute engine, possibly because it's registered on the internal domain name of the instance.

service with consul: NewService{id='hello-service-10003', name='hello-service', tags=[secure=false], address='consul-app-test.c.name-of-project.internal', meta=null, port=10003, enableTagOverride=null, check=Check{script='null', interval='10s', ttl='null', http='http://consul-app-test.c.name-of-project.internal:10003/actuator/health', method='null', header={}, tcp='null', timeout='null', deregisterCriticalServiceAfter='null', tlsSkipVerify=null, status='null'}, checks=null}

  1. Application, not de-registering from the consul. We have stopped the application still it shows on consul UI.

Solution

  • I made a few changes in the application.yaml and bootstrap.yaml which worked for me.

    application.yaml

    spring:
      application:
        name: hello-service
      cloud:
        consul:
          discovery:
            instanceId: ${spring.application.name}:${random.value}
            health-check-critical-timeout: 3m
            prefer-ip-address: true # disable if we want to use google cloud internal DNS 
    

    bootstrap.yaml

    spring:
      cloud:
        consul:
          enabled: true
          host: 10.160.0.18
          port: 8500