我正在使用一组使用 Java + Spring Boot 开发的微服务,并希望在 Docker 组合中使用 Consul 和 KrakenD。
我的 docker-compose 文件如下所示:
version: '3.8'
services:
# Consul
# Service discovery similar to Eureka but could keep configuration
consul:
image: consul
container_name: consul
command: agent -server -ui -node=server1 -bootstrap-expect=1 -client=0.0.0.0
environment:
- CONSUL_BIND_INTERFACE=eth0
ports:
- "8500:8500"
- "8600:8600/udp"
- "8600:8600/tcp"
hostname: "consul"
networks:
- micros
krakend:
image: devopsfaith/krakend
container_name: krakend
volumes:
- ./krakend:/etc/krakend
ports:
- "1234:1234"
- "8080:8080"
- "8090:8090"
networks:
- micros
google-search-service:
environment:
- JAVA_OPTIONS=-Dlogging.level.net.leyba.googlesearch=INFO
image: google-search-service
container_name: google-search-service
#ports:
# - "7000-7200"
networks:
- micros
depends_on:
consul:
condition: service_started
# krakend:
# condition: service_started
networks:
micros:
KrakenD 配置文件如下所示:
{
"version": 2,
"extra_config": {
"github_com/devopsfaith/krakend-gologging": {
"level": "ERROR",
"prefix": "[KRAKEND]",
"syslog": false,
"stdout": true,
"format": "default"
}
},
"timeout": "3000ms",
"cache_ttl": "300s",
"output_encoding": "json",
"name": "googlesearch",
"port": 8080,
"endpoints": [
{
"endpoint": "/v1/googlesearch/{searchParam}",
"method": "GET",
"output_encoding": "json",
"extra_config": {},
"backend": [
{
"sd": "dns",
"url_pattern": "/external-dbs/google/{searchParam}",
"host": [
"google-search-service.service.consul"
],
"disable_host_sanitize": true
}
]
},
]
}
在没有 docker 的情况下,主机google-search-service.service.consul是通过我的 macOS 中的解析器解析的,但是似乎无法在 docker-compose 网络中解析,因此 Krakend 无法将 API 调用重定向到微服务因为找不到领事。
我想知道是否有办法在 docker-compose 中配置解析器或允许 KrakendD 以任何其他方式找到 Consul。
提前谢谢