【问题标题】:Istio Gateway/VirtualService does not work (local ip works)Istio Gateway/VirtualService 不工作(本地 ip 工作)
【发布时间】:2019-09-22 23:24:41
【问题描述】:

我刚刚在服务上第一次设置 istio,但我无法让网关/vs 正常工作。

这是我的配置,与文档一致:

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: dragon-gateway
spec:
  selector:
    # use Istio default gateway implementation
    istio: ingressgateway
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "*"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: dragon
spec:
  hosts:
  - "vtest.westus.cloudapp.azure.com"
  gateways:
  - dragon-gateway
  http:
  - match:
    - uri:
        prefix: /
    - uri:
        prefix: /status
    - uri:
        prefix: /delay
    - uri:
        prefix: /api/values
    route:
    - destination:
        host: dragon
        port:
          number: 80

kubectl 描述看起来不错:

Name:         dragon-gateway
Namespace:    default
Labels:       <none>
Annotations:  kubectl.kubernetes.io/last-applied-configuration:
                {"apiVersion":"networking.istio.io/v1alpha3","kind":"Gateway","metadata":{"annotations":{},"name":"dragon-gateway","namespace":"default"},...
API Version:  networking.istio.io/v1alpha3
Kind:         Gateway
Metadata:
  Creation Timestamp:  2019-09-22T22:54:31Z
  Generation:          1
  Resource Version:    723889
  Self Link:           /apis/networking.istio.io/v1alpha3/namespaces/default/gateways/dragon-gateway
  UID:                 f0738082-dd8b-11e9-b099-e259debf6109
Spec:
  Selector:
    Istio:  ingressgateway
  Servers:
    Hosts:
      *
    Port:
      Name:      http
      Number:    80
      Protocol:  HTTP


Name:         dragon
Namespace:    default
Labels:       <none>
Annotations:  kubectl.kubernetes.io/last-applied-configuration:
                {"apiVersion":"networking.istio.io/v1alpha3","kind":"VirtualService","metadata":{"annotations":{},"name":"dragon","namespace":"default"},"...
API Version:  networking.istio.io/v1alpha3
Kind:         VirtualService
Metadata:
  Creation Timestamp:  2019-09-22T22:54:31Z
  Generation:          1
  Resource Version:    723891
  Self Link:           /apis/networking.istio.io/v1alpha3/namespaces/default/virtualservices/dragon
  UID:                 f0988c3c-dd8b-11e9-b099-e259debf6109
Spec:
  Gateways:
    dragon-gateway
  Hosts:
    vtest.westus.cloudapp.azure.com
  Http:
    Match:
      Uri:
        Prefix:  /
      Uri:
        Prefix:  /status
      Uri:
        Prefix:  /delay
      Uri:
        Prefix:  /api/values
    Route:
      Destination:
        Host:  dragon
        Port:
          Number:  80

服务的配置如下:

apiVersion: v1
kind: Service
metadata:
  namespace: flight
  name: dragon
  labels:
    app: dragon
    release: r1
    version: 1.0.0
spec:
type: ClusterIP
  ports:
      - name: http
        port: 80
        targetPort: 80
      - name: https
        port: 443
        targetPort: 80

 selector:
    app: dragon
    release: r1

docker 文件很简单:

FROM microsoft/dotnet:latest AS runtime


# ports 
EXPOSE 80
EXPOSE 443

WORKDIR /
COPY /publish /app

RUN dir /app

WORKDIR /app

FROM runtime AS final
ENTRYPOINT ["dotnet", "dragon.dll"]

如果您有任何想法,请告诉我。我试图从另一个 pod 卷曲,它可以工作。问题是使用外部 IP 或使用分配给网关的内部 IP。这些都不起作用。

提前感谢任何线索。

编辑:

添加有关 curl 的更多信息

curl 40.118.228.111/api/values -v
*   Trying 40.118.228.111...
* TCP_NODELAY set
* Connected to 40.118.228.111 (40.118.228.111) port 80 (#0)
> GET /api/values HTTP/1.1
> Host: 40.118.228.111
> User-Agent: curl/7.55.1
> Accept: */*
>
< HTTP/1.1 404 Not Found
< date: Sun, 22 Sep 2019 23:27:54 GMT
< server: istio-envoy
< content-length: 0
<
* Connection #0 to host 40.118.228.111 left intact

同时添加代理状态:

NAME                                                   CDS        LDS        EDS               RDS        PILOT                           VERSION
dragon-dc789456b-g9fxb.flight                          SYNCED     SYNCED     SYNCED (50%)      SYNCED     istio-pilot-689d75bc8-j7j8m     1.1.3
istio-ingressgateway-5c4f9f859d-nj9sq.istio-system     SYNCED     SYNCED     SYNCED (100%)     SYNCED     istio-pilot-689d75bc8-j7j8m     1.1.3

【问题讨论】:

    标签: kubernetes istio azure-aks envoyproxy


    【解决方案1】:

    您好像将dragon VirtualService 和dragon-gateway 放在默认命名空间中?

    由于服务名称依赖于 dns,并且通常 pod 的 resolv.conf 搜索路径仅包含本地命名空间,因此服务名称 dragon 只能在同一命名空间内正确解析。而是将 fqdn 用于 dragon 服务:

    ...
        route:
        - destination:
            host: dragon.flight.svc.cluster.local
            port:
              number: 80
    

    您已将 istio 配置为基于主机名进行路由,但您的 curl 命令使用的是 ip 地址。使用这样的 A 记录配置 DNS - vtest.westus.cloudapp.azure.com -> 40.118.228.111,或者强制 curl 发送正确的主机头:

    curl http://vtest.westus.cloudapp.azure.com/api/values --resolve vtest.westus.cloudapp.azure.com:80:40.118.228.111
    

    【讨论】:

    • 谢谢erk。我尝试使用主机:dragon.flight.svc.cluster.local,但没有运气。我是否也需要更改主机?或者这个值并不重要,因为我现在使用 ip?
    • 我在消息的编辑中也添加了 istioctl proxy-status。
    • 另外,有什么方法可以检查所有的 dns 条目并进行一些跟踪?
    • 啊,是的,您需要提供正确的主机名。您的网关允许所有主机,但 VirtualService 只接受 vtest.westus.cloudapp.azure.com。试试curl http://vtest.westus.cloudapp.azure.com/api/values --resolve vtest.westus.cloudapp.azure.com:80:40.118.228.111
    • 有趣。看起来问题出在主机(下)。目前尚不清楚为什么......但正在使用的值是 spec: hosts: - "*"
    【解决方案2】:

    您好,我不是 istio 专家,但经过调查,它看起来像是在使用主机和 istio 网关、虚拟网络服务,您应该使用 Host prefix 以通过 host HTTP Headerlike this:

    curl -I -HHost:httpbin.example.com http://$INGRESS_HOST:$INGRESS_PORT/
    

    这是必需的,因为您的入口网关配置为处理“httpbin.example.com”,但在您的测试环境中,您没有该主机的 DNS 绑定,只是将您的请求发送到入口 IP。

    从另一个角度来看,此设置必须与 Vitualservice 匹配:

    VirtualService 必须绑定到网关,并且必须有一个或多个与服务器中指定的主机匹配的主机。

    指定'*' 绑定所有主机名。 您还可以使用这种方法限制虚拟服务或为主机/主机等服务器指定多个规则。

    您可以在此处找到更多高级示例-Istio Server:

    希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-29
      • 2019-04-16
      • 2021-02-04
      相关资源
      最近更新 更多