codecamp

Spring Cloud Ribbon在Kubernetes中发现

Spring Cloud调用微服务的客户端应用程序应该对依靠客户端负载平衡功能感兴趣,以便自动发现它可以在哪个端点到达给定服务。该机制已在 spring-cloud-kubernetes-ribbon 项目中实现,其中Kubernetes客户端填充Ribbon ServerList,其中包含有关此类端点的信息。

该实现是以下启动器的一部分,可以通过将其依赖项添加到pom文件中来使用该实现:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-kubernetes-ribbon</artifactId>
    <version>${latest.version}</version>
</dependency>

填充端点列表后,Kubernetes客户端通过匹配Ribbon Client批注中定义的服务名称来搜索位于当前名称空间或项目中的已注册端点,如下所示:

@RibbonClient(name = "name-service")

您可以使用以下格式,在application.properties中(通过应用程序专用的ConfigMap)提供属性,以配置Ribbon的行为:<name of your service>.ribbon.<Ribbon configuration key>,其中:

  • <name of your service>对应于您在Ribbon上访问的服务名称,该名称是使用@RibbonClient批注配置的(例如上例中的name-service)。
  • <Ribbon configuration key> Ribbon的CommonClientConfigKey 定义的Ribbon配置键之一

此外,spring-cloud-kubernetes-ribbon项目定义了两个附加的配置键,以进一步控制Ribbon与Kubernetes的交互方式。特别是,如果端点定义了多个端口,则默认行为是使用找到的第一个端口。要更具体地选择在多端口服务中使用哪个端口,可以使用【7 /】键。 如果您想指定应在哪个Kubernetes命名空间中查找目标服务,则可以使用KubernetesNamespace键,在这两个实例中都记住要为这些键加上您的服务名和ribbon前缀(如前所述)。

以下示例使用此模块进行功能区发现:

您可以通过在应用程序属性文件中设置spring.cloud.kubernetes.ribbon.enabled=false键来禁用Ribbon发现客户端。
Spring Cloud PropertySource重新加载
Spring Cloud Kubernetes配置文件自动配置
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

三、Spring Cloud Netflix

SpringCloud Hystrix超时和Ribbon客户

SpringCloud 重试失败的请求

五、Spring Cloud Stream

六、SpringCloud Binder实现

SpringCloud 重试RabbitMQ Binder

SpringCloud Dead-Letter队列处理

八、Spring Cloud Sleuth

SpringCloud 当前Span

十二、Spring Cloud for Cloud Foundry

十三、Spring Cloud Contract

Spring Cloud Contract验证程序设置

SrpingCloud Gradle项目

十五、Spring Cloud网关

Spring Cloud 配置路由谓词工厂和网关过滤工厂

Spring Cloud TLS / SSL

Spring Cloud网关配置

SpringCloud 故障排除

十八、Spring Cloud GCP

Spring Cloud GCP Spring资源

Spring Cloud Spring JDBC

Spring Cloud Redis的Cloud Memorystore

Spring Cloud 云身份识别代理(IAP)身份验证

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }