Cloud Foundry Service Registry (Eureka) 失败蓝绿部署和路由路径

Posted

技术标签:

【中文标题】Cloud Foundry Service Registry (Eureka) 失败蓝绿部署和路由路径【英文标题】:Cloud Foundry Service Registry (Eureka) fails Blue-Green deployment & route paths 【发布时间】:2017-08-16 03:16:31 【问题描述】:

在启用 Spring Cloud Services 的情况下,我面临两个与将微服务部署到 Cloud Foundry 相关的问题。 首先,如果我使用 CF 路由路径部署应用程序,似乎将无法注册。我部署这样的应用程序:

cf push -p target/date-services-1.0.jar --hostname env5-date-services --route-path /v1 -f manifest.yml date-services-v1 清单如下所示:

applications:
- name: date-services-v1
  memory: 1024M
  instances: 1
  timeout: 180
  env:
    JBP_CONFIG_OPEN_JDK_MEMORY_CALCULATOR: "[memory_sizes: metaspace: 180m, memory_heuristics: metaspace:  25]"
  services:
  - rabbitmq
  - config-server
  - discovery
  - circuit-breaker
  - mysql

应用程序已被 Eureka 注册,但找不到。如果我从 Eureka 仪表板打开链接,它会被翻译为:

http://example.com/v1:80/info
http://example.com/v1:80/date

这个网址根本无法访问。其他应用程序尝试调用 date-services 微服务并失败并显示“404 not found”。如果我从部署中删除路由路径,一切都很好。

另一个问题是蓝绿部署。

如果我将同一个 jar 部署到一个新的应用名称,例如 date-services-GREEN,那么我在 Eureka 中再次失败:

Thu Mar 23 2017 09:21:16 GMT+0200 (IST) [APP] OUT 2017-03-23 07:21:16.225 ERROR [date-services-sa-v1,,,] 20 --- [tbeatExecutor-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_date-services-SA-V1/pcfdev01-date-services-sa-v1-GREEN.apps.cf.example.com:84e48618-3b11-46e4-7b3e-f638788786ea - was unable to send heartbeat!
Thu Mar 23 2017 09:21:16 GMT+0200 (IST) [APP] OUT at com.netflix.discovery.DiscoveryClient.register(DiscoveryClient.java:815)
Thu Mar 23 2017 09:21:16 GMT+0200 (IST) [APP] OUT at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
Thu Mar 23 2017 09:21:16 GMT+0200 (IST) [APP] OUT 2017-03-23 07:21:16.225 WARN [date-services-sa-v1,,,] 20 --- [tbeatExecutor-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_date-services-SA-V1/pcfdev01-date-services-sa-v1-GREEN.apps.cf.example.com:84e48618-3b11-46e4-7b3e-f638788786ea - registration failed Cannot execute request on any known server
Thu Mar 23 2017 09:21:16 GMT+0200 (IST) [APP] OUT com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
Thu Mar 23 2017 09:21:16 GMT+0200 (IST) [APP] OUT at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:111)
Thu Mar 23 2017 09:21:16 GMT+0200 (IST) [APP] OUT at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56)
Thu Mar 23 2017 09:21:16 GMT+0200 (IST) [APP] OUT at com.netflix.discovery.DiscoveryClient.renew(DiscoveryClient.java:837)
Thu Mar 23 2017 09:21:16 GMT+0200 (IST) [APP] OUT at com.netflix.discovery.DiscoveryClient$HeartbeatThread.run(DiscoveryClient.java:1396)
Thu Mar 23 2017 09:21:16 GMT+0200 (IST) [APP] OUT at java.util.concurrent.FutureTask.run(FutureTask.java:266)
Thu Mar 23 2017 09:21:16 GMT+0200 (IST) [APP] OUT at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
Thu Mar 23 2017 09:21:16 GMT+0200 (IST) [APP] OUT at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
Thu Mar 23 2017 09:21:16 GMT+0200 (IST) [APP] OUT at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.execute(EurekaHttpClientDecorator.java:59)
Thu Mar 23 2017 09:21:16 GMT+0200 (IST) [APP] OUT at java.lang.Thread.run(Thread.java:745)
Thu Mar 23 2017 09:21:16 GMT+0200 (IST) [APP] OUT com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
Thu Mar 23 2017 09:21:16 GMT+0200 (IST) [APP] OUT at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
Thu Mar 23 2017 09:21:16 GMT+0200 (IST) [APP] OUT at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:111)
Thu Mar 23 2017 09:21:16 GMT+0200 (IST) [APP] OUT at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56)
Thu Mar 23 2017 09:21:16 GMT+0200 (IST) [APP] OUT at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77)
Thu Mar 23 2017 09:21:16 GMT+0200 (IST) [APP] OUT at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56)
Thu Mar 23 2017 09:21:16 GMT+0200 (IST) [APP] OUT at java.util.concurrent.FutureTask.run(FutureTask.java:266)
Thu Mar 23 2017 09:21:16 GMT+0200 (IST) [APP] OUT at com.netflix.discovery.DiscoveryClient.register(DiscoveryClient.java:815)
Thu Mar 23 2017 09:21:16 GMT+0200 (IST) [APP] OUT at com.netflix.discovery.DiscoveryClient.renew(DiscoveryClient.java:837)
Thu Mar 23 2017 09:21:16 GMT+0200 (IST) [APP] OUT at com.netflix.discovery.DiscoveryClient$HeartbeatThread.run(DiscoveryClient.java:1396)
Thu Mar 23 2017 09:21:16 GMT+0200 (IST) [APP] OUT at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
Thu Mar 23 2017 09:21:16 GMT+0200 (IST) [APP] OUT at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
Thu Mar 23 2017 09:21:16 GMT+0200 (IST) [APP] OUT at java.lang.Thread.run(Thread.java:745)
Thu Mar 23 2017 09:21:16 GMT+0200 (IST) [APP] OUT 2017-03-23 07:21:16.306 INFO [date-services-sa-v1,,,] 20 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_date-services-SA-V1/pcfdev01-date-services-sa-v1-GREEN.apps.cf.example.com:84e48618-3b11-46e4-7b3e-f638788786ea: registering service...
Thu Mar 23 2017 09:21:16 GMT+0200 (IST) [APP] OUT com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
Thu Mar 23 2017 09:21:16 GMT+0200 (IST) [APP] OUT 2017-03-23 07:21:16.331 WARN [date-services-sa-v1,,,] 20 --- [nfoReplicator-0] c.n.d.s.t.d.RetryableEurekaHttpClient : Request execution failure with status code 403; retrying on another server if available

