Kubernetes Ingress は常にトラフィックを間違ったポッドに誘導する

Kubernetes Ingress は常にトラフィックを間違ったポッドに誘導する

minikubeKubernetesクラスタ(ローカル)に次の設定があります

  1. 名前空間customer-a
  • 1 回のデプロイメント -> 「Hi from Customer A」を出力します
  • 1 LoadBalancer タイプのサービス
  • 1 イングレス -> ホストcustomer-a.example.com
  1. 名前空間customer-b
  • 1 回のデプロイメント -> 「Hi from Customer B」を出力します
  • 1 LoadBalancer タイプのサービス
  • 1 イングレス -> ホストcustomer-b.example.com
  1. 名前空間customer-c
  • 1 回のデプロイメント -> 「Hi from Customer C」と出力します
  • 1 LoadBalancer タイプのサービス
  • 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.comcustomer-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 プロトコルでは、同じマシンで実行されている 2 つのアプリケーションが同じポート番号を持つことはできません。そのため、この場合は、3 つのデプロイメントすべてにカスタム ポート番号を設定し、ロード バランサー、イングレス、または nginx 構成でそれに応じてマップする必要があります。

関連情報