我面临的问题是我无法使用它的 IP 访问浏览器上的 Kubernetes Ingress。我已经在 Windows 10 Home 上安装了 K8s 和 Minikube。
我正在关注这个官方文档 - https://kubernetes.io/docs/tasks/access-application-cluster/ingress-minikube/
kubectl 创建部署 web --image=gcr.io/google-samples/hello-app:1.0
部署已创建,可以在下图中看到:
kubectl 公开部署 web --type=NodePort --port=8080
这创建了一个可以通过运行以下命令看到的服务:
kubectl get service web
服务截图如下所示:minikube 服务网络
在下面的屏幕截图中,您可以看到我可以在浏览器上查看它。
kubectl apply -f https://k8s.io/examples/service/networking/example-ingress.yaml
顺便说一下,入口 yaml 代码是:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
rules:
- host: hello-world.info
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: web
port:
number: 8080
入口被创建,我可以通过运行以下命令来验证它:kubectl get ingress
屏幕截图如下:入口 ip 列为
192.168.49.2
.所以这意味着如果我应该在浏览器中打开它,那么它应该打开,但不幸的是没有。显示网站无法访问。请参阅下面的截图。问题是什么。请给我一个解决方案?
我还在 etc\hosts 文件上添加了映射。
192.168.49.2 hello-world.info
然后我也尝试在浏览器上打开 hello-world.info 但没有运气。在下图中,我已经 ping 到
hello-world.info
这将转到 IP 地址 192.168.49.2。这表明 etc\hosts 映射是正确的:我也 curl 到 minikube ip 和
hello-world.info
并且都超时。见下图:kubectl describe services web
提供以下详细信息:Name: web
Namespace: default
Labels: app=web
Annotations: <none>
Selector: app=web
Type: NodePort
IP: 10.100.184.92
Port: <unset> 8080/TCP
TargetPort: 8080/TCP
NodePort: <unset> 31880/TCP
Endpoints: 172.17.0.4:8080
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
kubectl describe ingress example-ingress
给出以下输出:Name: example-ingress
Namespace: default
Address: 192.168.49.2
Default backend: default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules:
Host Path Backends
---- ---- --------
hello-world.info
/ web:8080 172.17.0.4:8080)
Annotations: nginx.ingress.kubernetes.io/rewrite-target: /$1
Events: <none>
请帮忙。谢谢你。
最佳答案
与 OP 有相同的问题,并且仅适用于 minikube ssh
,分享下面的ingress.yaml。
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: frontend-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
defaultBackend:
service:
name: default-http-backend
port:
number: 80
rules:
- host: myapp-com # domain (i.e. need to change host table)
http:
paths: # specified path below, only be working when there is more than 1 path; If only having 1 path, it's always using / as path
- path: /
pathType: Prefix
backend:
service:
name: frontend-service # internal service
port:
number: 8080 # port number that internal service exposes
- path: /e($|/)(.*)
pathType: Prefix
backend:
service:
name: express-service # internal service
port:
number: 3000 # port number that internal service exposes
关于kubernetes - 无法使用 Minikube 在 Windows Home 上的浏览器中访问 Kubernetes Ingress?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66275458/