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:

nix
helm 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
nix
helm 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=prod to the ingress controller pods.
  • Creates an IngressClass resource with a class name of prod.

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+.

  1. Before installing the ingress controller with kubectl, add the --ingress-class startup argument. In this partial snippet, we set its value to prod-controller:

    haproxy-ingress.hapee.yaml
    yaml
    apiVersion: apps/v1
    kind: Deployment
    metadata:
    labels:
    run: haproxy-ingress
    name: haproxy-ingress
    namespace: haproxy-controller
    spec:
    ...
    spec:
    serviceAccountName: haproxy-ingress-service-account
    imagePullSecrets:
    - name: regcred
    containers:
    - name: haproxy-ingress
    image: kubernetes-registry.haproxy.com/hapee-ingress:v1.11
    args:
    - --configmap=haproxy-controller/haproxy-kubernetes-ingress
    - --ingress.class=prod-controller
    haproxy-ingress.hapee.yaml
    yaml
    apiVersion: apps/v1
    kind: Deployment
    metadata:
    labels:
    run: haproxy-ingress
    name: haproxy-ingress
    namespace: haproxy-controller
    spec:
    ...
    spec:
    serviceAccountName: haproxy-ingress-service-account
    imagePullSecrets:
    - name: regcred
    containers:
    - name: haproxy-ingress
    image: kubernetes-registry.haproxy.com/hapee-ingress:v1.11
    args:
    - --configmap=haproxy-controller/haproxy-kubernetes-ingress
    - --ingress.class=prod-controller
  2. Apply it with kubectl:

    nix
    kubectl apply -f haproxy-ingress.hapee.yaml
    nix
    kubectl apply -f haproxy-ingress.hapee.yaml
  3. Create an IngressClass resource. 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 the prod-controller ingress controller (note that we use the prefix haproxy.org/ingress-controller/) with the class name prod:

    prod-ingressclass.yaml
    yaml
    apiVersion: networking.k8s.io/v1
    kind: IngressClass
    metadata:
    name: prod
    spec:
    controller: haproxy.org/ingress-controller/prod-controller
    prod-ingressclass.yaml
    yaml
    apiVersion: networking.k8s.io/v1
    kind: IngressClass
    metadata:
    name: prod
    spec:
    controller: haproxy.org/ingress-controller/prod-controller
  4. Apply it with kubectl:

    nix
    kubectl apply -f prod-ingressclass.yaml
    nix
    kubectl 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.yml
yaml
kind: Ingress
apiVersion: networking.k8s.io/v1
metadata:
name: example
spec:
ingressClassName: prod
rules:
- host: example.k8s.local
http:
paths:
- path: /
backend:
serviceName: http-echo
servicePort: http
example-ingress.yml
yaml
kind: Ingress
apiVersion: networking.k8s.io/v1
metadata:
name: example
spec:
ingressClassName: prod
rules:
- host: example.k8s.local
http:
paths:
- path: /
backend:
serviceName: http-echo
servicePort: 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.yml
yaml
kind: Ingress
apiVersion: networking.k8s.io/v1
metadata:
name: example
annotations:
ingress.class: prod
spec:
rules:
- host: example.k8s.local
http:
paths:
- path: /
backend:
serviceName: http-echo
servicePort: http
example-ingress.yml
yaml
kind: Ingress
apiVersion: networking.k8s.io/v1
metadata:
name: example
annotations:
ingress.class: prod
spec:
rules:
- host: example.k8s.local
http:
paths:
- path: /
backend:
serviceName: http-echo
servicePort: http

Do you have any suggestions on how we can improve the content of this page?