|
| 1 | +# [IngressClass](https://kubernetes.io/docs/concepts/services-networking/ingress/#ingress-class) |
| 2 | + |
| 3 | +Ingresses can be implemented by different controllers, often with different configuration. Each Ingress should specify a |
| 4 | +class, a reference to an IngressClass resource that contains additional configuration including the name of the |
| 5 | +controller that should implement the class. IngressClass resources contain an optional parameters field. This can be |
| 6 | +used to reference additional implementation-specific configuration for this class. |
| 7 | +For the AWS Load Balancer controller, the implementation-specific configuration is |
| 8 | +[IngressClassParams](#ingressclassparams) in the `elbv2.k8s.aws` API group. |
| 9 | + |
| 10 | +!!!example |
| 11 | + - specify controller as `ingress.k8s.aws/alb` to denote Ingresses should be managed by AWS Load Balancer Controller. |
| 12 | + ``` |
| 13 | + apiVersion: networking.k8s.io/v1 |
| 14 | + kind: IngressClass |
| 15 | + metadata: |
| 16 | + name: awesome-class |
| 17 | + spec: |
| 18 | + controller: ingress.k8s.aws/alb |
| 19 | + ``` |
| 20 | + - specify additional configurations by referencing an IngressClassParams resource. |
| 21 | + ``` |
| 22 | + apiVersion: networking.k8s.io/v1 |
| 23 | + kind: IngressClass |
| 24 | + metadata: |
| 25 | + name: awesome-class |
| 26 | + spec: |
| 27 | + controller: ingress.k8s.aws/alb |
| 28 | + parameters: |
| 29 | + apiGroup: elbv2.k8s.aws |
| 30 | + kind: IngressClassParams |
| 31 | + name: awesome-class-cfg |
| 32 | + ``` |
| 33 | + |
| 34 | +!!!tip "[default IngressClass](https://kubernetes.io/docs/concepts/services-networking/ingress/#default-ingress-class)" |
| 35 | + You can mark a particular IngressClass as the default for your cluster. Setting the |
| 36 | + `ingressclass.kubernetes.io/is-default-class` annotation to `true` on an IngressClass resource will ensure that new |
| 37 | + Ingresses without an `ingressClassName` field specified will be assigned this default IngressClass. |
| 38 | + |
| 39 | + |
| 40 | +## [Deprecated `kubernetes.io/ingress.class` annotation](https://kubernetes.io/docs/concepts/services-networking/ingress/#deprecated-annotation) |
| 41 | + |
| 42 | +Before the IngressClass resource and `ingressClassName` field were added in Kubernetes 1.18, Ingress classes were |
| 43 | +specified with a `kubernetes.io/ingress.class` annotation on the Ingress. This annotation was never formally defined, |
| 44 | +but was widely supported by Ingress controllers. |
| 45 | + |
| 46 | +The newer `ingressClassName` field on Ingresses is a replacement for that annotation, but is not a direct equivalent. |
| 47 | +While the annotation was generally used to reference the name of the Ingress controller that should implement the |
| 48 | +Ingress, the field is a reference to an IngressClass resource that contains additional Ingress configuration, including |
| 49 | +the name of the Ingress controller. |
| 50 | + |
| 51 | +!!!tip "disable `kubernetes.io/ingress.class` annotation" |
| 52 | + In order to maintain backwards-compatibility, `kubernetes.io/ingress.class` annotation is still supported currently. |
| 53 | + You can enforce IngressClass resource adoption by disable the `kubernetes.io/ingress.class` annotation via [--disable-ingress-class-annotation](../../../deploy/configurations/#disable-ingress-class-annotation) controller flag. |
| 54 | + |
| 55 | +## IngressClassParams |
| 56 | +IngressClassParams is a [CRD](https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/) specific to the AWS Load Balancer Controller, which can be used along with IngressClass’s parameter field. |
| 57 | +You can use IngressClassParams to enforce settings for a set of Ingresses. |
| 58 | + |
| 59 | +!!!example |
| 60 | + - with scheme & ipAddressType & tags |
| 61 | + ``` |
| 62 | + apiVersion: elbv2.k8s.aws/v1beta1 |
| 63 | + kind: IngressClassParams |
| 64 | + metadata: |
| 65 | + name: awesome-class |
| 66 | + spec: |
| 67 | + scheme: internal |
| 68 | + ipAddressType: dualstack |
| 69 | + tags: |
| 70 | + - key: org |
| 71 | + value: my-org |
| 72 | + ``` |
| 73 | + - with namespaceSelector |
| 74 | + ``` |
| 75 | + apiVersion: elbv2.k8s.aws/v1beta1 |
| 76 | + kind: IngressClassParams |
| 77 | + metadata: |
| 78 | + name: awesome-class |
| 79 | + spec: |
| 80 | + namespaceSelector: |
| 81 | + matchLabels: |
| 82 | + team: team-a |
| 83 | + ``` |
| 84 | + - with IngressGroup |
| 85 | + ``` |
| 86 | + apiVersion: elbv2.k8s.aws/v1beta1 |
| 87 | + kind: IngressClassParams |
| 88 | + metadata: |
| 89 | + name: awesome-class |
| 90 | + spec: |
| 91 | + group: |
| 92 | + name: my-group |
| 93 | + ``` |
| 94 | + |
| 95 | +### IngressClassParams specification |
| 96 | + |
| 97 | +#### spec.namespaceSelector |
| 98 | +`namespaceSelector` is an optional setting that follows general Kubernetes |
| 99 | +[label selector](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors) |
| 100 | +semantics. |
| 101 | + |
| 102 | +Cluster administrators can use the `namespaceSelector` field to restrict the namespaces of Ingresses that are allowed to specify the IngressClass. |
| 103 | + |
| 104 | +1. If `namespaceSelector` specified, only Ingresses in selected namespaces can use IngressClasses with this parameter. The controller will refuse to reconcile for Ingresses that violates `namespaceSelector`. |
| 105 | +2. If `namespaceSelector` un-specified, all Ingresses in any namespace can use IngressClasses with this parameter. |
| 106 | + |
| 107 | +#### spec.group |
| 108 | + |
| 109 | +`group` is an optional setting. The only available sub-field is `group.name`. |
| 110 | + |
| 111 | +Cluster administrators can use `group.name` field to denote the groupName for all Ingresses belong to this IngressClass. |
| 112 | + |
| 113 | +1. If `group.name` specified, all Ingresses with this IngressClass will belong to the same IngressGroup specified and result in a single ALB. |
| 114 | +If `group.name` is not specified, Ingresses with this IngressClass can use the older / legacy `alb.ingress.kubernetes.io/group.name` annotation to specify their IngressGroup. Ingresses that belong to the same IngressClass can form different IngressGroups via that annotation. |
| 115 | + |
| 116 | +#### spec.scheme |
| 117 | + |
| 118 | +`scheme` is an optional setting. The available options are `internet-facing` or `internal`. |
| 119 | + |
| 120 | +Cluster administrators can use the `scheme` field to restrict the scheme for all Ingresses that belong to this IngressClass. |
| 121 | + |
| 122 | +1. If `scheme` specified, all Ingresses with this IngressClass will have the specified scheme. |
| 123 | +2. If `scheme` un-specified, Ingresses with this IngressClass can continue to use `alb.ingress.kubernetes.io/scheme annotation` to specify scheme. |
| 124 | + |
| 125 | +#### spec.ipAddressType |
| 126 | + |
| 127 | +`ipAddressType` is an optional setting. The available options are `ipv4` or `dualstack`. |
| 128 | + |
| 129 | +Cluster administrators can use `ipAddressType` field to restrict the ipAddressType for all Ingresses that belong to this IngressClass. |
| 130 | + |
| 131 | +1. If `ipAddressType` specified, all Ingresses with this IngressClass will have the specified ipAddressType. |
| 132 | +2. If `ipAddressType` un-specified, Ingresses with this IngressClass can continue to use `alb.ingress.kubernetes.io/ip-address-type` annotation to specify ipAddressType. |
| 133 | + |
| 134 | +#### spec.tags |
| 135 | + |
| 136 | +`tags` is an optional setting. |
| 137 | + |
| 138 | +Cluster administrators can use `tags` field to specify the custom tags for AWS resources provisioned for all Ingresses belong to this IngressClass. |
| 139 | + |
| 140 | +1. If `tags` is set, AWS resources provisioned for all Ingresses with this IngressClass will have the specified tags. |
| 141 | +2. You can also use controller-level flag `--default-tags` or `alb.ingress.kubernetes.io/tags` annotation to specify custom tags. These tags will be merged together based on tag-key. If same tag-key appears in multiple sources, the priority is as follows: |
| 142 | + 1. controller-level flag `--default-tags` will have the highest priority. |
| 143 | + 2. `spec.tags` in IngressClassParams will have the middle priority. |
| 144 | + 3. `alb.ingress.kubernetes.io/tags` annotation will have the lowest priority. |
0 commit comments