Answers: <p>The sample I posted initially works as is:</p>
  <pre><code>apiVersion: traefik.containo.us/v1alpha1
  kind: IngressRoute
  metadata:
    name: my-service-ingress
  spec:
    entryPoints:
      - web
      - websecure
    routes:
      - kind: Rule
        match: Host(`myservice.mycompany.example`)
        services:
          - kind: Service
            name: myservice-node1-clusterip
            passHostHeader: true
            port: 80
          - kind: Service
            name: myservice-node2-clusterip
            passHostHeader: true
            port: 80
          - kind: Service
            name: myservice-node3-clusterip
            passHostHeader: true
            port: 80
          - kind: Service
            name: myservice-node4-clusterip
            passHostHeader: true
            port: 80
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2021-05-16T20:10:38.837Z
Answers: 2021-05-16T20:10:38.837Z
Answers: DogEatDog
Body: <p>I want to be able to load balance several nodes of a backend service represented by <code>ClusterIP</code> services using a <code>traefik.containo.us/v1alpha1</code> ingress. I know that <code>ClusterIP</code> service can load balance easily with deployments and <code>ReplicaSet</code>  but the way this application is designed each node needs to be it's own Deployment as it is a stateful node.</p>
  <p>So I either need a way to have the flow be:</p>
  <pre><code>Ingress --&gt; [ClusterIP-Node1, ClusterIP-Node2, ClusterIP-Node3, ClusterIP-Node4] 
  </code></pre>
  <p>or</p>
  <pre><code>Ingress --&gt; ClusterIP-LoadBalancer --&gt; [ClusterIP-Node1, ClusterIP-Node2, ClusterIP-Node3, ClusterIP-Node4] 
  </code></pre>
  <p>How can I use <code>traefik.containo.us/v1alpha1</code> to automatically loadbalance between these <code>ClusterIP</code> services?</p>
  <p>For example, if I currently have one <code>Ingress</code> for each `ClusterIP, like this:</p>
  <pre><code>...
  apiVersion: traefik.containo.us/v1alpha1
  kind: IngressRoute
  metadata:
    name: my-service-node1-ingress
  spec:
    entryPoints:
      - web
      - websecure
    routes:
      - kind: Rule
        match: Host(`myservice-node1.mycompany.example`)
        services:
          - kind: Service
            name: myservice-node1-clusterip
            passHostHeader: true
            port: 80
  
  ---
  apiVersion: v1
  kind: Service
  metadata:
    name: myservice-node1-clusterip
    labels:
      app: myservice
      tier: backend
      name: myservice-node1
  spec:
    selector:
      app: myservice
      tier: backend
      name: myservice-node1-deployment
    type: ClusterIP
    ports:
      - name: rpc-listener
        protocol: TCP
        port: 80
        targetPort: 8545
  ... N+1
  </code></pre>
  <p>And I want to change that to a single <code>Ingress</code> Point similar to this:</p>
  <pre><code>apiVersion: traefik.containo.us/v1alpha1
  kind: IngressRoute
  metadata:
    name: my-service-ingress
  spec:
    entryPoints:
      - web
      - websecure
    routes:
      - kind: Rule
        match: Host(`myservice.mycompany.example`)
        services:
          - kind: Service
            name: myservice-node1-clusterip
            passHostHeader: true
            port: 80
  </code></pre>
  <p>Is it possible to have the <code>traefik.containo.us/v1alpha1</code> load balance across the services similar to this? I saw something that looked promising on this page in the <a href="https://doc.traefik.io/traefik/v2.1/routing/providers/kubernetes-crd/" rel="nofollow noreferrer">docs</a> that you can have <code>n</code> number of <code>services[n].name</code> for a matching route <code>routes[n].services</code>. Does that mean you can do something similar to the following?</p>
  <pre><code>apiVersion: traefik.containo.us/v1alpha1
  kind: IngressRoute
  metadata:
    name: my-service-ingress
  spec:
    entryPoints:
      - web
      - websecure
    routes:
      - kind: Rule
        match: Host(`myservice.mycompany.example`)
        services:
          - kind: Service
            name: myservice-node1-clusterip
            passHostHeader: true
            port: 80
          - kind: Service
            name: myservice-node2-clusterip
            passHostHeader: true
            port: 80
          - kind: Service
            name: myservice-node3-clusterip
            passHostHeader: true
            port: 80
          - kind: Service
            name: myservice-node4-clusterip
            passHostHeader: true
            port: 80
  </code></pre>
  <p>Also, is there a way to pass the <code>sessionAffinity</code> with it like there are in services <code>sessionAffinity: ClientIP</code>?</p>
  
Tags: <kubernetes><traefik>
Title: How to get traefik ingress to load balance across several ClusterIP services
UserDisplayName: DogEatDog
ThreadText: # How to get traefik ingress to load balance across several ClusterIP services
  
  (Asked by: username_0 on 2021-05-12)
  
  I want to be able to load balance several nodes of a backend service represented by `ClusterIP` services using a `traefik.containo.us/v1alpha1` ingress. I know that `ClusterIP` service can load balance easily with deployments and `ReplicaSet` but the way this application is designed each node needs to be it's own Deployment as it is a stateful node.
  
  So I either need a way to have the flow be:
  
  ```
  Ingress --> [ClusterIP-Node1, ClusterIP-Node2, ClusterIP-Node3, ClusterIP-Node4] 
  
  ```
  
  or
  
  ```
  Ingress --> ClusterIP-LoadBalancer --> [ClusterIP-Node1, ClusterIP-Node2, ClusterIP-Node3, ClusterIP-Node4] 
  
  ```
  
  How can I use `traefik.containo.us/v1alpha1` to automatically loadbalance between these `ClusterIP` services?
  
  For example, if I currently have one `Ingress` for each `ClusterIP, like this:
  
  ```
  ...
  apiVersion: traefik.containo.us/v1alpha1
  kind: IngressRoute
  metadata:
    name: my-service-node1-ingress
  spec:
    entryPoints:
      - web
      - websecure
    routes:
      - kind: Rule
        match: Host(`myservice-node1.mycompany.example`)
        services:
          - kind: Service
            name: myservice-node1-clusterip
            passHostHeader: true
            port: 80
  
  ---
  apiVersion: v1
  kind: Service
  metadata:
    name: myservice-node1-clusterip
    labels:
      app: myservice
      tier: backend
      name: myservice-node1
  spec:
    selector:
      app: myservice
      tier: backend
      name: myservice-node1-deployment
    type: ClusterIP
    ports:
      - name: rpc-listener
        protocol: TCP
        port: 80
        targetPort: 8545
  ... N+1
  
  ```
  
  And I want to change that to a single `Ingress` Point similar to this:
  
  ```
  apiVersion: traefik.containo.us/v1alpha1
  kind: IngressRoute
  metadata:
    name: my-service-ingress
  spec:
    entryPoints:
      - web
      - websecure
    routes:
      - kind: Rule
        match: Host(`myservice.mycompany.example`)
        services:
          - kind: Service
            name: myservice-node1-clusterip
            passHostHeader: true
            port: 80
  
  ```
  
  Is it possible to have the `traefik.containo.us/v1alpha1` load balance across the services similar to this? I saw something that looked promising on this page in the [docs](https://doc.traefik.io/traefik/v2.1/routing/providers/kubernetes-crd/) that you can have `n` number of `services[n].name` for a matching route `routes[n].services`. Does that mean you can do something similar to the following?
  
  ```
  apiVersion: traefik.containo.us/v1alpha1
  kind: IngressRoute
  metadata:
    name: my-service-ingress
  spec:
    entryPoints:
      - web
      - websecure
    routes:
      - kind: Rule
        match: Host(`myservice.mycompany.example`)
        services:
          - kind: Service
            name: myservice-node1-clusterip
            passHostHeader: true
            port: 80
          - kind: Service
            name: myservice-node2-clusterip
            passHostHeader: true
            port: 80
          - kind: Service
            name: myservice-node3-clusterip
            passHostHeader: true
            port: 80
          - kind: Service
            name: myservice-node4-clusterip
            passHostHeader: true
            port: 80
  
  ```
  
  Also, is there a way to pass the `sessionAffinity` with it like there are in services `sessionAffinity: ClientIP`?
  
  **Tags:** kubernetes, traefik
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2021-05-16. Score: 1 | Accepted answer
  
  The sample I posted initially works as is:
  
  ```
  apiVersion: traefik.containo.us/v1alpha1
  kind: IngressRoute
  metadata:
    name: my-service-ingress
  spec:
    entryPoints:
      - web
      - websecure
    routes:
      - kind: Rule
        match: Host(`myservice.mycompany.example`)
        services:
          - kind: Service
            name: myservice-node1-clusterip
            passHostHeader: true
            port: 80
          - kind: Service
            name: myservice-node2-clusterip
            passHostHeader: true
            port: 80
          - kind: Service
            name: myservice-node3-clusterip
            passHostHeader: true
            port: 80
          - kind: Service
            name: myservice-node4-clusterip
            passHostHeader: true
            port: 80
  
  ```
  
  
  ---
  
  