traefik ingress
The above method needs to introduce haprox
or nginx
introduce an additional proxy forwarding layer, which in fact ingress
provides basic auth
support itself, just ingress
add additional authentication annotations
to the rules.
htpasswd
First, we need to create files for storing usernames and passwords
$ htpasswd -bc auth admin admin
- Then, then create a
auth
file-basedsecret
$ kubectl create secret generic system-basic-auth --from-file=auth -n kube-system
- Now we need to add the
auth-type:basic
andauth-secret:system-basic-auth
annotations to theingress
definition. This tells whattraefik ingress controller
to configure for hostsbasic auth
, and where to readhtpasswd
files from.
apiVersion: extensions/v1beta1
kind: Ingress
metadata: name: traefik-system namespace: kube-system annotations: ingress.kubernetes.io/auth-type: basic ingress.kubernetes.io/auth-secret: system-basic-auth spec: rules: - host: k8s.local http: paths: - path: / backend: serviceName: haproxy servicePort: k8s-ui