gpt4 book ai didi

kubernetes - 使用 istio 通过外部代理引导 http 流量

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

我们在一个启用了 istio 的 kubernetes 集群中运行了一堆微服务。其中一个微服务调用集群外部的外部服务,我需要通过也在集群外部运行的公司代理路由该特定调用。

再解释一下,比如说,我在容器中设置了 HTTP_PROXY,然后 curl 调用 http://external.com调用成功,因为调用是通过代理路由的,但我希望 istio 透明地通过代理进行路由。

例如。 curl http://external.com从容器内,istio 应该通过公司代理自动路由 http 调用并返回响应

我为 external.com 和 proxy.com 创建了服务条目以使调用成功

最佳答案

如果我理解正确,您正在寻找的是 Egress Gateway。

这是从 Istio documentation 配置外部 HTTPS 代理的教程的一部分:

Configure traffic to external HTTPS proxy

  1. Define a TCP (not HTTP!) Service Entry for the HTTPS proxy. Although applications use the HTTP CONNECT method to establish connections with HTTPS proxies, you must configure the proxy for TCP traffic, instead of HTTP. Once the connection is established, the proxy simply acts as a TCP tunnel.

   $ kubectl apply -f - <<EOF
apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
name: proxy
spec:
hosts:
- my-company-proxy.com # ignored
addresses:
- $PROXY_IP/32
ports:
- number: $PROXY_PORT
name: tcp
protocol: TCP
location: MESH_EXTERNAL
EOF
  1. Send a request from the sleep pod in the default namespace. Because the sleep pod has a sidecar, Istio controls its traffic.

   $ kubectl exec -it $SOURCE_POD -c sleep -- sh -c "HTTPS_PROXY=$PROXY_IP:$PROXY_PORT curl https://en.wikipedia.org/wiki/Main_Page" | grep -o "<title>.*</title>"
<title>Wikipedia, the free encyclopedia</title>
  1. Check the Istio sidecar proxy’s logs for your request:
   $ kubectl logs $SOURCE_POD -c istio-proxy
[2018-12-07T10:38:02.841Z] "- - -" 0 - 702 87599 92 - "-" "-" "-" "-" "172.30.109.95:3128" outbound|3128||my-company-proxy.com 172.30.230.52:44478 172.30.109.95:3128 172.30.230.52:44476 -
  1. Check the access log of the proxy for your request:
   $ kubectl exec -it $(kubectl get pod -n external -l app=squid -o jsonpath={.items..metadata.name}) -n external -- tail -f /var/log/squid/access.log
1544160065.248 228 172.30.109.89 TCP_TUNNEL/200 87633 CONNECT en.wikipedia.org:443 - HIER_DIRECT/91.198.174.192 -


查看整个教程,因为它涵盖了设置要求,并且还包含模拟外部代理的步骤,因此您可以比较它是否按预期工作。

istio.io/docs/tasks/traffic-management/egress/http-proxy/

关于kubernetes - 使用 istio 通过外部代理引导 http 流量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58731045/

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