【问题标题】:is spring cloud kubernetes support spring cloud loadbalancer?Spring Cloud Kubernetes 支持 Spring Cloud 负载均衡器吗?
【发布时间】:2020-10-06 23:01:38
【问题描述】:

Spring Cloud Kubernetes 是否支持 Spring Cloud Loadbalancer?

我将在 Kubernetes 上部署 Spring Boot 应用程序,并通过以下链接使用 Ribbon 客户端执行客户端负载平衡https://cloud.spring.io/spring-cloud-static/spring-cloud-kubernetes/2.0.0.M1/reference/html/#ribbon-discovery-in-kubernetes

我想使用新的 Spring 云负载均衡器而不是 Ribbon 客户端。

【问题讨论】:

    标签: spring-cloud-kubernetes


    【解决方案1】:

    是的,确实如此。 一个完整的例子可以在这里找到 - https://github.com/dhananjay12/spring-microservices-using-spring-kubernetes

    基本上,跟随依赖就可以了

    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-kubernetes</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-loadbalancer</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
      <exclusions>
        <exclusion>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-starter-netflix-archaius</artifactId>
        </exclusion>
        <exclusion>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
        </exclusion>
        <exclusion>
          <groupId>com.netflix.ribbon</groupId>
          <artifactId>ribbon-eureka</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    

    【讨论】:

      【解决方案2】:

      我迟到了,但我想分享对 Spring Cloud LoadBalancer 的支持已添加到 Spring Cloud Kubernetes last year 中,它就像一个魅力。从 Spring Cloud 2020.0 开始。 (又名 Ilford),它是默认的客户端负载均衡器,因此 您不再需要排除功能区

      我建议在您的项目中包含 org.springframework.cloud:spring-cloud-starter-kubernetes-client-all 依赖项,以利用 Spring Cloud Kubernetes 启用的所有细节。

      在 Kubernetes 上使用 Spring Cloud LoadBalancer 的最典型方式是使用服务发现。如果您的类路径中有任何 DiscoveryClient,则默认的 Spring Cloud LoadBalancer 配置使用它来检查服务实例。因此,它只会从已启动并正在运行的实例中进行选择。所需要做的就是使用 @EnableDiscoveryClient 注释您的 Spring Boot 应用程序以启用 K8s-native 服务发现

      您可以在 Spring Cloud Kubernetes documentation 上阅读有关它的更多信息。

      【讨论】:

        猜你喜欢
        • 2022-01-18
        • 2021-12-31
        • 1970-01-01
        • 2019-08-22
        • 2016-10-07
        • 2019-04-28
        • 2023-04-10
        • 2016-03-29
        • 2021-10-22
        相关资源
        最近更新 更多