<p>I have a StatefulSet that has 2 replicas. I want to create an endpoint to be able to reach any of this replica, passing it hostname id, and in a way that if I scale it to more replicas, the new pods need to be reachable.</p>

<p>I can do this creating an Ingress like this:</p>

<pre><code>apiVersion: voyager.appscode.com/v1beta1
kind: Ingress
metadata:
  name: test-ingress
  namespace: default
spec:
  rules:
  - host: appscode.example.com
    http:
      paths:
      - path: /0
        backend:
          hostNames:
          - web-0
          serviceName: nginx-set
          servicePort: '80'
      - path: /1
        backend:
          hostNames:
          - web-1
          serviceName: nginx-set
          servicePort: '80'

</code></pre>

<p>With this, a <code>GET</code> on <code>appscode.example.com/0</code> will be routed to <code>web-0</code> pod.
But, how can I do this in a dynamic way? If I change the replicas to 3, I will need to manually create a new path route to the pod <code>web-2</code> to be reachable.</p>

fabriciols
<p>You need a program (operator) listening to the Kubernetes API, and patching the ingress resource every time teh number of pods in the statefull set.</p>

<p>Using go:</p>

<ul>
<li>watching a resource: <a href="https://medium.com/programming-kubernetes/building-stuff-with-the-kubernetes-api-part-4-using-go-b1d0e3c1c899" rel="nofollow noreferrer">https://medium.com/programming-kubernetes/building-stuff-with-the-kubernetes-api-part-4-using-go-b1d0e3c1c899</a></li>
<li>patching a resource: <a href="https://dwmkerr.com/patching-kubernetes-resources-in-golang/" rel="nofollow noreferrer">https://dwmkerr.com/patching-kubernetes-resources-in-golang/</a></li>
</ul>
