Istio istio-ingressgateway 投掷 "no cluster match for URL '/'"

Istio istio-ingressgateway throwing "no cluster match for URL '/'"

我在 docker-desktop 上安装了 Istio。一般来说它工作正常。我正在尝试在一个非常简单的虚拟服务上设置 http-based 匹配,但我只能获得 404。这是技术细节。

我的端点图像是 hashi http-echo,它使用 net/http 库创建一个简单的 http 服务器,return 是您提供的消息。它工作得很好,再简单不过了。

这是我的 pod 和服务配置:

kind: Pod
apiVersion: v1
metadata:
  name: a
  labels:
    app: a
    version: v1
spec:
  containers:
  - name: a
    image: hashicorp/http-echo
    args:
    - "-text='this is service a: v1'"
    - "-listen=:6789"
---
kind: Service
apiVersion: v1
metadata:
  name: a-service
spec:
  selector:
    app: a
    version: v1
  ports:
  # Default port used by the image
  - port: 6789
    targetPort: 6789
    name: http-echo

这是我从同一命名空间中的另一个 pod 卷曲服务的示例:

/ # curl 10.1.0.29:6789
'this is service a: v1'

这里是 docker-desktop 集群中的 pod 运行:

NAME       READY   STATUS    RESTARTS   AGE     IP          NODE             NOMINATED NODE   READINESS GATES
a          2/2     Running   0          45h     10.1.0.29   docker-desktop   <none>           <none>

这是注册和管理 pod 的服务:

NAME         TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)    AGE     SELECTOR
a-service    ClusterIP   10.101.113.9   <none>        6789/TCP   45h     app=a,version=v1

这是我通过 Helm 的 istio istio-ingressgateway pod 规范(似乎工作正常),我列出了它,因为这是我更改的安装的唯一部分,并且更改本身是完全微不足道的(只需添加一个新的端口块,它似乎工作正常,因为确实在进行监听):

gateways:
  istio-ingressgateway:
    name: istio-ingressgateway
    labels:
      app: istio-ingressgateway
      istio: ingressgateway
    ports:
    - port: 15021
      targetPort: 15021
      name: status-port
      protocol: TCP
    - port: 80
      targetPort: 8080
      name: http2
      protocol: TCP
    - port: 443
      targetPort: 8443
      name: https
      protocol: TCP
    - port: 6789
      targetPort: 6789
      name: http-echo
      protocol: TCP

这里是 istio-ingressgateway 上的 kubectl get svc 只是为了表明我确实有一个 external-ip 并且一切看起来都很正常:

NAME                   TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)                                                     AGE     SELECTOR
istio-ingressgateway   LoadBalancer   10.109.63.15    localhost     15021:30095/TCP,80:32454/TCP,443:31644/TCP,6789:30209/TCP   2d16h   app=istio-ingressgateway,istio=ingressgateway
istiod                 ClusterIP      10.96.155.154   <none>        15010/TCP,15012/TCP,443/TCP,15014/TCP                       2d16h   app=istiod,istio=pilot

这是我的虚拟服务:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: a-service
  namespace: default
spec:
  hosts:
  - 'a-service.default.svc.cluster.local'
  gateways:
  - gateway
  http:
  - match:
    - port: 6789
    route:
    - destination:
        host: 'a-service.default.svc.cluster.local'
        port:
          number: 6789

这是我的网关:

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: gateway
  namespace: default
spec:
  selector:
    app: istio-ingressgateway
  servers:
  - port:
      number: 6789
      name: http-echo
      protocol: http
    hosts:
    - 'a-service.default.svc.cluster.local'

最后是来自 istio-ingressgateway 的调试日志,显示尽管所有这些看似正确的 pod、服务、网关、虚拟服务和入口网关配置,入口网关只有 return 404s:

2021-09-27T15:34:41.001773Z debug   envoy connection    [C367] closing data_to_write=143 type=2
2021-09-27T15:34:41.001779Z debug   envoy connection    [C367] setting delayed close timer with timeout 1000 ms
2021-09-27T15:34:41.001786Z debug   envoy pool  [C7] response complete
2021-09-27T15:34:41.001791Z debug   envoy pool  [C7] destroying stream: 0 remaining
2021-09-27T15:34:41.001925Z debug   envoy connection    [C367] write flush complete
2021-09-27T15:34:41.002215Z debug   envoy connection    [C367] remote early close
2021-09-27T15:34:41.002279Z debug   envoy connection    [C367] closing socket: 0
2021-09-27T15:34:41.002348Z debug   envoy conn_handler  [C367] adding to cleanup list
2021-09-27T15:34:41.179213Z debug   envoy conn_handler  [C368] new connection from 192.168.65.3:62904
2021-09-27T15:34:41.179594Z debug   envoy http  [C368] new stream
2021-09-27T15:34:41.179690Z debug   envoy http  [C368][S14851390862777765658] request headers complete (end_stream=true):
':authority', '0:6789'
':path', '/'
':method', 'GET'
'user-agent', 'curl/7.64.1'
'accept', '*/*'
'version', 'TESTING'

