Minikube 部署在 EC2 实例中。 Kubernetes 仪表板部署为 Minikube 中的集群 ip 服务
Nginx-Ingress-Controller 部署为 NodePort 服务。 Ingress 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
入口地址是:
Minikube IP 是:
Minikube IP 和入口地址不同。我没有在 Ingress.yaml 中提及任何主机。
Ingress 和 Kubernetes 仪表板部署在同一命名空间中:kubernetes-dashboard。
我应该如何通过 Ingress 访问 Kubernetes 仪表板?
我想通过以下方式访问:
curl https://localhost:NodePort/kubedashboard --insecure
或
curl https://MinikubeIP:NodePort/kubedashboard --insecure
或
curl https://EC2PublicIP:NodePort/kubedashboard --insecure
不需要ingress,
ingress
仅用于端口80和443,如果你想使用节点端口访问dashboard,只需将dashboard服务类型设置为NodePort即可。
然后您应该可以使用
curl https://localhost:NodePort/ --insecure
进行访问
kubectl patch service kubernetes-dashboard -n kubernetes-dashboard -p '{"spec": {"type": "NodePort"}}'
kubectl get service kubernetes-dashboard -n kubernetes-dashboard
如果你真的想使用ingress。使用下面的 ingress,然后就可以从 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
@yip102011 就像手套一样适合我的箱子!谢谢!