# 方法1 使用base64用户名密码
apiVersion: v1
kind: Secret
metadata:
name: authsecret2
namespace: default
type: kubernetes.io/basic-auth
data:
username: dXNlcg== # 用户名base64格式: user
password: cGFzc3dvcmQ= # 密码: password
---
# 方法2,使用加密的用户名密码 生成密码并base64
# htpasswd -nb user password | openssl base64
apiVersion: v1
kind: Secret
metadata:
name: authsecret
namespace: default
data:
users: |2
dGVzdDokYXByMSRINnVza2trVyRJZ1hMUDZld1RyU3VCa1RycUU4d2ovCnRlc3QyOiRhcHIxJGQ5
aHI5SEJCJDRIeHdnVWlyM0hQNEVzZ2dQL1FObzAK
# 2个用户,内容如下
# test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/
# test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0
---
# 定义中间件
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: test-auth
spec:
basicAuth:
secret: authsecret2
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: xxx
spec:
entryPoints:
- websecure
routes:
- match: Host(`dash.xx.com`)
kind: Rule
middlewares:
- name: test-auth
namespace: default
...
生成密码
yum install -y httpd
apt install apache2-utils
#生成密码文件
htpasswd -bc temp.txt username 123456
直接生成并显示
htpasswd -n username