Is there a way for services to discovery each other in a stack

For example, we have a cluster with some different components, the must known each other in order to work properly.

Manually maintain the links between each other is a little inconvenience, and may lead some mistake.

AFAIK, rancher is using a DNS to resolve links, so I want to know if there is some way to reach each other by DNS name within one stack automatically, like SkyDNS for k8s and Mesos-DNS for mesosphere.

The following picture shows a small size deployment of a mongo shards cluster as a example.

OK, I find the external-dns can help.
BTW, when it will be shipped in rancher’s officially release?

For your use case, you would need to use selector labels. io.rancher.service.selector.link

http://docs.rancher.com/rancher/labels/#selector-labels

This would allow you to just have the appropriate labels on services and they would automatically get linked.

For external-dns, that is actually for this feature. https://github.com/rancher/rancher/issues/1675

On a related note, different scenario, can I specify what the linked to service should be called?

When I setup a link manually, I can give an alias that it would be known as. Using selector links are great when you have a common “catch all” kind of service, but the trouble is that the other services doesn’t know the name of this service (or rather, it is masquerading as someone else), so I need to have an alias per link in place.

Example:

svc_A talks to ext_B.
svc_X works as (or routes requests to another B service).

now I want svc_A to talk to svc_X (but still using the dns name ext_B), this works when I setup a link to svc_X with an alias of ext_B.

The link can be setup using selectors for the above case in a generic and nice way, except for the alias part. But without the alias, svc_A will continue to talk to ext_B regardless of its link to svc_X. (OK, I’m guessing here, but I couldn’t find anything in the docs that says otherwise, will run some tests too).

Followup question: are selector links supposed to work cross stacks?

I have a dead simple test case, but I can’t see that the link works, in any direction, under any name… (but the two services are not in the same stack).

@kaos to answer your last question - selector links are supposed to work cross stacks. If it doesn’t work - its a bug, please file it under https://github.com/rancher/rancher/issues

To answer your other question - about the way to specify the alias for the service link when target service joins via selector. Our service Alias (service of kind dnsService) might be helpful in this scenario:

  1. Service A talks to service B that is of kind service Alias (dnsService)
  2. Then as your service B is the alias service, you can put any service behind it (either by creating a service link manually, or make service X join alias service B using selector way)

Ah, thank you, that would be the rancher way of doing things (and I have been doing that, but manually as a layer of abstraction, rather than simply aliasing the service, but it works equally well here). Didn’t realize I could use the selector links with alias service in that way.

I’ll file a issue if/when I have a reproducible test case showing the issue with cross stack selectors. Thus far it could be due to something else…