2

I have a kubernetes cluster with serviceA on namespaceA and serviceB on namespaceB.

I want, from serviceA, use kubernetes service discovery to programmatically list serviceB. I am planning to use spring cloud kubernetes ( @EnableDiscoveryClient ).

However, there is a company wide policy to block the use of the configuration below that should have solved the problem: spring.cloud.kubernetes.discovery.all-namespaces=true

Is there any way to circumvent the problem? Maybe assign serviceB to two different namespaces or some other permission/configuration that I am not aware of?

guilhermecgs
  • 2,913
  • 11
  • 39
  • 69
  • 1
    You want to access a service in different namespace i.e. your eureka server? If so, you can refer the link: https://stackoverflow.com/questions/37221483/service-located-in-another-namespace service-x.namespace-b.svc.cluster.local: - you can try? is what I am guessing. – ARINDAM BANERJEE Dec 03 '19 at 14:18
  • 1
    Very interesting link, thanks! I am not using eureka server, I am planning to use spring cloud kubernetes implementation of discoveryClient. Do you think that it is possible that the discoveryClient find the service located in a different namespace using the externalName parameter? – guilhermecgs Dec 03 '19 at 14:49
  • 1
    Sorry for delay in response, I have did not use it that way, so need to implement to check this out. If you are able to resolve, please let me know. – ARINDAM BANERJEE Dec 04 '19 at 09:07
  • `spring.cloud.kubernetes.discovery.all-namespaces` setting is not mentioned in the link you have provided. Could you please elaborate more on what your problem actually is? – Wytrzymały Wiktor Dec 05 '19 at 11:34
  • 1
    @OhHiMark, sure. Here it is: https://github.com/spring-cloud/spring-cloud-kubernetes#3-discoveryclient-for-kubernetes – guilhermecgs Dec 05 '19 at 12:31

1 Answers1

1

If you are trying to simply look up a service IP by service name through Kubernetes API than it should not really matter if you're doing it through kubectl or a Java client, the options you pass to the API are the same.

The thing that matters however is whether the service name would be looked up in the same namespace only or in all namespaces. Accessing a service from a different namespace can be done by specifying its name along with the namespace - instead of my-service they would need to write my-service.some-namespace.

Services without selectors are also an option to expose a service from one namespace to another so that the namespace would be specified in Kubernetes objects and not in app code.

Please let me know if that helps.

Wytrzymały Wiktor
  • 11,492
  • 5
  • 29
  • 37