Ingress sharding in OKD

    Ingress sharding is useful in cases where you want to load balance incoming traffic across multiple Ingress Controllers, when you want to isolate traffic to be routed to a specific Ingress Controller, or for a variety of other reasons described in the next section.

    By default, each route uses the default domain of the cluster. However, routes can be configured to use the domain of the router instead. For more information, see Creating a route for Ingress Controller Sharding.

    You can use Ingress sharding, also known as router sharding, to distribute a set of routes across multiple routers by adding labels to routes, namespaces, or both. The Ingress Controller uses a corresponding set of selectors to admit only the routes that have a specified label. Each Ingress shard comprises the routes that are filtered using a given selection expression.

    As the primary mechanism for traffic to enter the cluster, the demands on the Ingress Controller can be significant. As a cluster administrator, you can shard the routes to:

    • Balance Ingress Controllers, or routers, with several routes to speed up responses to changes.

    • Allocate certain routes to have different reliability guarantees than other routes.

    • Allow certain Ingress Controllers to have different policies defined.

    • Allow only specific routes to use additional features.

    • Expose different routes on different addresses so that internal and external users can see different routes, for example.

    • Transfer traffic from one version of an application to another during a blue green deployment.

    When Ingress Controllers are sharded, a given route is admitted to zero or more Ingress Controllers in the group. A route’s status describes whether an Ingress Controller has admitted it or not. An Ingress Controller will only admit a route if it is unique to its shard.

    An Ingress Controller can use three sharding methods:

    • Adding only a namespace selector to the Ingress Controller, so that all routes in a namespace with labels that match the namespace selector are in the Ingress shard.

    • Adding only a route selector to the Ingress Controller, so that all routes with labels that match the route selector are in the Ingress shard.

    • Adding both a namespace selector and route selector to the Ingress Controller, so that routes with labels that match the route selector in a namespace with labels that match the namespace selector are in the Ingress shard.

    With sharding, you can distribute subsets of routes over multiple Ingress Controllers. These subsets can be non-overlapping, also called traditional sharding, or overlapping, otherwise known as overlapped sharding.

    An Ingress Controller finops-router is configured with the label selector spec.namespaceSelector.matchLabels.name set to finance and ops:

    Example YAML definition for finops-router

    A second Ingress Controller dev-router is configured with the label selector spec.namespaceSelector.matchLabels.name set to dev:

    Example YAML definition for dev-router

    1. apiVersion: v1
    2. items:
    3. - apiVersion: operator.openshift.io/v1
    4. kind: IngressController
    5. metadata:
    6. name: dev-router
    7. namespace: openshift-ingress-operator
    8. spec:
    9. namespaceSelector:
    10. matchLabels:
    11. name: dev

    If all application routes are in separate namespaces, each labeled with name:finance, name:ops, and name:dev respectively, this configuration effectively distributes your routes between the two Ingress Controllers. OKD routes for console, authentication, and other purposes should not be handled.

    In the above scenario, sharding becomes a special case of partitioning, with no overlapping subsets. Routes are divided between router shards.

    Overlapped sharding example

    In addition to finops-router and dev-router in the example above, you also have devops-router, which is configured with the label selector spec.namespaceSelector.matchLabels.name set to dev and ops:

    Example YAML definition for devops-router

    1. apiVersion: v1
    2. items:
    3. - apiVersion: operator.openshift.io/v1
    4. kind: IngressController
    5. metadata:
    6. name: devops-router
    7. namespace: openshift-ingress-operator
    8. spec:
    9. namespaceSelector:
    10. matchLabels:
    11. name:
    12. - dev
    13. - ops

    The routes in the namespaces labeled name:dev and name:ops are now serviced by two different Ingress Controllers. With this configuration, you have overlapping subsets of routes.

    After creating a new Ingress shard, there might be routes that are admitted to your new Ingress shard that are also admitted by the default Ingress Controller. This is because the default Ingress Controller has no selectors and admits all routes by default.

    You can restrict an Ingress Controller from servicing routes with specific labels using either namespace selectors or route selectors. The following procedure restricts the default Ingress Controller from servicing your newly sharded finance, ops, and dev, routes using a namespace selector. This adds further isolation to Ingress shards.

    You must keep all of OKD’s administration routes on the same Ingress Controller. Therefore, avoid adding additional selectors to the default Ingress Controller that exclude these essential routes.

    Prerequisites

    • You installed the OpenShift CLI (oc).

    • You are logged in as a project administrator.

    Procedure

    1. Modify the default Ingress Controller by running the following command:

      1. $ oc edit ingresscontroller -n openshift-ingress-operator default
    2. Edit the Ingress Controller to contain a namespaceSelector that excludes the routes with any of the finance, , and dev labels:

      1. apiVersion: v1
      2. items:
      3. kind: IngressController
      4. metadata:
      5. name: default
      6. namespace: openshift-ingress-operator
      7. spec:
      8. namespaceSelector:
      9. matchExpressions:
      10. - key: type
      11. operator: NotIn
      12. values:
      13. - finance
      14. - ops
      15. - dev

    The default Ingress Controller will no longer serve the namespaces labeled name:finance, name:ops, and name:dev.

    Ingress sharding and DNS

    The cluster administrator is responsible for making a separate DNS entry for each router in a project. A router will not forward unknown routes to another router.

    Consider the following example:

    • Router A lives on host 192.168.0.5 and has routes with *.foo.com.

    • Router B lives on host 192.168.1.9 and has routes with *.example.com.

    Separate DNS entries must resolve *.foo.com to the node hosting Router A and *.example.com to the node hosting Router B:

    • *.foo.com A IN 192.168.0.5

    • *.example.com A IN 192.168.1.9

    Ingress Controller sharding by using route labels means that the Ingress Controller serves any route in any namespace that is selected by the route selector.

    Figure 1. Ingress sharding using route labels

    Ingress Controller sharding is useful when balancing incoming traffic load among a set of Ingress Controllers and when isolating traffic to a specific Ingress Controller. For example, company A goes to one Ingress Controller and company B to another.

    Procedure

    1. Edit the router-internal.yaml file:

      1. # cat router-internal.yaml
      2. apiVersion: v1
      3. items:
      4. - apiVersion: operator.openshift.io/v1
      5. kind: IngressController
      6. metadata:
      7. name: sharded
      8. namespace: openshift-ingress-operator
      9. spec:
      10. domain: <apps-sharded.basedomain.example.net> (1)
      11. nodePlacement:
      12. nodeSelector:
      13. matchLabels:
      14. node-role.kubernetes.io/worker: ""
      15. routeSelector:
      16. matchLabels:
      17. type: sharded
      18. status: {}
      19. kind: List
      20. metadata:
      21. resourceVersion: ""
      22. selfLink: ""
    2. Apply the Ingress Controller router-internal.yaml file:

      The Ingress Controller selects routes in any namespace that have the label type: sharded.

    3. Create a new route using the domain configured in the router-internal.yaml:

      1. $ oc expose svc <service-name> --hostname <route-name>.apps-sharded.basedomain.example.net

    Configuring Ingress Controller sharding by using namespace labels

    A diagram showing multiple Ingress Controllers with different namespace selectors serving routes that belong to the namespace containing a label that matches a given namespace selector

    Figure 2. Ingress sharding using namespace labels

    Ingress Controller sharding is useful when balancing incoming traffic load among a set of Ingress Controllers and when isolating traffic to a specific Ingress Controller. For example, company A goes to one Ingress Controller and company B to another.

    Procedure

    1. Edit the router-internal.yaml file:

      1. # cat router-internal.yaml

      Example output

      1. apiVersion: v1
      2. items:
      3. kind: IngressController
      4. name: sharded
      5. namespace: openshift-ingress-operator
      6. spec:
      7. domain: <apps-sharded.basedomain.example.net> (1)
      8. nodePlacement:
      9. nodeSelector:
      10. matchLabels:
      11. node-role.kubernetes.io/worker: ""
      12. namespaceSelector:
      13. matchLabels:
      14. type: sharded
      15. status: {}
      16. kind: List
      17. metadata:
      18. resourceVersion: ""
      19. selfLink: ""
      1Specify a domain to be used by the Ingress Controller. This domain must be different from the default Ingress Controller domain.
    2. Apply the Ingress Controller router-internal.yaml file:

      1. # oc apply -f router-internal.yaml

      The Ingress Controller selects routes in any namespace that is selected by the namespace selector that have the label type: sharded.

    3. Create a new route using the domain configured in the router-internal.yaml:

      1. $ oc expose svc <service-name> --hostname <route-name>.apps-sharded.basedomain.example.net

    A route allows you to host your application at a URL. In this case, the hostname is not set and the route uses a subdomain instead. When you specify a subdomain, you automatically use the domain of the Ingress Controller that exposes the route. For situations where a route is exposed by multiple Ingress Controllers, the route is hosted at multiple URLs.

    The following procedure describes how to create a route for Ingress Controller sharding, using the hello-openshift application as an example.

    Ingress Controller sharding is useful when balancing incoming traffic load among a set of Ingress Controllers and when isolating traffic to a specific Ingress Controller. For example, company A goes to one Ingress Controller and company B to another.

    Prerequisites

    • You installed the OpenShift CLI (oc).

    • You are logged in as a project administrator.

    • You have a web application that exposes a port and an HTTP or TLS endpoint listening for traffic on the port.

    • You have configured the Ingress Controller for sharding.

    Procedure

    1. Create a project called hello-openshift by running the following command:

    2. Create a pod in the project by running the following command:

      1. $ oc create -f https://raw.githubusercontent.com/openshift/origin/master/examples/hello-openshift/hello-pod.json
    3. Create a service called hello-openshift by running the following command:

      1. $ oc expose pod/hello-openshift
    4. Create a route definition called hello-openshift-route.yaml:

      YAML definition of the created route for sharding:

      1. apiVersion: route.openshift.io/v1
      2. kind: Route
      3. metadata:
      4. labels:
      5. type: sharded (1)
      6. name: hello-openshift-edge
      7. namespace: hello-openshift
      8. spec:
      9. subdomain: hello-openshift (2)
      10. tls:
      11. termination: edge
      12. to:
      13. kind: Service
      14. name: hello-openshift
    5. Use hello-openshift-route.yaml to create a route to the hello-openshift application by running the following command:

      1. $ oc -n hello-openshift create -f hello-openshift-route.yaml

    Verification

    • Get the status of the route with the following command:

      1. $ oc -n hello-openshift get routes/hello-openshift-edge -o yaml

      Example output

      1The hostname the Ingress Controller, or router, uses to expose the route. The value of the host field is automatically determined by the Ingress Controller, and uses its domain. In this example, the domain of the Ingress Controller is .
      2The hostname of the Ingress Controller.
      3The name of the Ingress Controller. In this example, the Ingress Controller has the name sharded.