Skip to content

Ingress default backend

An Ingress default backend is a configuration within a Kubernetes Ingress resource that specifies a fallback destination for traffic.^[400-devops__06-Kubernetes__k8s-ithelp__Day9__README.md] It defines where requests should be routed if they do not match any of the specific rules defined in the Ingress spec, such as particular hostnames or path patterns.^[400-devops__06-Kubernetes__k8s-ithelp__Day9__README.md]

Usage

The defaultBackend is primarily used to handle traffic that falls outside of the explicitly defined routing rules^[400-devops__06-Kubernetes__k8s-ithelp__Day9__README.md]. In scenarios where an Ingress Controller is used to expose a single service without complex routing logic (such as hostname or path-based fanout), the default backend can be configured to catch all traffic and direct it to that specific service^[400-devops__06-Kubernetes__k8s-ithelp__Day9__README.md].

This creates a routing path from the external LoadBalancer or entry point directly to the backend Service, and subsequently to its Pods^[400-devops__06-Kubernetes__k8s-ithelp__Day9__README.md].

Configuration

To configure a default backend, the spec section of an Ingress resource includes a defaultBackend field^[400-devops__06-Kubernetes__k8s-ithelp__Day9__README.md]. This field specifies the target Service name and the port number to which the traffic should be forwarded^[400-devops__06-Kubernetes__k8s-ithelp__Day9__README.md].

Example configuration:

spec:
  ingressClassName: nginx
  defaultBackend:
    service:
      name: my-service
      port:
        number: 8000

In this example, any request that does not match a specific host or path rule (or if no other rules are present) will be directed to my-service on port 8000^[400-devops__06-Kubernetes__k8s-ithelp__Day9__README.md].

Sources

^[400-devops__06-Kubernetes__k8s-ithelp__Day9__README.md]