Default Backend Configuration
You'll learn how to configure a fallback Service in Kubernetes Ingress that handles requests not matching any defined routing rules.
When you set up Ingress rules, you define paths and hosts to route traffic to specific Services. But what happens when a user makes a request that doesn't match any of your rules? Without a default backend, these requests might result in a confusing 404 error or no response at all.
What Is a Default Backend?
A default backend is a fallback Service that catches all unmatched requests. Think of it as the "catch-all" handler—like a friendly receptionist who redirects visitors when they've arrived at the wrong office door. Instead of leaving users hanging, you can send them to a custom error page, a status page, or a maintenance message.
How It Works
You configure the default backend directly in your Ingress manifest using the defaultBackend field. This backend is separate from your regular routing rules and only triggers when no host or path matches.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-ingress
spec:
defaultBackend:
service:
name: fallback-service
port:
number: 80
rules:
- host: example.com
http:
paths:
- path: /app
pathType: Prefix
backend:
service:
name: app-service
port:
number: 8080
In this example, requests to example.com/app go to app-service, but requests to example.com/unknown or any unmatched host go to fallback-service.
Common Use Cases
- Custom 404 pages with helpful navigation
- Maintenance mode pages during updates
- Security placeholders to avoid exposing backend details
Key Takeaway: A default backend in Ingress provides a graceful fallback Service for requests that don't match any routing rules, improving user experience and security.