最终这些错误消失了,但是在完全蓝绿色之后,Eureka 中的注册路线仍然指向 GREEN 而不是原始路线。这当然是无法访问的。

这是我正在运行的命令:

cf push -p artifact.jar --hostname $ENV_NAME-$HOST_NAME-$VERSION_NUMBER-GREEN  -f manifest.yml $TARGET_JOB_NAME-GREEN

cf map-route $TARGET_JOB_NAME-GREEN $DOMAIN --hostname $ENV_NAME-$HOST_NAME-$VERSION_NUMBER

cf delete-route $DOMAIN -f --hostname $ENV_NAME-$HOST_NAME-$VERSION_NUMBER-GREEN

cf rename $TARGET_JOB_NAME-GREEN $TARGET_JOB_NAME

在 Eureka 中注册的最终 URL 是:

http://pcfdev01-date-services-sa-v1-green.cf.example.com/info

在 URL 中使用“绿色”,它根本不起作用。如果我从 URL 中删除“绿色”,它就可以工作。

我试过 Camden.SR6 和 Brixton SR7。 Spring Cloud Services 是 1.4.1.RELEASE。我相信 CF 环境下的运行时是 1.7。

谢谢。

【问题讨论】:

【参考方案1】:

您的环境中安装了哪个版本的 Spring Cloud Services 磁贴?要在同一空间中蓝绿部署应用程序,您必须使用 1.2 或更高版本,请参阅http://docs.pivotal.io/spring-cloud-services/1-2/security-overview.html#service-registry-virtual-hostname-ownership。该部分讨论了跨 PCF 安装的应用程序,但在 PCF 中,您可以让多个应用程序注册为相同的 Eureka 应用程序名/虚拟主机名,前提是它们都在同一个空间中。

关于基于路径的路由的第一个问题,它与 Eureka 开箱即用不兼容。该应用程序将使用主机名+路径(取自 vcap.application.uris)进行注册,该值将进入注册表中的主机名字段。功能区不希望这样:https://github.com/Netflix/ribbon/blob/v2.2.2/ribbon-loadbalancer/src/main/java/com/netflix/loadbalancer/LoadBalancerContext.java#L572 您可以尝试在此处覆盖该行为:https://github.com/spring-cloud/spring-cloud-netflix/blob/v1.3.0.RC1/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonLoadBalancerContext.java

另一种方法可能是使用 Zuul 将 /v1 和 /v2 映射到正确的 Eureka 应用程序,并使用不同的名称注册这些 /v1 和 /v2 应用程序。

【讨论】:

谢谢!是的,在那个特定的环境中,我们仍然使用版本 1.1.1-build 6。我想知道升级是否也能解决第一个问题? 非常感谢。除了路由路径,我将使用不同的方法。

以上是关于Cloud Foundry Service Registry (Eureka) 失败蓝绿部署和路由路径的主要内容,如果未能解决你的问题,请参考以下文章

如何在SAP云平台的Cloud Foundry环境下添加新的Service(服务)

如何在SAP云平台的Cloud Foundry环境下添加新的Service(服务)

Cloud Foundry平台中国唯一云供应商,阿里云持续链接Cloud Foundry/Kuber

Cloud FoundryCould Foundry学习——Could Foundry浅谈

Cloud FoundryCould Foundry学习——核心组件分析

Spring Cloud 数据流与基础 Cloud Foundry 版本的兼容性