Issue#

You create an Ingress, but it never gets an address and every request returns the controller's default 404 Not Found:

$ kubectl get ingress myapp NAME CLASS HOSTS ADDRESS PORTS AGE myapp <none> app.example.com 80 10m

The ingress-nginx controller logs show it is skipping the resource:

Ignoring ingress because of error while validating ingress class" ingress="default/myapp" error="ingress does not contain a valid IngressClass"

Cause#

Since ingress-nginx v1.0 (Kubernetes 1.19+ networking.k8s.io/v1), the controller only handles Ingresses that reference its IngressClass. An Ingress with no spec.ingressClassName (and no default IngressClass in the cluster) is ignored. The old kubernetes.io/ingress.class annotation is deprecated and is not a reliable replacement.

Solution#

  1. Find the IngressClass name your controller uses:
kubectl get ingressclass
NAME CONTROLLER PARAMETERS AGE nginx k8s.io/ingress-nginx <none> 30d
  1. Set ingressClassName on the existing Ingress:
kubectl patch ingress myapp --type=merge \ -p '{"spec":{"ingressClassName":"nginx"}}'
  1. Fix the manifest so it stays correct on the next apply:
apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: myapp spec: ingressClassName: nginx rules: - host: app.example.com http: paths: - path: / pathType: Prefix backend: service: name: myapp port: number: 80
  1. Optional: make nginx the cluster default so new Ingresses without a class get it automatically:
kubectl annotate ingressclass nginx \ ingressclass.kubernetes.io/is-default-class="true"

Note: The default class is applied only when an Ingress is created. Existing Ingresses still need step 2.

  1. Alternative: tell the controller to also serve class-less Ingresses (useful with a single controller):
helm upgrade ingress-nginx ingress-nginx/ingress-nginx \ -n ingress-nginx --reuse-values \ --set controller.watchIngressWithoutClass=true

Verify#

The Ingress now shows a class and an address:

$ kubectl get ingress myapp NAME CLASS HOSTS ADDRESS PORTS AGE myapp nginx app.example.com 203.0.113.10 80 12m

The controller logs no longer show the warning:

kubectl logs -n ingress-nginx deploy/ingress-nginx-controller | grep -i "valid IngressClass"

And the app responds instead of the default 404:

curl -i -H "Host: app.example.com" http://203.0.113.10/