【发布时间】:2018-12-18 19:52:36
【问题描述】:
这是我的客户的 bootstrap.yml
spring:
cloud:
config:
enabled: true
uri: http://localhost:8888
label: master
spring.application:
name: microservices-client
spring.profiles:
active: dev
这是我的 spring 配置服务器 bootstrap.yml
spring:
application:
name: microservices-client
profiles:
active: dev
cloud:
config:
uri: http://localhost:8888
这是我的 spring 配置 application.yml
server:
port: 8888
spring:
cloud:
config:
server:
git:
uri: ssh://git@riscm.company.com/sem/some_repo.git
ignoreLocalSshSettings: true
privateKey: |
-----BEGIN RSA PRIVATE KEY-----
MIIJKgIBAAKCAgEA3iOtvDLAez5Azk6fYt2ApS8smK3mGZVt9Uu/mqsZxijx9hEG
Q4oPHhebR1sX/AstBZAWvcx7O9fb7CfA1/Zsy3x520FbGAEH+rQtiVfafJ27ZfDm
xtiAKzX1bGWVV51WcgCF8A9NcXOqoIF6yXeyGgBmMwHG3vi/Yc0JzqLsqcqLdQ==
-----END RSA PRIVATE KEY-----
endpoints:
health:
sensitive: true
management:
security:
enabled: false
health:
solr:
enabled: false
当我在本地运行配置服务器时,我可以从 Spring Boot 客户端提取值,但当服务器作为 Kubernetes 上的 docker 映像远程运行时则不行。
我在客户端 bootstrap.yml 中发现一个问题,标签应该是 master 而不是 Master! 我继续将微服务部署到 Kubernetes,现在我从 Kubernetes 上的日志客户端收到此错误。当我直接登录到客户端容器时,我没有收到此错误。
2018-07-11 19:20:02.455 INFO 1 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888
2018-07-11 19:20:02.545 INFO 1 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Connect Timeout Exception on Url - http://localhost:8888 . Will be trying the next url if available
2018-07-11 19:20:02.545 WARN 1 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: I/O error on GET request for "http://localhost:8888/microservices-client/dev/master": Connection refused (Connection refused); nested exception is java.net.ConnectException: Connection refused (Connection refused)
2018-07-11 19:20:02.547 INFO 1 --- [ main] com.regen.rest.Application : The following profiles are active: dev
.
【问题讨论】:
-
1.您不需要服务器 bootstrap.yml - 在您的示例中,它几乎是客户端 bootstrap.yml 的副本。但这可能不是它不起作用的原因 2. 8888 端口是否从您的 docker 容器中暴露出来?
-
是的。它暴露了。我可以直接点击它并为这个调用返回正确的数据:192.168.99.100:8888/microservices-client/dev
-
好的。您在微服务客户端控制台中是否有一些例外情况?
-
我已经添加了来自客户端和服务器的日志,见上文。
-
您专门告诉配置客户端在
http://localhost:8888寻找配置服务器。那是行不通的。
标签: spring-boot kubernetes spring-cloud spring-cloud-config