How to fix 404 Not Found in Kubernetes
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.
Quick fix
Fixes 404 Not Found
metadata:
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /myapp
pathType: Prefix
backend:
service:
name: myapp-service
port:
number: 8080- Verify Ingress configuration matches your Service
- Check if backend pods are running and healthy
- Test direct pod connectivity
- Add or fix the rewrite-target annotation
metadata:annotations:nginx.ingress.kubernetes.io/rewrite-target: /spec:rules:- http:paths:- path: /myapppathType: Prefixbackend:service:name: myapp-serviceport:number: 8080404 Not Found
What this error means
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.
Typical symptoms
- Browser displays "404 Not Found" when accessing domain mapped to Ingress
- Requests fail for specific paths while root path might work
- Error appears immediately after creating or updating Ingress rules
- Service works when accessed via port-forward but fails through Ingress
- Ingress controller logs show no routing errors but requests still return 404
- Different paths on same domain have different success rates
Common causes
- Service name in Ingress resource doesn't match actual Kubernetes Service name
- Service port number in Ingress doesn't match the Service target port
- Missing or incorrect ingressClassName/kubernetes.io/ingress.class annotation
- Path rewriting misconfiguration—Ingress sends wrong path to backend application
- Backend service pods not running or not healthy, removing endpoints from service
- Application not configured to handle the request path Ingress forwards to it
- Service selector labels don't match running pods, resulting in no available backends
How to fix "404 Not Found"
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.
Advanced notes
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.
Frequently asked questions
- What does "404 Not Found" mean?
- 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.
- How do I fix "404 Not Found"?
- 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.
- What causes "404 Not Found"?
- Service name in Ingress resource doesn't match actual Kubernetes Service name Service port number in Ingress doesn't match the Service target port Missing or incorrect ingressClassName/kubernetes.io/ingress.class annotation
- Is the "404 Not Found" error serious?
- It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- 📚Kubernetes Official Documentation
- 📖Microsoft Docs: 404 not found error in kubernetes(Official Docs)
- 💬Stack Overflow: kubernetes ingress non root path 404 not found(Stack Overflow)
- 💬
- 🐙
- 📖Google Cloud Docs: error 404 on ingress backend 000004715(Official Docs)