<p>I am looking to have a dynamic <code>etcd</code> cluster running inside my k8s cluster. The best way I can think of doing it dynamically (no hardcoded addresses, names, etc.) is to use DNS discovery, with the internal k8s DNS (CoreDNS).</p>

<p>I find detached information about <code>SRV</code> records created for services in k8s, and some explanations on how <code>etcd</code> DNS discovery works, but no complete howto.</p>

<p>For example:</p>

<ul>
<li>how does k8s name <code>SRV</code> entries?</li>
<li>should they be named with a specific way for <code>etcd</code> to be able to find them?</li>
<li>should any special CoreDNS setting be set?</li>
</ul>

<p>Any help on that would be greatly appreciated.</p>

<p>references:</p>

<ul>
<li><a href="https://coreos.com/etcd/docs/latest/v2/clustering.html#dns-discovery" rel="nofollow noreferrer">https://coreos.com/etcd/docs/latest/v2/clustering.html#dns-discovery</a></li>
<li><a href="https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/</a></li>
</ul>

Ehud Kaldor
<blockquote>
  <p>how does k8s name SRV entries?</p>
</blockquote>

<p>via the <code>Service.port[].name</code>, which is why almost everything in kubernetes has to be a DNS-friendly name: because a lot of times, it does put them in DNS for you.</p>

<p>A Pod that has <code>dig</code> or a new enough <code>nslookup</code> will then show you:</p>

<pre><code>$ dig SRV kubernetes.default.svc.cluster.local.
</code></pre>

<p>and you'll see the names of the ports that the <code>kubernetes</code> <code>Service</code> is advertising.</p>

<blockquote>
  <p>should they be named with a specific way for etcd to be able to find them?</p>
</blockquote>

<p>Yes, as one can see in the page you linked to, they need to be named one of these four:</p>

<ul>
<li><code>_etcd-client</code></li>
<li><code>_etcd-client-ssl</code></li>
<li><code>_etcd-server</code></li>
<li><code>_etcd-server-ssl</code></li>
</ul>

<p>so something like this on the kubernetes side:</p>

<pre><code>ports:
- name: etcd-client
  port: 2379
  containerPort: whatever
- name: etcd-server
  port: 2380
  containerPort: whatever
</code></pre>
