仅对外访问生效,内部通信不生效
安装http工具
yum -y install httpd-tools
生成密钥文件
htpasswd -c auth <user> #密文输入passwd
创建集群密钥
kubectl -n <namespace> create secret generic basic-auth --from-file=auth
ingress 添加配置
... annotations: nginx.ingress.kubernetes.io/auth-type: basic nginx.ingress.kubernetes.io/auth-secret: basic-auth ...
示例:
apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: prometheus-server-ingress namespace: prometheus-server annotations: kubernetes.io/ingress.class: nginx nginx.ingress.kubernetes.io/rewrite-target: / nginx.ingress.kubernetes.io/auth-type: basic nginx.ingress.kubernetes.io/auth-secret: basic-auth spec: rules: - host: prometheus-server.da-e.top http: paths: - path: / pathType: Prefix backend: service: name: prometheus-server-svc port: number: 80