
minikube
我在kubernetes 叢集(本地)中有以下設置
- 名稱空間
customer-a
- 1 部署 -> 列印“Hi from Customer A”
- 1 負載平衡器類型服務
- 1 個入口 -> 主機
customer-a.example.com
- 名稱空間
customer-b
- 1 部署 -> 列印“Hi from Customer B”
- 1 負載平衡器類型服務
- 1 個入口 -> 主機
customer-b.example.com
- 名稱空間
customer-c
- 1 部署 -> 列印“Hi from Customer C”
- 1 負載平衡器類型服務
- 1 個入口 -> 主機
customer-c.example.com
由於我在叢集中運行此設置minikube
,因此我必須使用該minikube tunnel
命令來存取入口服務
這是我目前的設置
// kubectl get ing, svc -n customer-a
NAME CLASS HOSTS ADDRESS PORTS AGE
ingress.networking.k8s.io/customer-a nginx customer-a.example.com 80 11s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/customer-a LoadBalancer 10.96.39.62 127.0.0.1 80:30048/TCP 11s
// kubectl get ing, svc -n customer-b
NAME CLASS HOSTS ADDRESS PORTS AGE
ingress.networking.k8s.io/customer-b nginx customer-b.example.com 192.168.49.2 80 30s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/customer-b LoadBalancer 10.110.126.198 127.0.0.1 80:31292/TCP 30s
// kubectl get ing, svc -n customer-c
NAME CLASS HOSTS ADDRESS PORTS AGE
ingress.networking.k8s.io/customer-c nginx customer-c.example.com 192.168.49.2 80 6m36s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/customer-c LoadBalancer 10.104.99.195 127.0.0.1 80:32717/TCP 6m36s
根據上面的內容,EXTERNAL-IP
所有LoadBalancer
類型的服務都是相同的,但是為了區分流量,我使用了HOSTS
上面的(customer-a.example.com
, customer-b.example.com
, customer-c.example.com
)
我已將 Ip 對應到主機名,如下/etc/hosts
所示:
127.0.0.1 customer-a.example.com customer-b.example.com customer-c.example.com
當我嘗試訪問每個 URL 時,它只會將我定向到相同的結果,即Hi from Customer C
// curl -kv http://customer-a.example.com
> GET / HTTP/1.1
> Host: customer-a.example.com
> User-Agent: curl/7.85.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< date: Thu, 29 Dec 2022 00:24:49 GMT
< server: uvicorn
< content-length: 20
< content-type: application/json
<
* Connection #0 to host customer-a.example.com left intact
{"response":"Hi from Customer C"}
// curl -kv http://customer-b.example.com
> GET / HTTP/1.1
> Host: customer-b.example.com
> User-Agent: curl/7.85.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< date: Thu, 29 Dec 2022 00:24:49 GMT
< server: uvicorn
< content-length: 20
< content-type: application/json
<
* Connection #0 to host customer-b.example.com left intact
{"response":"Hi from Customer C"}
// curl -kv http://customer-c.example.com
> GET / HTTP/1.1
> Host: customer-c.example.com
> User-Agent: curl/7.85.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< date: Thu, 29 Dec 2022 00:24:49 GMT
< server: uvicorn
< content-length: 20
< content-type: application/json
<
* Connection #0 to host customer-c.example.com left intact
{"response":"Hi from Customer C"}
有人可以幫我找到這個問題嗎?我認為這與minikube tunnel
?
答案1
這與 minikube 隧道無關。這裡的問題是您的所有服務都使用相同的連接埠在叢集外部進行通訊。在tcp 協定中,在同一台電腦上執行的兩個應用程式不能具有相同的連接埠號,因此在這種情況下,您需要為所有三個部署配置自訂連接埠號,並在負載平衡器或入口或nginx 配置中相應地映射它們。