Middle+
Is the ingress class or specifying the ingress controller directly in the application more commonly used now?
sobes.tech AI
Answer from AI
The ingress class (ingressClassName) is used more frequently.
This allows:
- To separate ingress configuration from application configuration.
- Easier management of different ingress controllers within a cluster.
- Flexibly apply different ingress controller configurations for different ingresses (e.g., different SSL certificates, different load balancing types).
Specifying the ingress controller via annotations (e.g., kubernetes.io/ingress.class) is considered an outdated approach in most scenarios, especially with the introduction of ingressClassName in the networking.k8s.io/v1 API.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: minimal-ingress
spec:
ingressClassName: nginx # prefer this approach
rules:
- http:
paths:
- path: /test
pathType: Prefix
backend:
service:
name: test-service
port:
number: 80
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: older-ingress
annotations:
kubernetes.io/ingress.class: nginx # older approach, still supported by some controllers
spec:
rules:
- http:
paths:
- path: /test
pathType: Prefix
backend:
service:
name: test-service
port:
number: 80
Comparison table:
| Aspect | ingressClassName |
Annotation kubernetes.io/ingress.class |
|---|---|---|
| Status | Recommended | Deprecated (in most cases) |
| Flexibility | High | Medium |
| Readability | Better | Worse |
| API | Part of API specification | Annotation |