无法从Kubernetes中的Spring Boot客户端从远程Spring配置中获取值

时间:2018-07-10 21:31:47

标签: spring-boot kubernetes spring-cloud spring-cloud-config

这是我客户的bootstrap.yml

spring:
  cloud:
    config:
      enabled: true
      uri: http://localhost:8888
      label: master

spring.application:
    name: microservices-client

spring.profiles:
    active: dev

这是我的春季配置服务器bootstrap.yml

spring:
  application:
    name: microservices-client

  profiles:
    active: dev

  cloud:
    config:
      uri: http://localhost:8888

这是我的spring config 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 个答案:

答案 0 :(得分:0)

请将波纹管配置添加到bootstrap.xml中。我可以通过以下配置解决此问题。

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