spring-cloud-kubernetes icon indicating copy to clipboard operation
spring-cloud-kubernetes copied to clipboard

Using ExternalName service type with KubernetesDiscoveryClient

Open ArtyomGabeev opened this issue 6 years ago • 10 comments

Imagine you have a setup when services running in K8S need to access services running outside.

I want to create an ExternalName service:

apiVersion: v1
kind: Service
metadata:
  name: my-service
  namespace: prod
spec:
  type: ExternalName
  externalName: my.service.example.com

After that I should be able to resolve service call http://my-service/doCall into http://my.service.example.com/doCall

So instead of relying only on endpoints in KubernetesDiscoveryClient, check if service type is ExternalName, then return single service instance with hostname: my.service.example.com.

Does it make sense to contribute this enhancement?

ArtyomGabeev avatar Nov 21 '19 11:11 ArtyomGabeev

very much needed feature

is this related? https://github.com/spring-cloud/spring-cloud-kubernetes/issues/344

guilhermecgs avatar Dec 03 '19 16:12 guilhermecgs

I am using Spring Cloud Hoxton.RELEASE (i.e., with Spring Cloud Kubernetes 1.1.0.RELEASE) and the following configuration is not working, so I don't think what you're asking for is covered by #344

ExternalName service:

kind: Service
metadata:
  name: my-service
  namespace: my-namespace
spec:
  type: ExternalName
  externalName: my.service.example.com

My client application is using ribbon with : @FeignClient(name = my-service)

Spring Sloud Kubernetes Ribbon config is: spring.cloud.kubernetes.ribbon.mode : SERVICE

KubernetesServicesServerList reports that it finds the service, but no ribbons:

o.s.b.f.s.DefaultListableBeanFactory     : Autowiring by type from bean name 'ribbonRule' via factory method to bean named 'ribbonClientConfig'
c.netflix.config.ChainedDynamicProperty  : Flipping property: my-service.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean 'ribbonPing'
o.s.b.f.s.DefaultListableBeanFactory     : Autowiring by type from bean name 'ribbonPing' via factory method to bean named 'ribbonClientConfig'
o.s.b.f.s.DefaultListableBeanFactory     : Creating shared instance of singleton bean 'ribbonServerListUpdater'
o.s.b.f.s.DefaultListableBeanFactory     : Autowiring by type from bean name 'ribbonServerListUpdater' via factory method to bean named 'ribbonClientConfig'
o.s.b.f.s.DefaultListableBeanFactory     : Autowiring by type from bean name 'ribbonLoadBalancer' via factory method to bean named 'ribbonClientConfig'
o.s.b.f.s.DefaultListableBeanFactory     : Autowiring by type from bean name 'ribbonLoadBalancer' via factory method to bean named 'ribbonServerList'
o.s.b.f.s.DefaultListableBeanFactory     : Autowiring by type from bean name 'ribbonLoadBalancer' via factory method to bean named 'ribbonServerListFilter'
o.s.b.f.s.DefaultListableBeanFactory     : Autowiring by type from bean name 'ribbonLoadBalancer' via factory method to bean named 'ribbonRule'
o.s.b.f.s.DefaultListableBeanFactory     : Autowiring by type from bean name 'ribbonLoadBalancer' via factory method to bean named 'ribbonPing'
o.s.b.f.s.DefaultListableBeanFactory     : Autowiring by type from bean name 'ribbonLoadBalancer' via factory method to bean named 'ribbonServerListUpdater'
c.netflix.loadbalancer.BaseLoadBalancer  : Client: my-service instantiated a LoadBalancer: DynamicServerListLoadBalancer:{NFLoadBalancer:name=my-service,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:null
c.n.l.DynamicServerListLoadBalancer      : Using serverListUpdater PollingServerListUpdater
o.s.c.k.r.KubernetesServicesServerList   : Found Service[my-service]
o.s.c.k.r.KubernetesServicesServerList   : Did not find any service in ribbon in namespace [my-namespace] for name [my-service] and portName [null]
c.n.l.DynamicServerListLoadBalancer      : DynamicServerListLoadBalancer for client my-service initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=my-service,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:org.springframework.cloud.kubernetes.ribbon.KubernetesServicesServerList@48ffce4d

michaelaplante avatar Dec 11 '19 19:12 michaelaplante

@michaelaplante, not sure about ribbon, but should work with blocking load balancer provided by spring cloud load balancer.

ArtyomGabeev avatar Jan 08 '20 13:01 ArtyomGabeev

With Ribbon, you can consider this: https://github.com/spring-cloud/spring-cloud-kubernetes/pull/512#issuecomment-572561485

digows avatar Jan 09 '20 13:01 digows

We are all for enhancements!

ryanjbaxter avatar Mar 03 '20 21:03 ryanjbaxter

@ryanjbaxter I would like to contribute to this feature.. can you guide me here

muralidharan-rade avatar Jun 24 '20 18:06 muralidharan-rade

That would be great!

I would start by looking at the class KubernetesDiscoveryClient.

ryanjbaxter avatar Jun 24 '20 19:06 ryanjbaxter

@muralidharan-rade there is already a PR open here https://github.com/spring-cloud/spring-cloud-kubernetes/pull/512

ryanjbaxter avatar Jun 24 '20 21:06 ryanjbaxter

@muralidharan-rade there is already a PR open here #512

sure let me work on that

muralidharan-rade avatar Jun 25 '20 07:06 muralidharan-rade

I stumbled across the same problem. Are there still any plans on making this work?

stoetti avatar Apr 30 '21 05:04 stoetti

this is my next thing to take care of, but for the initial phase, I'll add such support for the fabric8 client only (there are other features that will be ported to k8s client in the nearest future, this one included).

imo, such support for ExternalName services should be allowed only by opting into it via a property. The first reason is compatibility: we were not returning such services until now, so we should keep it that way; unless you want this explicitly. The second reason is that this will introduce more calls to the api-server, so having it optional is only reasonable to me.

Otherwise I will present a proposal PR in the upcoming days.

@ryanjbaxter FYI and blessing. thank you.

wind57 avatar Feb 23 '23 10:02 wind57

Agree on the opt in

ryanjbaxter avatar Feb 23 '23 17:02 ryanjbaxter

@ryanjbaxter this can be closed now. thank you.

wind57 avatar Mar 09 '23 08:03 wind57

Lets leave it open until the k8s client implementation is done

ryanjbaxter avatar Mar 09 '23 13:03 ryanjbaxter

this can be closed now as the implementation is both part of fabric8 and k8s-client

wind57 avatar Nov 14 '23 19:11 wind57