我的前端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
只是为了确保:你的调用是在客户端触发的吗?如果是,那就是原因,因为... http://backend-svc:8000/users/
是由核心组件发出的DNS条目,并且只在集群内部可用。
也就是说,你应该在集群中创建一个 闸道 自定义资源.完整的描述是 此处
网关可以让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
一个很好的资源可以将这些东西拼凑在一起。Istio入门页面