6

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.

I can do this creating an Ingress like this:

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'

With this, a GET on appscode.example.com/0 will be routed to web-0 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 web-2 to be reachable.

fabriciols
  • 959
  • 1
  • 12
  • 25
  • This is not the task of ingress but the service to distribute the requests amongst the pod, could you show us the service definition ? – Kartoch Apr 03 '20 at 19:15
  • today it has no service attached... can you show me an example of how to do this using a service? – fabriciols Apr 03 '20 at 20:44
  • Are you sure ? Because the ingress points to a service calls "nginx-set" in the default namespace. If you don't have service, you couldn't access `web-0` using `appscode.example.com/0` – Kartoch Apr 04 '20 at 11:27
  • this is an example created just to try to explain my problem... So, how can I do this using service? – fabriciols Apr 04 '20 at 17:59

1 Answers1

2

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.

Using go:

Kartoch
  • 7,610
  • 9
  • 40
  • 68
  • but it will load balance the connection right? if yes, I need something different, I need to be able to connect to a specific pod – fabriciols Apr 04 '20 at 18:29