Kubernetes Ingress 404 Not Found Fix
In this tutorial, you'll learn about Kubernetes Ingress 404 Not Found Fix. We cover key concepts, practical examples, and best practices.
The Problem
You visit your application's URL and get a 404 Not Found:
$ curl https://app.example.com
404 Not Found
The Ingress resource exists, the service and pods are running, but traffic is not reaching the backend. The ingress controller either cannot find the service or the path does not match.
Quick Fix
Step 1: Check the ingress controller is running
kubectl get pods -n ingress-nginx
NAME READY STATUS RESTARTS
ingress-nginx-controller-7d6c9b5d8f-abc12 1/1 Running 0
If no ingress controller is deployed, the Ingress resource does nothing:
# Install NGINX Ingress Controller
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/cloud/deploy.yaml
Step 2: Verify the ingress rule matches a real service
kubectl describe ingress my-ingress
Rules:
Host Path Backends
---- ---- --------
app.example.com
/api my-service:8080 (10.1.0.5:8080)
WRONG -- service name does not exist:
rules:
- host: app.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: my-srvc # typo -- should be my-service
port:
number: 8080
RIGHT -- verify with kubectl get svc:
kubectl get svc my-service
Fix the ingress:
kubectl edit ingress my-ingress
Step 3: Check the service has endpoints
kubectl get endpoints my-service
NAME ENDPOINTS AGE
my-service 10.1.0.5:8080 2d
If ENDPOINTS is empty, the service selector does not match any pods:
kubectl describe svc my-service
# Selector: app=my-app
kubectl get pods -l app=my-app
# Check if pods have label "app: my-app"
Step 4: Test path matching
Ingress controllers use path matching rules. A prefix /api will not match a request to /api/v1/users with Exact pathType:
WRONG -- Exact pathType for API routes:
paths:
- path: /api
pathType: Exact # only matches /api exactly, not /api/v1
RIGHT -- Prefix pathType:
paths:
- path: /api
pathType: Prefix # matches /api, /api/v1, /api/v1/users
Step 5: Check TLS certificate configuration
A misconfigured TLS block causes 404 or SSL errors:
kubectl describe ingress my-ingress
TLS:
hosts:
- app.example.com
secretName: my-tls-secret
WRONG -- secret does not exist:
tls:
- hosts:
- app.example.com
secretName: nonexistent-secret
RIGHT -- create the secret first:
kubectl create secret tls my-tls-secret \
--cert=fullchain.pem \
--key=privkey.pem
Or use cert-manager to auto-provision TLS certificates.
Step 6: Check ingress controller logs
kubectl logs -n ingress-nginx deployment/ingress-nginx-controller
Look for lines mentioning your host or service:
WARNING: service "default/my-service" does not have any active endpoints
Or check the controller's configuration dump:
kubectl exec -n ingress-nginx deployment/ingress-nginx-controller -- cat /etc/nginx/nginx.conf | grep my-service
Use DodaTech's Ingress Debugger to visualize the traffic path from external request through the ingress controller to the backend pods.
Prevention
- Always verify service names and ports match the Ingress spec.
- Use
kubectl get endpointsafter creating a service. - Test with curl inside the cluster before enabling external access.
- Use
pathType: Prefixfor API routes unless you need exact matching. - Set up monitoring on the ingress controller metrics.
Common Mistakes with ingress 404
- Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
- Non-exhaustive pattern matches that compile with warnings then crash at runtime
- Misunderstanding that
Stringis[Char]with poor performance for large text operations
These mistakes appear frequently in real-world K8S code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro