Skip to content

Router sharding example

Create a new router shared

Take all routes with label type=sharded

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
oc create -f - <<EOF
apiVersion: operator.openshift.io/v1
kind: IngressController
metadata:
  name: sharded
  namespace: openshift-ingress-operator
spec:
  domain: external.demo.openshift.pub
  endpointPublishingStrategy: 
    type: NodePortService
  nodePlacement:
    nodeSelector:
      matchLabels:
        node-role.kubernetes.io/worker: ""
  routeSelector:
    matchLabels:
      type: sharded
status: {}
EOF

Adjust default router to skip type: sharded

1
2
3
4
5
oc patch \
  -n openshift-ingress-operator \
  IngressController/default \
  --type='merge' \
  -p '{"spec":{"routeSelector":{"matchExpressions":[{"key":"type","operator":"NotIn","values":["sharded"]}]}}}'  

Dummy routes

1
2
3
4
oc new-project demo
oc create service clusterip dummy --tcp=8080:8080
oc expose svc/dummy -l type=sharded --name dummy-shared
oc expose svc/dummy --name dummy-default

Check routes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
$ oc describe route -n demo dummy-default
Name:           dummy-default
Namespace:      demo
Created:        2 minutes ago
Labels:         app=dummy
Annotations:        openshift.io/host.generated=true
Requested Host:     dummy-default-demo.apps.demo.openshift.pub
              exposed on router default (host apps.demo.openshift.pub) 2 minutes ago
Path:           <none>
TLS Termination:    <none>
Insecure Policy:    <none>
Endpoint Port:      8080-8080

Service:    dummy
Weight:     100 (100%)
Endpoints:  <none>

$ oc describe route -n demo dummy-shared
Name:           dummy-shared
Namespace:      demo
Created:        3 minutes ago
Labels:         type=sharded
Annotations:        openshift.io/host.generated=true
Requested Host:     dummy-shared-demo.apps.demo.openshift.pub
              exposed on router sharded (host external.demo.openshift.pub) 2 minutes ago
Path:           <none>
TLS Termination:    <none>
Insecure Policy:    <none>
Endpoint Port:      8080-8080

Service:    dummy
Weight:     100 (100%)
Endpoints:  <none>



$ oc rsh -n openshift-ingress deployment/router-sharded cat os_http_be.map
^dummy-shared-demo\.apps\.demo\.openshift\.pub(:[0-9]+)?(/.*)?$ be_http:demo:dummy-shared

$ oc rsh -n openshift-ingress deployment/router-default cat os_http_be.map
^dummy-default-demo\.apps\.demo\.openshift\.pub(:[0-9]+)?(/.*)?$ be_http:demo:dummy-default

One downside: all routes auto generated with default domain:

1
2
$ oc get ingresses.config.openshift.io/cluster -o jsonpath="{.spec.domain}"
apps.demo.openshift.pub

Last update: July 2, 2020