There are some ingress controllers, that work without the definition of a default IngressClass. For example, the Ingress-NGINX controller can be configured with a flag--watch-ingress-without-class. It is recommended though, to specify the default IngressClass as shown below.
If the ingressClassName is omitted, a default Ingress class should be defined.
Missing ingressclass ?
sauron@kind:~/Projects/kind$ k create deployment first --image nginx:1.25.2 --port 80
deployment.apps/first created
sauron@kind:~/Projects/kind$ k create deployment second --image nginx:1.25.2 --port 80
deployment.apps/second created
sauron@kind:~/Projects/kind$ k expose deployment first --name service1 --port 80
service/service1 exposed
sauron@kind:~/Projects/kind$ k expose deployment second --name service2 --port 80
service/service2 exposed
sauron@kind:~/Projects/kind$ k get ingressclass
NAME CONTROLLER PARAMETERS AGE
ingress-nginx k8s.io/ingress-nginx <none> 22m
sauron@kind:~/Projects/kind$ k create ingress example-ingress \
--class ingress-nginx \
--rule=/first*=service1:80 \
--rule=/second*=service2:80 \
--annotation nginx.ingress.kubernetes.io/rewrite-target="/"
ingress.networking.k8s.io/example-ingress created
sauron9@kind:~/Projects/kind$ k describe ingress example-ingress
Name: example-ingress
Labels: <none>
Namespace: default
Address: 10.254.254.240
Ingress Class: ingress-nginx
Default backend: <default>
Rules:
Host Path Backends
---- ---- --------
*
/first service1:80 (192.168.110.135:80)
/second service2:80 (192.168.110.136:80)
Annotations: nginx.ingress.kubernetes.io/rewrite-target: /
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Sync 3m51s (x2 over 3m54s) nginx-ingress-controller Scheduled for sync
sauron@kind:~/Projects/kind$ k get ingress example-ingress -oyaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
creationTimestamp: "2023-09-12T12:41:38Z"
generation: 1
name: example-ingress
namespace: default
resourceVersion: "8416"
uid: a6759c94-f625-4f8b-9fbc-5f92ed45d847
spec:
ingressClassName: ingress-nginx
rules:
- http:
paths:
- backend:
service:
name: service1
port:
number: 80
path: /first
pathType: Prefix
- backend:
service:
name: service2
port:
number: 80
path: /second
pathType: Prefix
status:
loadBalancer:
ingress:
- ip: 10.254.254.240
sauron@kind:~/Projects/kind$curl -s 10.254.254.240/first | grep "<h1>"
<h1>Welcome to nginx!</h1>
sauron@kind:~/Projects/kind$ curl -s 10.254.254.240/second | grep "<h1>"
<h1>Welcome to nginx!</h1>
sauron@kind:~/Projects/kind$
Below is the yaml file i have used . if i comment everything under rules and just use the defaultBackend . i can see the application is working if i browse just the IP ADDRESS alone without any prefix. ( http:ingressipaddress )