<p>I need to hard code the address of a couchDB instance to another server in my kubernetes cluster. I'm not super familiar with kubernetes but I know that IP will change each time the cluster is rebuilt or the pod is rebuilt. So I can't use that.</p>
<p>What is the URL to this kubernetes service/what should I hard code into my Server Docker Image so it will alway find the CouchDB server in the system. I think it will be in this format</p>
<pre><code>&lt;service-name&gt;.&lt;namespace&gt;.svc.cluster.local:&lt;service-port&gt;
</code></pre>
<p><a href="https://i.stack.imgur.com/c3oIl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/c3oIl.png" alt="Picture of the interface" /></a></p>
<pre><code># YAML for launching the server
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: kino-couch
  labels:
    app: kino-couch
spec:
  serviceName: orderer
  # Single instance of the Orderer Pod is needed
  replicas: 1
  selector:
    matchLabels:
      app: kino-couch
  template:
    metadata:
      labels:
        app: kino-couch
    spec:
      containers:
      - name: kino-couch
        ports:
        - containerPort: 5984
        # Image used
        image: dpacchain/development:dpaccouch
</code></pre>
<p><a href="https://i.stack.imgur.com/EgoLe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EgoLe.png" alt="enter image description here" /></a></p>
<p>If &quot;wget 172.17.0.2:5984&quot; works what should &quot;172.17.0.2&quot; be replaced with</p>
<p>The following is not correct</p>
<p>wget kino-couch-0.couch-service.default.svc.cluster.local:5984</p>
<p>wget kino-couch-0.couch-service.default.svc.cluster.local:5984</p>
<p>wget kino-couch-0.kino-couch.default.svc.cluster.local:5984</p>
<p>wget kino-couch-0.kino-couchdb.default.svc.cluster.local:5984</p>
<p>wget kino-couch-0.kino-couchdb.svc.cluster.local:5984</p>

Some Guy Trying To Do Math
<p>For StatefulSet you need to create a <a href="https://kubernetes.io/docs/concepts/services-networking/service/#headless-services" rel="nofollow noreferrer">Headless service</a> to be responsible for the network identity of the Pods proving stable DNS entries. Notice <code>clusterIP: None</code> in below example.</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: couch-service
  labels:
    app: kino-couch
spec:
  ports:
  - port: 5984
  clusterIP: None
  selector:
    app: kino-couch
</code></pre>
<p>The statefulset need to refer to the above service in <code>serviceName</code>. So the statefulset yaml would look like below</p>
<pre><code># YAML for launching the server
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: kino-couch
  labels:
    app: kino-couch
spec:
  serviceName: couch-service
  # Single instance of the Orderer Pod is needed
  replicas: 1
  selector:
    matchLabels:
      app: kino-couch
  template:
    metadata:
      labels:
        app: kino-couch
    spec:
      containers:
      - name: kino-couch
        ports:
        - containerPort: 5984
        # Image used
        image: dpacchain/development:dpaccouch
</code></pre>
<p>Then as a client you can access it using <code>couch-service.&lt;namespace&gt;.svc.cluster.local:5984</code> to connect to a any of the CouchDB pods.</p>
<p>If you want to connect to a specific pod then use <code>kino-couch-0.couch-service.&lt;namespace&gt;.svc.cluster.local:5984</code>. This is typically needed for connecting the couchDB pods between themselves to create a cluster.</p>
