The problem occurs when you have two or more namespaces, where the service name is the same
See original GitHub issueThe 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:
- Created 4 years ago
- Comments:10 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.so, how can i set the route, i want proxy request to
someservice.namespaceA
andsomeservice.namespaceB
from different path(eg:/someservice.namespaceA/**
, and/someservice.namespaceB/**
)