4
votes

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.

1
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
today it has no service attached... can you show me an example of how to do this using a service?fabriciols
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/0Kartoch
this is an example created just to try to explain my problem... So, how can I do this using service?fabriciols

1 Answers

1
votes

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: