Reputation: 91608
Let's say I have a Service Fabric Cluster with 5 nodes. On one of these nodes, I run a service called Cache:
<Service Name="Cache" ServicePackageActivationMode="ExclusiveProcess">
<StatelessService ServiceTypeName="CacheType" InstanceCount="1">
<SingletonPartition />
</StatelessService>
</Service>
CacheType is some Docker container that exposes port 8080 and provides some internal service for my app. In this situation, I just want one of them, so I set the InstanceCount to 1. When I deploy my app to the cluster, App Fabric will pick out one node to install "Cache" on. My question is how can my app find out what node that is so it can connect to it?
I did find there's a Hostname
attribute on the <ContainerHostPolicies>
node, so I can do something like this:
<ContainerHostPolicies CodePackageRef="Code" Hostname="Cache">
Now, from within a Docker container I can PING Cache
and connect to the container running my service. This is great, however it only works if I happen to be on the same node. If I'm on Node 1 and my Cache service is running on Node 3, this doesn't work.
There's an example here, which is a Voting Booth app which kinda does what I'm looking for. What they do is setup a separate load balancer pool which maps some public IP address to a backend pool of voting services. Then, the app can just connect to that single public IP address. However, in my case I need this to be a completely internal thing where my Cache service is not reachable anywhere outside the cluster's virtual network. I'd also rather avoid the overhead of a load balancer.
Another idea is to use some sort of placement constraint to say "Hey I only want this service installed on a node with this DNS name" or something, but that seems rather hacky. Is there a recommended approach to this?
Upvotes: 0
Views: 505
Reputation: 969
You can setup a DNS name for the service.
Here is an example from the docs:
In ApplicationManifest.xml
.
<Service Name="Stateless1" ServiceDnsName="service1.application1">
<StatelessService ServiceTypeName="Stateless1Type" InstanceCount="[Stateless1_InstanceCount]">
<SingletonPartition />
</StatelessService>
</Service>
If your service uses partitioning schema then you should follow this guideline to make sure it will resolve them correctly.
Upvotes: 2