我想在kubernetes集群中将我的java spring引导微服务注册到consul中,第一步我使用gradle添加consul依赖项:
implementation "org.springframework.cloud:spring-cloud-starter-consul-discovery"
现在我在application.properties
中这样定义consul配置:
# registry center
spring.cloud.consul.host=consul-1630121482-headless.reddwarf-pro.svc.cluster.local
spring.cloud.consule.port=8500
spring.cloud.consul.enabled=true
spring.cloud.consul.discovery.health-check-interval=15s
spring.cloud.consul.discovery.instance-id= ${spring.application.name}:${server.port}
但是consul显示如下错误:
Get "http://dolphin-post-service-78f88c8c54-nrfbz:11014/actuator/health": dial tcp: lookup dolphin-post-service-78f88c8c54-nrfbz on 10.96.0.10:53: no such host
consul通过pod名访问我的服务,那么如何使consul访问正确的url呢?我认为url应该是这样的:
dolphin-post-service-78f88c8c54-nrfbz.dolphin-post-service.reddwarf-pro.svc.cluster.local
那么我该怎么做才能让它工作呢?
添加此配置到applicaton.properties
使用ip地址:
spring.cloud.consul.discovery.prefer-ip-address= true