1 Ingress 进行 BasicAuth 认证
借用 http 的 htpasswd 模块,创建auth文件
yum -y install httpdmkdir basic-authcd basic-auth/htpasswd -c auth admin #admin是认证的用户New password: 123.com #123.com 是 admin认证的密码Re-type new password:123.com
在k8s集群中创建secret
kubectl create secret generic basic-auth --from-file=auth
在ingress.yaml中添加配置
apiVersion: extensions/v1beta1kind: Ingressmetadata:name: ingress-with-authannotations:nginx.ingress.kubernetes.io/auth-type: basicnginx.ingress.kubernetes.io/auth-secret: basic-authnginx.ingress.kubernetes.io/auth-realm: 'Authentication Required - admin'spec:rules:- host: auth.ng.comhttp:paths:- path: /backend:serviceName: ng-svcservicePort: 80
