【问题标题】:Spring Cloud Config Client Actuator RefreshSpring Cloud Config 客户端执行器刷新
【发布时间】:2020-06-12 23:12:33
【问题描述】:

我有一个监听配置服务器的客户端。 Config Server 指向 github。本地主机工作正常。但是,当我将应用程序部署到 Kubernetes 时,用于刷新属性的客户端端点无法正常工作。

端点(发布):http://config-client.sbx.com/actuator/refresh

这会在 Postman "[]" 上返回一个空响应,并且响应代码是 200 OK。我可以看到 Config 服务器已在 K8s 上启动并运行。

有什么可能出错的建议吗?

附:我启用了 DEBUG 日志,但那里没有看到太多信息。

【问题讨论】:

  • kubernetes节点能打到GitHub吗?
  • 是的,我可以从配置服务器上的 Github 获取属性。不知何故无法从在不同 pod 上运行的客户端访问它。然而,这两个 pod 都在 8080 上运行,并且我在客户端的 bootstrap.yml 中添加了该属性,以使执行器在没有 SSL 的情况下进行监听。
  • 您是否尝试在config-client.sbx.com/refresh上请求

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


【解决方案1】:

您能否在刷新时验证应用程序链接是否已获取主机名和应用程序名称。因为在 localhost 中进行刷新时,它只是本地的 springboot 应用程序,因此不需要额外的 application-name 路径。当您通常部署到服务器时,除了主机名之外,我们还必须提供应用程序的路径名。在tomcat中,我使用的网址如下,

http://<hostname>/**<application-name>**/actuator/refresh/

通常,当您通过邮递员访问此 URL 时,它会给您一个 200 响应,其中包含一个空的 [] 正文。然后,您应该能够在客户端应用程序的日志文件中看到以下行。 [我还在应用程序的 main 方法中设置了属性 @RefreshScope 属性,就在 @SpringBootApplication 属性的下方,用于刷新应用程序的属性。]

INFO   o.s.c.c.c.ConfigServicePropertySourceLocator.getRemoteEnvironment:249 - Fetching config from server at : http://<hostname>/<Config-server-application-name>/
INFO   o.s.c.c.c.ConfigServicePropertySourceLocator.log:168 - Located environment: name=config-client, profiles=[development], label=null, version=ab36989c85922f1c9cf7803fac4, state=null
INFO   o.s.c.b.c.PropertySourceBootstrapConfiguration.initialize:112 - Located property source: [BootstrapPropertySource {name='bootstrapProperties-configClient'}, BootstrapPropertySource {name='bootstrapProperties-https://<gitlaburl>/<companyname>/config-server.git/config-client-development.yml'}]
INFO   o.s.boot.SpringApplication.logStartupProfileInfo:655 - The following profiles are active: development
INFO   o.s.boot.SpringApplication.logStarted:61 - Started application in 1.557 seconds (JVM running for 70689.032)

对于 Kubernetes,

尝试使用

kubectl 应用

(而不是 kubectl 创建配置映射。)

要部署配置映射,只需在 Kubernetes 上运行以下命令:

kubectl apply -f config-map.yml

确保配置映射的名称与 Spring Boot 应用程序的名称匹配。另请参阅下面的链接,

https://github.com/spring-cloud/spring-cloud-kubernetes/issues/255

还有一个 spring cloud kuberenetes,您可以如下探索,

https://cloud.spring.io/spring-cloud-static/spring-cloud-kubernetes/2.0.0.M1/reference/html/#why-do-you-need-spring-cloud-kubernetes

【讨论】:

    猜你喜欢
    • 2021-04-13
    • 1970-01-01
    • 2020-07-19
    • 2018-08-28
    • 2016-09-09
    • 2019-03-20
    • 1970-01-01
    • 2020-06-27
    • 1970-01-01
    相关资源
    最近更新 更多