在k8s节点上执行
密码生成
htpasswd -c auth <用户名>
# 输入密码
创建保密字典
namespace=<K8s项目名称>
kubectl create secret generic basic-auth --from-file=auth -n ${namespace}
Ingress配置密钥
添加注解
nginx.ingress.kubernetes.io/auth-type: basic
# 对应保密字典
nginx.ingress.kubernetes.io/auth-secret: basic-auth
# 错误提示
nginx.ingress.kubernetes.io/auth-realm: 'Authentication Required!'