Add basic-auth wati in ingress-nginx class

This commit is contained in:
niusmallnan
2021-04-14 20:30:05 +08:00
parent f3432ff282
commit e1b7672796
4 changed files with 59 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
## Traefik Auth
This can be used in the cluster which uses the nginx-ingress.
We use `basic-auth` to control the access of kube-explorer. The auth token is stored in the secret.
The default user is `niusmallnan`, and password is `dagedddd`. You can replace to another value with `htpasswd` tool.
```
htpasswd -nb username password | base64
```
To install this mode, just run this script:
```
kubectl apply -f ./secret.yaml
export MY_XIP_IO=$(curl -sL ipinfo.io/ip)
envsubst < ./ingress.yaml.tpl | kubectl apply -f -
```
For more infos: https://kubernetes.github.io/ingress-nginx/examples/auth/basic/

View File

@@ -0,0 +1,25 @@
# Note: please replace the host first
# To use xip.io: http://xip.io/
# To get your public IP: curl ipinfo.io/ip
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: kube-explorer
namespace: kube-system
labels:
app: kube-explorer
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/auth-type: basic
nginx.ingress.kubernetes.io/auth-secret: kube-explorer
nginx.ingress.kubernetes.io/auth-realm: 'Authentication Required - kube-explorer'
spec:
rules:
- host: "${MY_XIP_IO}.xip.io"
http:
paths:
- path: /
backend:
serviceName: kube-explorer
servicePort: 8989

View File

@@ -0,0 +1,13 @@
# To create an encoded user:password pair, the following command can be used:
# htpasswd -nb user password | base64
apiVersion: v1
kind: Secret
metadata:
name: kube-explorer
namespace: kube-system
labels:
app: kube-explorer
data:
auth: bml1c21hbGxuYW46JGFwcjEkbDdUZjJOdWskbmNXajYubHYvMGNkcXM0NFoyelVQLgoK
type: Opaque