gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 11:46:39 31 4
gpt4 key购买 nike

我的前端 pod 正在尝试与我的后端 pod 通信以获取数据库中的所有用户。当我在前端 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 应用程序提供服务(不确定这是否会成为问题)。

编辑:一些反馈说我需要调整我的网关和/或虚拟服务文件。这是它们现在的样子:

# 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

最佳答案

您的代码示例中有几处看起来不对:

  1. 您的 Istio 虚拟服务路由与请求不匹配。正确的格式应该是这样的:

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. 您必须修改前端代码才能调用网关后端 URL。此 URL 需要包括您的网关的外部 IP 或域名以及外部 HTTP 端口。

将这些东西拼凑在一起的好资源是 Istio Getting Started Page

关于nginx - 使用 Istio 在两个 pod 之间进行简单的 http 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61653064/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com