1 Ingress 进行 BasicAuth 认证

借用 http 的 htpasswd 模块,创建auth文件

  1. yum -y install httpd
  2. mkdir basic-auth
  3. cd basic-auth/
  4. htpasswd -c auth admin #admin是认证的用户
  5. New password: 123.com #123.com 是 admin认证的密码
  6. Re-type new password:123.com

在k8s集群中创建secret

  1. kubectl create secret generic basic-auth --from-file=auth

在ingress.yaml中添加配置

  1. apiVersion: extensions/v1beta1
  2. kind: Ingress
  3. metadata:
  4. name: ingress-with-auth
  5. annotations:
  6. nginx.ingress.kubernetes.io/auth-type: basic
  7. nginx.ingress.kubernetes.io/auth-secret: basic-auth
  8. nginx.ingress.kubernetes.io/auth-realm: 'Authentication Required - admin'
  9. spec:
  10. rules:
  11. - host: auth.ng.com
  12. http:
  13. paths:
  14. - path: /
  15. backend:
  16. serviceName: ng-svc
  17. servicePort: 80