Configuration reference
IngressClass
An Ingress resource can target a specific ingress controller instance, which is useful when running multiple ingress controllers in the same cluster. To target a specific ingress controller, you must first install that ingress controller with a unique class name.
Set the ingress controller’s class Jump to heading
Give each ingress controller a different class name so that your Ingress resources can target the appropriate one. In the following sections, we’ll show how to do this depending on whether you’re using Helm.
With Helm: Set the class name Jump to heading
When installing with Helm, you can set the class name via the variable controller.ingressClass. Its default value is haproxy if you don’t set it. For demonstration purposes, we’ll set it to prod:
nixhelm install haproxy-kubernetes-ingress haproxytech/kubernetes-ingress \--create-namespace \--namespace haproxy-controller \--set controller.imageCredentials.registry=kubernetes-registry.haproxy.com \--set controller.imageCredentials.username=[KEY] \--set controller.imageCredentials.password=[KEY] \--set controller.image.repository=kubernetes-registry.haproxy.com/hapee-ingress \--set controller.image.tag=v3.0 \--set controller.ingressClass=prod
nixhelm install haproxy-kubernetes-ingress haproxytech/kubernetes-ingress \--create-namespace \--namespace haproxy-controller \--set controller.imageCredentials.registry=kubernetes-registry.haproxy.com \--set controller.imageCredentials.username=[KEY] \--set controller.imageCredentials.password=[KEY] \--set controller.image.repository=kubernetes-registry.haproxy.com/hapee-ingress \--set controller.image.tag=v3.0 \--set controller.ingressClass=prod
Setting this variable does the following for you:
- Adds the startup argument
--ingress.class=prodto the ingress controller pods. - Creates an
IngressClassresource with a class name ofprod.
Without Helm: Set the class name Jump to heading
When not using Helm, you must set the --ingress.class startup argument and create the IngressClass resource yourself. The IngressClass resource is available in Kubernetes 1.18+.
-
Before installing the ingress controller with
kubectl, add the--ingress-classstartup argument. In this partial snippet, we set its value toprod-controller:haproxy-ingress.hapee.yamlyamlapiVersion: apps/v1kind: Deploymentmetadata:labels:run: haproxy-ingressname: haproxy-ingressnamespace: haproxy-controllerspec:...spec:serviceAccountName: haproxy-ingress-service-accountimagePullSecrets:- name: regcredcontainers:- name: haproxy-ingressimage: kubernetes-registry.haproxy.com/hapee-ingress:v1.11args:- --configmap=haproxy-controller/haproxy-kubernetes-ingress- --ingress.class=prod-controllerhaproxy-ingress.hapee.yamlyamlapiVersion: apps/v1kind: Deploymentmetadata:labels:run: haproxy-ingressname: haproxy-ingressnamespace: haproxy-controllerspec:...spec:serviceAccountName: haproxy-ingress-service-accountimagePullSecrets:- name: regcredcontainers:- name: haproxy-ingressimage: kubernetes-registry.haproxy.com/hapee-ingress:v1.11args:- --configmap=haproxy-controller/haproxy-kubernetes-ingress- --ingress.class=prod-controller -
Apply it with
kubectl:nixkubectl apply -f haproxy-ingress.hapee.yamlnixkubectl apply -f haproxy-ingress.hapee.yaml -
Create an
IngressClassresource. The purpose of this resource is to map the class name you want to use to the ingress controller you want to target. In this example, we associate theprod-controlleringress controller (note that we use the prefixhaproxy.org/ingress-controller/) with the class nameprod:prod-ingressclass.yamlyamlapiVersion: networking.k8s.io/v1kind: IngressClassmetadata:name: prodspec:controller: haproxy.org/ingress-controller/prod-controllerprod-ingressclass.yamlyamlapiVersion: networking.k8s.io/v1kind: IngressClassmetadata:name: prodspec:controller: haproxy.org/ingress-controller/prod-controller -
Apply it with
kubectl:nixkubectl apply -f prod-ingressclass.yamlnixkubectl apply -f prod-ingressclass.yaml
Set an Ingress’s class Jump to heading
To match up an Ingress resource with a targeted ingress controller, set the Ingress resource’s class name to be the same as the ingress controller’s.
Set IngressClassName Jump to heading
To target an ingress controller from within an Ingress resource, add an IngressClassName field:
example-ingress.ymlyamlkind: IngressapiVersion: networking.k8s.io/v1metadata:name: examplespec:ingressClassName: prodrules:- host: example.k8s.localhttp:paths:- path: /backend:serviceName: http-echoservicePort: http
example-ingress.ymlyamlkind: IngressapiVersion: networking.k8s.io/v1metadata:name: examplespec:ingressClassName: prodrules:- host: example.k8s.localhttp:paths:- path: /backend:serviceName: http-echoservicePort: http
Set ingress.class (legacy) Jump to heading
The ingress.class annotation is the legacy way to target an ingress controller. Consider the following Ingress object in which we use ingress.class to target the prod ingress controller:
example-ingress.ymlyamlkind: IngressapiVersion: networking.k8s.io/v1metadata:name: exampleannotations:ingress.class: prodspec:rules:- host: example.k8s.localhttp:paths:- path: /backend:serviceName: http-echoservicePort: http
example-ingress.ymlyamlkind: IngressapiVersion: networking.k8s.io/v1metadata:name: exampleannotations:ingress.class: prodspec:rules:- host: example.k8s.localhttp:paths:- path: /backend:serviceName: http-echoservicePort: http
Do you have any suggestions on how we can improve the content of this page?