Ingress resources not working properly

Asking for help? Comment out what you need so we can get more information to help you!

Cluster information:

Kubernetes version: v1.19.4
Cloud being used: (put bare-metal if not on a public cloud) bare-metal
Installation method: kubeadm
Host OS: CentOS 7.5 (64-bit)
CNI and version: Docker version 19.03.13
CRI and version: 3.14

I installed NGINX ingress controller in my Kubernetes cluster.

I am able to access my application through an external load balancer(HAProxy) using below Ingress resources.

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: nginx-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  -
    host: mydomain.com
    http:
      paths:
      -
        path: /
        pathType: Prefix
        backend:
          serviceName: ui-service 
          servicePort: 8090

[root@MasterNode ingress]# kubectl describe ingress nginx-ingress
Warning: extensions/v1beta1 Ingress is deprecated in v1.14+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
Name:             nginx-ingress
Namespace:        default
Address:          
Default backend:  default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules:
  Host                 Path  Backends
  ----                 ----  --------
  mydomain.com  
                       /   ui-service:8090 (podIP:8090)
Annotations:           kubernetes.io/ingress.class: nginx
                       nginx.ingress.kubernetes.io/rewrite-target: /
Events:
  Type    Reason          Age                      From                      Message
  ----    ------          ----                     ----                      -------
  Normal  AddedOrUpdated  <invalid> (x8 over 61m)  nginx-ingress-controller  Configuration for default/nginx-ingress was added or updated
  Normal  AddedOrUpdated  <invalid> (x8 over 61m)  nginx-ingress-controller  Configuration for default/nginx-ingress was added or updated
  Normal  AddedOrUpdated  <invalid> (x8 over 61m)  nginx-ingress-controller  Configuration for default/nginx-ingress was added or updated

But if I change the Ingress resources as below -

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: nginx-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  -
    host: mydomain.com
    http:
      paths:
      -
        path: /ui
        pathType: Prefix
        backend:
          serviceName: ui-service 
          servicePort: 8090
      -
        path: /api
        pathType: Prefix
        backend:
           serviceName: api-service
           servicePort: 8080

[root@MasterNode ingress]# kubectl describe ingress nginx-ingress
Warning: extensions/v1beta1 Ingress is deprecated in v1.14+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
Name:             nginx-ingress
Namespace:        default
Address:          
Default backend:  default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules:
  Host                 Path  Backends
  ----                 ----  --------
  mydomain.com
                       /ui    ui-service:8090 (podIP:8090)  
                       /api   api-service:8080 (podIP:8080)
Annotations:           kubernetes.io/ingress.class: nginx
                       nginx.ingress.kubernetes.io/rewrite-target: /
Events:
  Type    Reason          Age                      From                      Message
  ----    ------          ----                     ----                      -------
  Normal  AddedOrUpdated  <invalid> (x9 over 75m)  nginx-ingress-controller  Configuration for default/nginx-ingress was added or updated
  Normal  AddedOrUpdated  <invalid> (x9 over 75m)  nginx-ingress-controller  Configuration for default/nginx-ingress was added or updated
  Normal  AddedOrUpdated  <invalid> (x9 over 75m)  nginx-ingress-controller  Configuration for default/nginx-ingress was added or updated

I can't access my application after applying ingress resources

Can you please suggest what i am doing wrong here ?

You can format your yaml by highlighting it and pressing Ctrl-Shift-C, it will make your output easier to read.