In Nginx, we can set up basic auth by adding annotation in the ingress.
nginx.ingress.kubernetes.io/auth-realm: Authentication Required
nginx.ingress.kubernetes.io/auth-secret: basic-auth
nginx.ingress.kubernetes.io/auth-type: basicBut if we are using azure application gateway instead of Nginx how can we set up basic auth.

Unfortunately Azure Application Gateway doesn't support basic auth and I would say using an ingress controller like nginx-ingress is the proper choice in a scenario where you need this feature. The lack of support for authentication in Azure Application Gateway was already reported in this thread.