question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The problem occurs when you have two or more namespaces, where the service name is the same

See original GitHub issue

The problem occurs when you have two or more namespaces, where the service name is the same. Example: service ‘price’ is in namespaces ns1 and ns2 in the same cluster kubernetes.

xxx-service.yaml

metadata:
   namespace: ns1
   name: price
   labels:
       app: price
       group.department: dept1

yyy-service.yaml

metadata:
  namespace: ns2
  name: price
  labels:
      app: price
      group.department: dept2
	  

app-discovery.yaml

spring:
  cloud:
    kubernetes:
	discovery:
	  service-labels:
	  - group.department: dept1

In this case, the current code returns the endpoints of both namespaces, which is not expected. To resolve this issue you have to apply the service-labels filter, .withLabels(serviceLabels).

spring-cloud-kubernetes, version:1.0.4.BUILD-SNAPSHOT

package org.springframework.cloud.kubernetes.discovery;
public class KubernetesDiscoveryClient implements DiscoveryClient {
  ...
	@Override
	public List<ServiceInstance> getInstances(String serviceId) {
		...
		// bug
		// List<Endpoints> endpointsList = this.properties.isAllNamespaces()
		//	? this.client.endpoints().inAnyNamespace().withField("metadata.name", serviceId).list().getItems()
		//	: Collections.singletonList(this.client.endpoints().withName(serviceId).get());

		//adjusted
		Map<String, String> serviceLabels = properties.getServiceLabels();
		List<Endpoints> endpointsList = properties.isAllNamespaces() ?
				client.endpoints().inAnyNamespace().withField("metadata.name", serviceId).withLabels(serviceLabels).list().getItems()
				: Collections.singletonList(client.endpoints().withName(serviceId).get());
	}			
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
m-kaycommented, Dec 17, 2019

I think there is not only a problem with the serivce label filter but more a general problem when spring.cloud.kubernetes.discovery.all-namespaces is set to true. Since in Kubernetes you can access the services by <namespace>.<service-name> this should also be reflected in the serviceId of the discovery client. I’m facing the problem in Spring Boot Admin where services with the same name but in different namespaces are shown as one service.

0reactions
junneyangcommented, Sep 17, 2020

In the discovery client you can now get the namespace information from each service instace with KubernetesServiceInstance#getNamespace(), if spring.cloud.kubernetes.discovery.all-namespaces is set to true.

so, how can i set the route, i want proxy request to someservice.namespaceA and someservice.namespaceB from different path(eg: /someservice.namespaceA/**, and /someservice.namespaceB/**)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Having issue with multiple controllers of the same name in my ...
Multiple types were found that match the controller named 'Home'. This can happen if the route that services this request ('Home/{action}/{id}') ...
Read more >
Namespaces - IBM
A namespace is a logical container in which all the names are unique; that is, a name can appear in multiple namespaces but...
Read more >
Namespaces - Kubernetes
Namespaces are a way to divide cluster resources between multiple users (via resource quota). It is not necessary to use multiple namespaces to ......
Read more >
Disjoint Namespace - Microsoft Learn
A disjoint namespace occurs when one or more domain member computers have a primary Domain Name Service (DNS) suffix that does not match...
Read more >
Kubernetes best practices: Specifying Namespaces in YAML
You can think of a Namespace as a virtual cluster inside your Kubernetes cluster. You can have multiple namespaces inside a single Kubernetes ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found