Kubernetes Services Discovery - Cross Namespace

风流意气都作罢 提交于 2020-01-16 08:36:29

问题


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?


回答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.



来源:https://stackoverflow.com/questions/59157447/kubernetes-services-discovery-cross-namespace

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!