2021-09-27T15:34:41.179708Z debug   envoy http  [C368][S14851390862777765658] request end stream
2021-09-27T15:34:41.179828Z debug   envoy router    [C368][S14851390862777765658] no cluster match for URL '/'
2021-09-27T15:34:41.179903Z debug   envoy http  [C368][S14851390862777765658] Sending local reply with details route_not_found
2021-09-27T15:34:41.179949Z debug   envoy http  [C368][S14851390862777765658] encoding headers via codec (end_stream=true):
':status', '404'
'date', 'Mon, 27 Sep 2021 15:34:41 GMT'
'server', 'istio-envoy'

这是 istioct proxy-status:

istioctl proxy-status                                                                                                                     ⎈ docker-desktop/istio-system
NAME                                                   CDS        LDS        EDS        RDS        ISTIOD                     VERSION
a.default                                              SYNCED     SYNCED     SYNCED     SYNCED     istiod-b9c8c9487-clkkt     1.11.3
istio-ingressgateway-5797689568-x47ck.istio-system     SYNCED     SYNCED     SYNCED     SYNCED     istiod-b9c8c9487-clkkt     1.11.3

这是 istioctl pc 集群 $ingressgateway:

SERVICE FQDN                                            PORT      SUBSET     DIRECTION     TYPE           DESTINATION RULE
BlackHoleCluster                                        -         -          -             STATIC
a-service.default.svc.cluster.local                     6789      -          outbound      EDS
agent                                                   -         -          -             STATIC
istio-ingressgateway.istio-system.svc.cluster.local     80        -          outbound      EDS
istio-ingressgateway.istio-system.svc.cluster.local     443       -          outbound      EDS
istio-ingressgateway.istio-system.svc.cluster.local     6789      -          outbound      EDS
istio-ingressgateway.istio-system.svc.cluster.local     15021     -          outbound      EDS
istiod.istio-system.svc.cluster.local                   443       -          outbound      EDS
istiod.istio-system.svc.cluster.local                   15010     -          outbound      EDS
istiod.istio-system.svc.cluster.local                   15012     -          outbound      EDS
istiod.istio-system.svc.cluster.local                   15014     -          outbound      EDS
kube-dns.kube-system.svc.cluster.local                  53        -          outbound      EDS
kube-dns.kube-system.svc.cluster.local                  9153      -          outbound      EDS
kubernetes.default.svc.cluster.local                    443       -          outbound      EDS
prometheus_stats                                        -         -          -             STATIC
sds-grpc                                                -         -          -             STATIC
xds-grpc                                                -         -          -             STATIC
zipkin                                                  -         -          -             STRICT_DNS

这是同一个入口上的 istioctl pc 侦听器:

ADDRESS PORT  MATCH DESTINATION
0.0.0.0 6789  ALL   Route: http.6789
0.0.0.0 15021 ALL   Inline Route: /healthz/ready*
0.0.0.0 15090 ALL   Inline Route: /stats/prometheus*

最后是 istioctl 路由:

NOTE: This output only contains routes loaded via RDS.
NAME          DOMAINS                                 MATCH                  VIRTUAL SERVICE
http.6789     a-service.default.svc.cluster.local     /*                     a-service.default
              *                                       /stats/prometheus*
              *                                       /healthz/ready*

我尝试过多种不同的配置,从更改选择器到确保端口名称匹配以尝试不同的端口。如果我将虚拟服务从 http 更改为 tcp,则端口匹配效果很好。但是因为我的最终目标是进行更高级的 header-based 匹配,所以我需要在 http 上进行匹配。任何见解将不胜感激!

原来问题是我在网关和虚拟服务的 hosts 指令中指定了 service。将 service 指定为主机条目几乎肯定永远不会正确,尽管可以通过将主机 header 添加到 curl 来“解决”这个问题,即 curl ... -H 'Host: kubernetes.docker.internal' ...。但正确的解决方案是简单地添加正确的主机条目,即 - mysite.mycompany.com 等。这种情况下的主机就像 Apache 中的虚拟主机;它们是一个 fqdn,可以解析为网格和集群可以用来向其发送请求的内容。 host,然而,在virtualservice destination 是服务,这有点令人费解,这让我很沮丧。