无法从Kubernetes中的Spring Boot客户端从远程Spring配置中获取值 [英] Can not fetch values from remote spring config from spring boot client in Kubernetes

查看:330
本文介绍了无法从Kubernetes中的Spring Boot客户端从远程Spring配置中获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我客户的bootstrap.yml

Here's my bootstrap.yml of my client

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

spring.application:
    name: microservices-client

spring.profiles:
    active: dev

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

Here's my spring config server bootstrap.yml

spring:
  application:
    name: microservices-client

  profiles:
    active: dev

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

这是我的spring config application.yml

And here's my 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映像远程运行时,则不能.

When I run the config server locally I can pull values from spring boot client, but not when the server runs remotely as a docker image on Kubernetes.

我在客户端bootstrap.yml中发现了一个问题,标签应该是 master 而不是 Master ! 我继续将微服务部署到Kubernetes,现在我从Kubernetes的日志客户端收到此错误.直接登录到客户端容器时,我没有收到此错误.

I found one problem in client bootstrap.yml the label should be master and not Master! I went ahead and deployed the microservices to Kubernetes and now I'm getting this error from the log client on Kubernetes. I'm not getting this error when I login directly into the client container.

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

.

推荐答案

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

Please add bellow configuration to bootstrap.xml. I can fixed this issue by putting below configuration.

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

这篇关于无法从Kubernetes中的Spring Boot客户端从远程Spring配置中获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