Minikube部署在EC2实例中。库伯内特斯仪表板在Minikube中部署为集群ip服务
Nginx-Intrace-Controller部署为NodePort服务。入口YAML文件如下:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
namespace: kubernetes-dashboard
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/ssl-passthrough: "true"
nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
nginx.ingress.kubernetes.io/use-regex: "true"
nginx.ingress.kubernetes.io/rewrite-target: "/$1"
name: ingress-resource
spec:
rules:
- http:
paths:
- path: /kubedashboard
pathType: Prefix
backend:
service:
name: kubernetes-dashboard
port:
number: 443
入口地址是:
MinikubeIP是:
MinikubeIP和入口地址是不同的。我没有在Ingress. yaml中提到任何主机。
入口和库伯内特斯仪表板部署在同一个命名空间:kubernetes-dashboard。
如何通过入口访问kubernetes仪表板?
我想通过以下方式访问:
curl https://localhost:NodePort/kubedashboard --insecure
或
curl https://MinikubeIP:NodePort/kubedashboard --insecure
或
curl https://EC2PublicIP:NodePort/kubedashboard --insecure
你不需要入口,ingress
仅用于端口80和443,如果你想使用节点端口访问仪表板,只需将仪表板服务类型设置为NodePort。
然后你应该能够使用curl访问https://localhost:NodePort/--in安全
kubectl patch service kubernetes-dashboard -n kubernetes-dashboard -p '{"spec": {"type": "NodePort"}}'
kubectl get service kubernetes-dashboard -n kubernetes-dashboard
如果你真的想使用入口。使用下面的入口,那么你可以从https://localhost/kubedashboard/访问
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: kubernetes-dashboard
annotations:
nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
nginx.ingress.kubernetes.io/rewrite-target: /$2
nginx.ingress.kubernetes.io/configuration-snippet: |
rewrite ^(/kubedashboard)$ $1/ redirect;
namespace: kubernetes-dashboard
spec:
ingressClassName: nginx
rules:
- http:
paths:
- path: /kubedashboard(/|$)(.*)
pathType: ImplementationSpecific
backend:
service:
name: kubernetes-dashboard
port:
number: 443