Ingress controller name for the ingress class

11,660

Solution 1

I have run multiple scenarios with IngressClass, Ingress and Nginx Ingress Controller.

Scenario 1

  • IngressClass with custom name
  • Nginx Ingress Controller with default --ingress-class value which is nginx
  • Ingress using ingressClassName same as IngressClass name

Output: Response 404

Scenario 2

  • IngressClass with custom name
  • Nginx Ingress Controller with owningress-class ingress-test
  • Ingress using ingressClassName same as IngressClass name

Output: Response 404

Scenario 3

  • IngressClass with test name
  • Nginx Ingress Controller --ingress-class with value test
  • Ingress using test in ingressClassName

Output: Proper response

Senario 4

  • IngressClass with nginx name
  • Nginx Ingress Controller --ingress-class with value nginx
  • Ingress using nginx in ingressClassName

Output: Proper response

Conclusion

First of all, please keep in mind that there are 3 types of Nginx. Open Source Nginx Ingress Controller, you are probably using it. Nginx Incorporaton (nginx inc) and Nginx Incorporaton Plus.

In one of the scenarios, when I have used spec.controller: nginx.org/ingress-controller with Nginx Ingress Controller with argument --ingress-class=nginx, in Nginx Ingress Controller pod you will see entry which is pointing to k8s.io/ingress-nginx.

To reproduce this behavior, you will need to deploy IngressClass with specific controller and then deploy nginx.

apiVersion: networking.k8s.io/v1beta1
kind: IngressClass
metadata:
  name: nginx
spec:
  controller: nginx.org/ingress-controller

After deploying Nginx Ingress Controller, controller pod will be in CrashLoopBackOff state. In logs you will find entry:

E1118 15:42:19.008911       8 main.go:134] Invalid IngressClass (Spec.Controller) value "nginx.org/ingress-controller". Should be "k8s.io/ingress-nginx"

It works only when IngressClass name is set to nginx.

I would say that nginx.org/ingress-controller is for Nginx Incorporated and k8s.io/ingress-nginx for Open Source Nginx Ingress.

If custom value is used for --ingress-class argument in the controller Deployment manifest, presence or absence of IngressClass object with the same name doesn't made any difference in, how the cluster works, if only you keep Ingress spec.ingressClass value the same with controller argument. Moreover, if it's present, IngressClass spec.controller can have any value that match the required pattern "domain like" and that didn't affect Ingress workflow behavior on my cluster at all.

In addition, Ingress works fine if I put the correct value of the ingress-class either to spec.ingressClass property or to metadata.annotation.kubernetes.io/ingress.class accordingly. It gives an error like the following if you try to put both values to the same Ingres object:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: test-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  ingressClassName: nginx

The Ingress "test-ingress" is invalid: annotations.kubernetes.io/ingress.class: Invalid value: "nginx": can not be set when the class field is also set

Please keep in mind it was tested only for Nginx Ingress Controlle. If you would like to use IngressClass with other Ingress Controllers like Traefik or Ambasador, you would check their release notes.

Solution 2

You will create the IngressClass as part of the Installation with Manifests steps (Step 3 here). That will create an IngressClass that looks like:

apiVersion: networking.k8s.io/v1beta1
kind: IngressClass
metadata:
  name: nginx
  # annotations:
  #   ingressclass.kubernetes.io/is-default-class: "true"
spec:
  controller: nginx.org/ingress-controller 

Then, to configure an Ingress resource to be consumed by nginx, just specify ingressClassName: nginx in the Ingress spec, as shown here, and pasted again below:

  apiVersion: networking.k8s.io/v1beta1
  kind: Ingress
  metadata:
    name: cafe-ingress
  spec:
    ingressClassName: nginx
    tls:
    - hosts:
      - cafe.example.com
      secretName: cafe-secret
    rules:
    - host: cafe.example.com
  . . .
Share:
11,660
letthefireflieslive
Author by

letthefireflieslive

Updated on August 01, 2022

Comments

  • letthefireflieslive
    letthefireflieslive almost 2 years

    I am setting up my ingress controller, ingress class and ingress to expose a service outside the cluster. This is fresh cluster setup.

    I have setup the nginx-ingress controller using

    kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.41.0/deploy/static/provider/baremetal/deploy.yaml

    The next step based on my understanding is to create the ingress class https://v1-18.docs.kubernetes.io/docs/concepts/services-networking/ingress/#ingress-class

    apiVersion: networking.k8s.io/v1beta1
    kind: IngressClass
    metadata:
      name: external-lb
    spec:
      controller: example.com/ingress-controller
      parameters:
        apiGroup: k8s.example.com/v1alpha
        kind: IngressParameters
        name: external-lb
    

    How did they get the name of the controller example.com/ingress-controller?