【问题标题】:Can not fetch values from remote spring config from spring boot client in Kubernetes无法从 Kubernetes 中的 Spring Boot 客户端从远程 Spring 配置中获取值
【发布时间】: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 中发现一个问题,标签应该是 ma​​ster 而不是 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


【解决方案1】:

请将以下配置添加到 bootstrap.xml。我可以通过下面的配置来解决这个问题。

> spring:   cloud:
>     enabled: true
>     config:
>       uri: http://config-server:8888
>       failFast: true
>       retry:
>         maxAttempts: 20

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2019-05-19
  • 2018-08-10
  • 2020-05-02
  • 2021-12-10
  • 2016-04-15
  • 1970-01-01
  • 2018-12-05
  • 1970-01-01
相关资源
最近更新 更多