What is Ingress Class in Kubernetes: Simple Explanation and Example
IngressClass is a resource that defines which controller should manage an Ingress resource. It helps Kubernetes know how to route external traffic by linking Ingress objects to specific controllers like NGINX or Traefik.How It Works
Think of an IngressClass as a label or tag that tells Kubernetes which traffic controller should handle incoming web requests. Just like in a post office where different mail carriers deliver mail to different areas, Kubernetes uses IngressClass to decide which controller will process the rules defined in an Ingress resource.
When you create an Ingress, you can specify the ingressClassName to link it to a particular IngressClass. This way, multiple controllers can run in the same cluster without confusion, each managing its own set of ingress rules.
Example
This example shows how to define an IngressClass for the NGINX controller and then create an Ingress that uses it.
apiVersion: networking.k8s.io/v1
kind: IngressClass
metadata:
name: nginx
spec:
controller: k8s.io/ingress-nginx
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
spec:
ingressClassName: nginx
rules:
- host: example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: example-service
port:
number: 80When to Use
Use IngressClass when you have multiple ingress controllers in your Kubernetes cluster and want to control which controller manages which ingress rules. For example, you might run NGINX for public traffic and Traefik for internal services. Assigning IngressClass ensures traffic is routed correctly without conflicts.
It is also useful when you want to upgrade or switch ingress controllers without changing all your ingress resources. You just update the IngressClass or create new ones and assign them accordingly.
Key Points
- IngressClass links ingress resources to specific controllers.
- It prevents conflicts when multiple ingress controllers run in one cluster.
- You specify the class in ingress with
ingressClassName. - Controllers watch for ingress resources matching their class.
- It helps manage traffic routing cleanly and flexibly.