This gist shows how to add authentication in a Ingress rule using a secret that contains a file generated with htpasswd. It's important the file generated is named auth (actually - that the secret has a key data.auth), otherwise the ingress-controller returns a 503.
Read more : https://kubernetes.github.io/ingress-nginx/examples/auth/basic
- Create auth credentials
docker run --rm -ti your-org/htpasswd toto-user toto-password > auth
- Create secret
kubectl create secret generic basic-auth --from-file=auth secret "basic-auth" created
- Patch Ingress
annotations:
# type of authentication
nginx.ingress.kubernetes.io/auth-type: basic
# name of the secret that contains the user/password definitions
nginx.ingress.kubernetes.io/auth-secret: basic-auth
# message to display with an appropriate context why the authentication is required
nginx.ingress.kubernetes.io/auth-realm: 'Authentication Required - foo'