Nếu website của bạn đang public ra internet và bạn cần tạo cho nó 1 password đơn giản và không cần edit Fontend thì có thể làm cách sau:

Bạn dùng câu lệnh này để tạo ra 1 file auth:
htpasswd -c auth nim-private
Sau khi bạn gõ xong nó sẽ tạo ra 1 file auth:

Khúc này khá là quan trọng:
Nếu ingress của bạn tạo cho deployment a là nằm ở namespace a.
thì lúc tạo secret nó cũng sẽ cần ở đúng namespace a
kubectl create secret generic basic-auth --from-file=auth -n namespace-a
Bạn nó giống như thế này:

Tiếp theo bạn tạo ingress và để ý annotations:
$ echo "
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-with-auth
annotations:
# type of authentication
nginx.ingress.kubernetes.io/auth-type: basic
# name of the secret that contains the user/password definitions
nginx.ingress.kubernetes.io/auth-secret: basic-auth
# message to display with an appropriate context why the authentication is required
nginx.ingress.kubernetes.io/auth-realm: 'Authentication Required'
spec:
ingressClassName: nginx
rules:
- host: foo.bar.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: http-svc
port:
number: 80
" | kubectl create -f -
Vậy là xong rồi!
Bạn cũng có cách để đăng nhập nhanh như sau:
https://username:password@integration-nim.nim.com