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

2024-01-16

这是我的客户端的 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://[email protected] /cdn-cgi/l/email-protection/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

.


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

> spring:   cloud:
>     enabled: true
>     config:
>       uri: http://config-server:8888
>       failFast: true
>       retry:
>         maxAttempts: 20
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

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

随机推荐