A 404 Not Found error in Kubernetes Ingress indicates that the routing configuration is incorrect or the backend service cannot be reached. This typically happens due to mismatched service names, missing rewrite rules, or incorrect path configurations in your Ingress resource.
A 404 Not Found error from Kubernetes Ingress means the NGINX controller received your request but could not route it to a valid backend service, or the backend service exists but doesn't have an endpoint that matches the requested path. Unlike 503 Service Unavailable (which means no backends exist), 404 indicates the routing rules are misconfigured or the path doesn't match your application's expectations. This error can occur at multiple layers: the Ingress resource references a non-existent service, the path rewriting is incorrect, the backend service selector doesn't match any pods, or the application itself doesn't handle the path being forwarded to it.
Run kubectl get ingress -n <namespace> and kubectl describe ingress <ingress-name> to review the configuration. Verify:
- serviceName matches actual Service: kubectl get svc <serviceName> -n <namespace>
- servicePort matches Service port: kubectl get svc <serviceName> -o yaml | grep -A5 ports
- ingressClassName is set correctly (usually "nginx" for NGINX controller)
Run kubectl get pods -l app=<selector-label> -n <namespace> where selector-label matches your Service selector. Verify pods are in Running state: kubectl get pods -n <namespace>. Check pod health: kubectl describe pod <pod-name> -n <namespace>. Look at readiness status—if Not Ready, the pod won't receive traffic.
Connect directly to a pod to verify it responds: kubectl exec -it <pod-name> -n <namespace> -- curl http://localhost:8080/<path>. Replace 8080 with your application port and /<path> with the request path. If the pod responds correctly here but fails through Ingress, the issue is path rewriting.
If your Ingress path doesn't match your application's root, add the rewrite annotation:
metadata:
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /myapp
pathType: Prefix
backend:
service:
name: myapp-service
port:
number: 8080This strips /myapp before sending to the backend. Apply with kubectl apply -f ingress.yaml.
Run kubectl get endpoints <service-name> -n <namespace> or kubectl describe svc <service-name> -n <namespace>. The Endpoints section should list pod IPs and ports. If Endpoints is empty or shows <none>, the service has no running pods. If pods exist but aren't in Endpoints, check readiness probes are passing.
Run kubectl logs -n ingress-nginx deployment/nginx-ingress-controller | grep -i "404\|not found". Look for warnings about missing backends or path mismatches. You can also check the access log: kubectl logs -n ingress-nginx <controller-pod> | tail -100 to see request details.
Update Ingress path configuration:
paths:
- path: /myapp(/|$)(.*)
pathType: ImplementationSpecific
backend:
service:
name: myapp-service
port:
number: 8080Use pathType: Prefix for prefix matching, pathType: Exact for exact matching, or pathType: ImplementationSpecific for regex. Test the regex pattern with online tools before applying.
When using multiple Ingress controllers (nginx, traefik), ensure ingressClassName specifies the correct controller. Cloud-managed Kubernetes (EKS, AKS, GKE) may use vendor-specific ingress implementations with different annotation syntax—check cloud documentation. For path rewriting, regex patterns are powerful but error-prone; test thoroughly. If backend service is in a different namespace, use fully qualified name: serviceName.namespace.svc.cluster.local. Custom Ingress controllers may have different annotation formats than nginx-ingress. WSL2 environments require proper DNS resolution from Windows to reach Ingress endpoints. In CI/CD, service names must match exactly; typos are common in automated deployments.
No subnets found for EKS cluster
How to fix "eks subnet not found" in Kubernetes
unable to compute replica count
How to fix "unable to compute replica count" in Kubernetes HPA
error: context not found
How to fix "error: context not found" in Kubernetes
default backend - 404
How to fix "default backend - 404" in Kubernetes Ingress
serviceaccount cannot list resource
How to fix "serviceaccount cannot list resource" in Kubernetes