title: How to select a specific pod for a service in Kubernetes
body: <p>I have a kubernetes cluster of 3 hosts where each Host has a unique id label. 
  On this cluster, there is a software that has 3 instances (replicas).</p>
  
  <p>Each replica requires to talk to all other replicas. In addition, there is a service that contains all pods so that this application is permanently available.</p>
  
  <p>So I have:</p>
  
  <pre><code>Instance1 (with labels run: theTool,instanceid: 1)
  Instance2 (with labels run: theTool,instanceid: 2)
  Instance3 (with labels run: theTool,instanceid: 3)
  </code></pre>
  
  <p>and</p>
  
  <pre><code>Service1 (selecting pods with label instanceid=1)
  Service2 (selecting pods with label instanceid=2)
  Service3 (selecting pods with label instanceid=3)
  Service (selecting pods with label run=theTool)
  </code></pre>
  
  <p>This approach works but have I cannot scale or use the rolling-update feature.</p>
  
  <p>I would like to define a deployment with 3 replicas, where each replicate gets a unique generic label (for instance the replica-id like 1/3, 2/3 and so on).</p>
  
  <p>Within the services, I could use the selector to fetch this label which will exist even after an update.</p>
  
  <p>Another solution might be to select the pod/deployment, depending on the host where it is running on. I could use a DaemonSet or just a pod/deployment with affinity to ensure that each host has an exact one replica of my deployment.</p>
  
  <p>But I didn't know how to select a pod based on a host label where it runs on.</p>
  
  <p>Using the hostname is not an option as hostnames will change in different environments.</p>
  
  <p>I have searched the docs but didn't find anything matching this use case. Hopefully, someone here has an idea how to solve this.</p>