使用Istio在两个pod之间进行简单的http请求。

问题描述 投票:0回答:1

我的前端pod试图与我的后端pod对话以获取DB中的所有用户。当我在前端pod的前端和istio-proxy容器中使用curl时,这个调用是直接的,并且工作。

kubectl exec -it frontend-pod -c frontend-container -- bash
curl backend-svc:8000/users/
# returns correct response

kubectl exec -it frontend-pod -c istio-proxy -- bash
curl backend-svc:8000/users/
# returns correct response

然而,我的前端react应用在Chrome浏览器中的这个端点上出现了问题。以下是控制台日志。

GET http://backend-svc:8000/users/ net::ERR_NAME_NOT_RESOLVED

看起来域名无法被解析 知道我在这里做错了什么吗?

我使用nginx为我的前端react应用提供服务(不知道这是否是一个问题)。

EDIT: 有些反馈说我需要调整我的Gateway和或虚拟服务文件。下面是它们现在的样子。

# Source: myapp/gateway.yaml
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: myapp-gateway
spec:
  selector:
    istio: ingressgateway # use istio default controller
  servers:
    - port:
        number: 80
        name: http
        protocol: HTTP
      hosts:
        - '*'
---
# Source: myapp/virtual-service.yaml
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: myapp
spec:
  hosts:
    - '*'
  gateways:
    - myapp-gateway
  http:
    - route:
        - destination:
            host: frontend-svc
            port:
              number: 80
nginx kubernetes istio envoyproxy
1个回答
0
投票

只是为了确保:你的调用是在客户端触发的吗?如果是,那就是原因,因为... http://backend-svc:8000/users/ 是由核心组件发出的DNS条目,并且只在集群内部可用。

也就是说,你应该在集群中创建一个 闸道 自定义资源.完整的描述是 此处

网关可以让Istio的监控和路由规则等功能应用于进入集群的流量。

希望我帮到了你。


0
投票

在你的代码样本中,有几件事情看起来是错误的。

  1. 你的Istio VirtualService Routes与请求不匹配。正确的格式应该是这样的。

apiVersion: networking.istio.io/v1alpha3
    kind: VirtualService
    metadata:
      name: bookinfo
    spec:
      hosts:
      - "*"
      gateways:
      - bookinfo-gateway
      http:
      - match:
        - uri:
            exact: /frontend
        route:
        - destination:
            host: frontend-svc
            port:
              number: 80
  1. 在同一个VirtualService中,你需要一个后端路由。
  2. 你必须修改你的前端代码来调用Gateway后端URL。这个URL需要包括你的网关的外部IP或域名以及外部的HTTP端口。

一个很好的资源可以将这些东西拼凑在一起。Istio入门页面

© www.soinside.com 2019 - 2024. All rights reserved.