<p>I'm currently using Solr Cloud 6.1, the following behavior can also be observed until 7.0.</p>

<p>I'm trying to create a Solr collection with 5 shards and a replication factor of 2. I have 5 physical servers. Normally, this would distribute all 10 replicas evenly among the available servers. </p>

<p>But, when starting Solr Cloud with a <code>-h</code> (hostname) param to give every Solr instance an individual, but constant hostname, this doesn't work any more. The distribution then looks like this:</p>

<pre><code>solr-0:
wikipedia_shard1_replica1  wikipedia_shard2_replica1  wikipedia_shard3_replica2  wikipedia_shard4_replica1  wikipedia_shard4_replica2

solr-1:

solr-2:
wikipedia_shard3_replica1  wikipedia_shard5_replica1  wikipedia_shard5_replica2

solr-3:
wikipedia_shard1_replica2

solr-4:
wikipedia_shard2_replica2
</code></pre>

<p>I tried using <a href="https://lucene.apache.org/solr/guide/7_0/rule-based-replica-placement.html" rel="nofollow noreferrer">Rule-based Replica Placement</a>, but the rules seem to be ignored.</p>

<p>I need to use hostnames, because Solr runs in a Kubernetes cluster, where IP adresses change frequently and Solr won't find it's cores after a container restart. I first suspected a newer Solr version to be the cause of this, but I narrowed it down to the hostname problem.</p>

<p>Is there any solution for this?</p>

<p>The solution was actually quite simple (but not really documented):</p>

<p>When creating a <code>Service</code> in OpenShift/Kubernetes, all matching Pods get backed by a load balancer. When all Solr instances get assigned an unique hostname, this hostnames would all resolve to one single IP address (that of the load balancer).</p>

<p>Solr somehow can't deal with that and fails to distribute its shards evenly.</p>

<p>The solution is to use <a href="https://kubernetes.io/docs/concepts/services-networking/service/#headless-services" rel="nofollow noreferrer">headless services</a> from Kubernetes. Headless services aren't backed by a load balancer and therefore every hostname resolves to an unique IP address.</p>
