MacOS Big Sur 11.6.8Minikube版本:v1.28.0
遵循几个关于入口的教程并尝试使其在本地工作。一切似乎都工作:手动minikube service foo
工作,kubectl get ingress
显示IP, ping指定的主机名解析预期的IP,等等。我试了几次,结果都一样。
我将其归结为kubernetes教程中最简单的复制。io:
# kubectl create deployment web --image=gcr.io/google-samples/hello-app:1.0
# kubectl expose deployment web --type=NodePort --port=8080
# kubectl get service web (ensure it's a node port)
# minikube service web --url (test url)
# kubectl apply -f ingress_hello_world.yaml
# curl localkube.com
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
rules:
- host: localkube.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: web
port:
number: 8080
手工服务:
>minikube service web --url
http://127.0.0.1:50111
❗ Because you are using a Docker driver on darwin, the terminal needs to be open to run it.
>curl http://127.0.0.1:50111
Hello, world!
Version: 1.0.0
Hostname: web-84fb9498c7-hnphb
入口看起来不错:
>minikube addons list | grep ingress
| ingress | minikube | enabled ✅ | Kubernetes |
>kubectl get ingress
NAME CLASS HOSTS ADDRESS PORTS AGE
example-ingress nginx localkube.com 192.168.49.2 80 15m
ping解析/etc/hosts中映射的地址:
>ping localkube.com
PING localkube.com (192.168.49.2): 56 data bytes
我看过类似的问题,没有积极的结果。我已经从这个简单的示例到apache,再到通过配置文件部署mongo。每次我都可以通过手动服务映射或创建外部服务(LoadBalancer/nodePort)来访问应用程序,但是当我到达入口部分时,配置应用没有错误,一切似乎都在工作,除了它实际上…工作。
根据Veera的回答,我研究了macOS和minikube tunnel
的入口问题。为了给别人省去麻烦,下面是我解决这个问题的方法:
- ingress似乎在macOS上不起作用(不同的页面显示"with docker")但我使用其他驱动程序(如hyperkit)也得到了相同的结果。
- 这个问题似乎与IP/网络有关。您无法从本地工作站访问minikube IP。如果您首先运行
minikube ssh
,您可以ping和curl minikube IP和您映射到/etc/hosts中的IP的域名但是,这并不能帮助尝试从浏览器访问服务。 - 解决方案是将域名映射到/etc/hosts中的127.0.0.1(而不是ingress分配的IP),并使用ingress组件来控制域名->
- 则使用
sudo minikube tunnel
启动隧道将保持基本隧道打开,并为任何现有或新的入口组件创建隧道。这与入口规则相结合,将模拟连接到任何解析到本地主机的域的主机头样式。
这是一个完整的mac解决方案的例子。将其转储到名为ingress_hello_world的文件中。并按照注释的说明实现一个简单的入口解决方案,将2个域路由到2个不同的服务(注意,这将与几乎任何内部服务一起工作,并且可以是ClusterIP而不是NodePort):
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
spec:
ingressClassName: nginx
rules:
- host: test1.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: web
port:
number: 8080
- host: test2.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: web2
port:
number: 8080
# Instructions:
# start minikube if not already
# >minikube start --vm-driver=docker
#
# enable ingress if not already
# >minikube addons enable ingress
# >minikube addons list | grep "ingress "
# | ingress | minikube | enabled ✅ | Kubernetes |
#
# >kubectl create deployment web --image=gcr.io/google-samples/hello-app:1.0
# deployment.apps/web created
#
# >kubectl expose deployment web --type=NodePort --port=8080
# service/web exposed
#
# >kubectl create deployment web2 --image=gcr.io/google-samples/hello-app:2.0
# deployment.apps/web2 created
#
# >kubectl expose deployment web2 --port=8080 --type=NodePort
# service/web2 exposed
#
# >kubectl get service | grep web
# web NodePort 10.101.19.188 <none> 8080:31631/TCP 21m
# web2 NodePort 10.102.52.139 <none> 8080:30590/TCP 40s
#
# >minikube service web --url
# http://127.0.0.1:51813
# ❗ Because you are using a Docker driver on darwin, the terminal needs to be open to run it.
#
# ------ in another console ------
# >curl http://127.0.0.1:51813
# ^---- this must match the port from the output above
# Hello, world!
# Version: 1.0.0 <---- will show version 2.0.0 for web2
# Hostname: web-84fb9498c7-7bjtg
# --------------------------------
# ctrl+c to kill tunnel in original tab, repeat with web2 if desired
#
# ------ In another console ------
# >sudo minikube tunnel
# ✅ Tunnel successfully started
#
# (leave open, will show the following when you start an ingress component)
# Starting tunnel for service example-ingress.
# --------------------------------
#
# >kubectl apply -f ingress_hello_world.yaml
# ingress.networking.k8s.io/example-ingress created
#
# >kubectl get ingress example-ingress --watch
# NAME CLASS HOSTS ADDRESS PORTS AGE
# example-ingress nginx test1.com,test2.com 80 15s
# example-ingress nginx test1.com,test2.com 192.168.49.2 80 29s
# wait for this to be populated ----^
#
# >cat /etc/hosts | grep test
# 127.0.0.1 test1.com
# 127.0.0.1 test2.com
# ^---- set this to localhost ip
#
# >ping test1.com
# PING test1.com (127.0.0.1): 56 data bytes
#
# >curl test1.com
# Hello, world!
# Version: 1.0.0
# Hostname: web-84fb9498c7-w6bkc
#
# >curl test2.com
# Hello, world!
# Version: 2.0.0
# Hostname: web2-7df4dcf77b-66g5b
# ------- Cleanup:
# stop tunnel
#
# >kubectl delete -f ingress_hello_world.yaml
# ingress.networking.k8s.io "example-ingress" deleted
#
# >kubectl delete service web
# service "web" deleted
#
# >kubectl delete service web2
# service "web2" deleted
#
# >kubectl delete deployment web
# deployment.apps "web" deleted
#
# >kubectl delete deployment web2
# deployment.apps "web2" deleted
你所描述的行为很可能是因为ingress and ingress-dns addons
目前只在Linux系统上支持,当使用Docker驱动程序时,如minikube文档的已知问题部分所述。
Minikube在Mac和Linux上对入口的支持不同。
在Linux上完全支持入口,因此不需要使用minikube隧道。
在Mac上,由于网络问题有一个开放的问题。文档声明minikube入口插件不受支持,如果不是不正确的话,似乎是误导。只是支持的方式不同(也不一样)。
请通过入口DNS和类似的SO获取更多信息。