IngressClass Resource
What You'll Learn
You'll learn how IngressClass helps Kubernetes manage multiple Ingress Controllers and direct traffic to the right one.
Why IngressClass Exists
In many Kubernetes clusters, you might run multiple Ingress Controllers simultaneously—perhaps NGINX for public-facing apps and Traefik for internal services, or different versions for testing. Without a way to specify which controller should handle which Ingress resource, chaos would ensue.
IngressClass is like a routing tag that says: "This Ingress resource should be handled by that specific Ingress Controller."
How It Works
Think of IngressClass as a lane marker on a highway. Each Ingress Controller watches for Ingress resources tagged with its IngressClass name, ignoring all others.
IngressClass Manifest
apiVersion: networking.k8s.io/v1
kind: IngressClass
metadata:
name: nginx-public
spec:
controller: k8s.io/ingress-nginx
This defines an IngressClass named nginx-public managed by the NGINX controller.
Using IngressClass in an Ingress
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-app
spec:
ingressClassName: nginx-public
rules:
- host: example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: my-service
port:
number: 80
The ingressClassName: nginx-public field ensures only the NGINX controller processes this Ingress.
Default IngressClass
You can mark one IngressClass as default by adding an annotation:
metadata:
annotations:
ingressclass.kubernetes.io/is-default-class: "true"
Ingress resources without a specified ingressClassName will use the default.
Key Takeaway:
IngressClass provides explicit control over which Ingress Controller handles each Ingress resource, enabling safe multi-controller deployments and clear separation of concerns.