|
| 1 | +# IngressClass |
| 2 | + |
| 3 | +An Ingress resource can target a specific Ingress controller instance which is useful when running multiple ingress controllers in the same cluster. Targetting an Ingress controller means only a specific controller should handle/implement the ingress resource. |
| 4 | +This can be done using either the `IngressClassName` field or the `ingress.class` annotation. |
| 5 | + |
| 6 | +## IngressClassName |
| 7 | +The `IngressClassName` field is available in kubernetes 1.18+ and is the [official](https://kubernetes.io/docs/concepts/services-networking/ingress/#ingress-class) way to handle this. This field should reference an IngressClass resource that contains the name of the controller that should implement the class. |
| 8 | +For example, let's consider the following Ingress object: |
| 9 | +```yaml |
| 10 | +kind: Ingress |
| 11 | +apiVersion: networking.k8s.io/v1 |
| 12 | +metadata: |
| 13 | + name: test |
| 14 | +spec: |
| 15 | + ingressClassName: haproxy |
| 16 | + rules: |
| 17 | + - host: test.k8s.local |
| 18 | + http: |
| 19 | + paths: |
| 20 | + - path: / |
| 21 | + backend: |
| 22 | + serviceName: http-echo |
| 23 | + servicePort: http |
| 24 | +``` |
| 25 | +
|
| 26 | +If there is a single HAProxy Ingress Controller instance then no need to set `--ingress.class`, but rather create an IngressClass resource with Spec.Controller set to **haproxy.org/ingress-controller** |
| 27 | +```yaml |
| 28 | +apiVersion: networking.k8s.io/v1 |
| 29 | +kind: IngressClass |
| 30 | +metadata: |
| 31 | + name: haproxy |
| 32 | +spec: |
| 33 | + controller: haproxy.org/ingress-controller |
| 34 | +``` |
| 35 | + |
| 36 | +In the other hand if multiple HAProxy Ingress Controllers are deployed then `--ingress.class` argument can be used to target one of them. This can be done via the following IngressClass (notice Spec.Controller is set to **haproxy.org/ingress-controller/prod**) |
| 37 | +```yaml |
| 38 | +apiVersion: networking.k8s.io/v1 |
| 39 | +kind: IngressClass |
| 40 | +metadata: |
| 41 | + name: haproxy-prod |
| 42 | +spec: |
| 43 | + controller: haproxy.org/ingress-controller/prod |
| 44 | +``` |
| 45 | +In this case `--ingress.class` should be set to **prod** and the `ingressClassName` field should be **haproxy-prod**. |
| 46 | + |
| 47 | +## ingress.class annotation |
| 48 | +The `ingress.class` annotation is the legacy way to target an Ingress Controller. |
| 49 | +For example, let's consider the following Ingress object: |
| 50 | +```yaml |
| 51 | +kind: Ingress |
| 52 | +apiVersion: networking.k8s.io/v1 |
| 53 | +metadata: |
| 54 | + name: test |
| 55 | + annotations: |
| 56 | + ingress.class: haproxy |
| 57 | +spec: |
| 58 | + rules: |
| 59 | + - host: test.k8s.local |
| 60 | + http: |
| 61 | + paths: |
| 62 | + - path: / |
| 63 | + backend: |
| 64 | + serviceName: http-echo |
| 65 | + servicePort: http |
| 66 | +``` |
| 67 | +In this case only HAProxy Ingress Controllers with `--ingress.class` set to "haproxy" are going to implement the previous Ingress object. |
| 68 | + |
| 69 | +## Eligibility rules |
| 70 | +- If the `--ingress.class` argument of the controller is not configured: |
| 71 | + - **Accept** Ingress resource when neither `ingress.class` annotation nor `ingressClassName` fields are set. |
| 72 | + - **Accept** Ingress resource when `ingress.class` annotation is not set but `ingressClassName` field matches. |
| 73 | +- If the `--ingress.class` argument of the controller is configured: |
| 74 | + - **Accept** Ingress resource when neither `ingress.class` annotation nor `ingressClassName` fields are set but controller argument `--EmptyIngressClass` is enabled. |
| 75 | + - **Accept** Ingress resource when --`ingress.class` argument is equal to `ingress.class` annotation. |
| 76 | + - **Accept** Ingress resource when `ingressClassName` field matches. |
| 77 | +- **Ignore** Ingress resource otherwise. |
0 commit comments