无法在NGINX入口控制器中使用基本认证



我正在使用NGINX入口控制器,我想使用基本身份验证,但我在浏览器中得到403错误。我用data.authbase64创建了一个秘密,从htpasswd创建的文件中获得,并在入口中添加了注释

annotations:
nginx.org/basic-auth-secret: htpasswd
nginx.org/basic-auth-realm: "Authentication Required"

其中htpasswd为与入口在同一命名空间中的秘密名称。

检查Nginx-ingress pod的日志,我可以找到这个

[error] 1783#1783: *68296 open() "/etc/nginx/secrets/my-demo-htpasswd" failed (2: No such file or directory)

我应该怎么做才能把秘密加载到入口控制器中?

with "您需要使用秘密类型:nginx.org/htpasswd

apiVersion: v1  
kind: Secret  
metadata:  
name: basic-auth  
type: nginx.org/htpasswd  
stringData:  
htpasswd: <copy the contents of the htpasswd file here>
example 
htpasswd: foo:$apr1$T6zUs/pB$xvCvBUfMvvIk8r12lZz9C0

您可以按照以下说明[1]向kubernetes inginx控制器添加基本身份验证。

[1] https://blog.petehouston.com/add-basic-authentication-to-kubernetes-ingress-nginx/