1. Deploy Ingress Controller
-
View Kubernetes version
-
Find a compatible version of Nginx Ingress
Helm Chart version Helm Chart Highest Available Version K8s Adaptor Version 3.x.x 3.36.0 1.16+ 4.x.x 4.4.2 1.19+ Reference: https://github.com/kubernetes/ingress-nginx
-
Installing Nginx Ingress Controller
-
Check out the services
1 2 3 4 5 6 7 8 9 10 11 12
kubectl -n ingress-nginx get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE ingress-nginx-controller LoadBalancer 10.233.11.232 <pending> 80:30914/TCP,443:31493/TCP 14m ingress-nginx-controller-admission ClusterIP 10.233.56.67 <none> 443/TCP 14m kae@node1:~$ kubectl -n ingress-nginx get pod,svc NAME READY STATUS RESTARTS AGE pod/ingress-nginx-controller-666f45c794-h2zk9 1/1 Running 0 14m NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/ingress-nginx-controller LoadBalancer 10.233.11.232 <pending> 80:30914/TCP,443:31493/TCP 14m service/ingress-nginx-controller-admission ClusterIP 10.233.56.67 <none> 443/TCP 14m
2. Add the secret key
-
Generate the secret key
Login user
admin
, login passwordxxxxxx
. -
In the namespace where the service is located, add the credentials
3. Add Ingress forwarding rules
|
|
nginx.ingress.kubernetes.io/auth-type: basic
and nginx.ingress.kubernetes.io/auth-secret: basic-auth
specify that the authentication method is Basic and the authentication secret key is basic-auth
.
4. Accessing services
-
Add hosts to the access host pointing to the cluster host
The domain name is the hosts configured in Ingress, in this case
longhorn.chenshaowen.com
. -
Access to services using domain names
Since Ingress Controller maps its port 80 to 30914 on the host, the service is accessed at
longhorn.chenshaowen.com:30914
.Enter the account
admin
and passwordxxxxx
to view the service. The image below.
Ref
https://www.chenshaowen.com/blog/how-to-add-basic-auth-to-kubernetes-service.html