共计 764 个字符,预计需要花费 2 分钟才能阅读完成。
Kubernetes中,应用服务使用ingress暴露后,默认是没有账号密码限制的,只要知道ingress的地址,所有人都可以访问服务(除非应用中有账号密码限制),那么是否可以在k8s中给ingress设置账号密码来限制访问呢?
步骤1.
使用htpasswd命令生产auth文件,如List-1,其中 admin 处改为你自己的账号,按提示输入密码
✘ ⚡ root@k8s-master ~/longhorn-test/chatrs/longhorn htpasswd -c auth admin
New password:
Re-type new password:
Adding password for user admin
步骤2.
#记得指定namespace
$ kubectl create secret generic basic-auth --from-file=auth -n longhorn-system
secret "basic-auth" created
步骤3.
kubectl edit ingress xxx -n xx
增加如下 annotations:
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: ingress-with-auth
annotations:
nginx.ingress.kubernetes.io/auth-type: basic
# 使用刚才创建的 secret 名称
nginx.ingress.kubernetes.io/auth-secret: basic-auth
# "Authentication Required"这个只是账号密码输错时的一个提示
nginx.ingress.kubernetes.io/auth-realm: 'Authentication Required'
正文完
Hi, this is a comment.
To get started with moderating, editing, and deleting comments, please visit the Comments screen in the dashboard.
Commenter avatars come from Gravatar.