我正在尝试从 istio 中的一个 Pod 调用在另一个 Pod 中运行的 Web 服务。
我用 python 编写了这两个微服务。您能告诉我如何从一个 pod 中运行的一个微服务到另一个 pod 中运行的另一个微服务进行 https 调用吗?
我可以从 istio 网站找到以下示例命令。
kubectl exec $(kubectl get pod -l app=sleep -o jsonpath={.items..metadata.name}) -c istio-proxy -- curl https://httpbin:8000/headers -o /dev/null -s -w '%{http_code}\n' --key /etc/certs/key.pem --cert /etc/certs/cert-chain.pem --cacert /etc/certs/root-cert.pem -k
但是这是从 istio-proxy 容器进行 https 调用,但是我的微服务如何将请求转发到 istio-proxy,然后将请求转发到不同 pod 中的另一个 istio-proxy?
从此链接https://istio.io/docs/concepts/security/ ,我无法理解“Istio 将出站流量从客户端重新路由到客户端的本地 sidecar Envoy”这一说法。?我的 python 微服务中调用 https Web 服务的代码有何变化?如果有的话请给出完整的例子?
最佳答案
这个task istio 文档中展示了双向 TLS 如何与 HTTPS 服务配合使用。它包括:
- 在没有 Istio sidecar 的情况下部署 HTTPS 服务
- 使用 Istio 部署 HTTPS 服务并禁用相互 TLS
- 部署启用了相互 TLS 的 HTTPS 服务。
上述所有场景都提供了可以在一个微服务容器上运行的命令,以访问另一个微服务的 https 端点。例如,从 sleep 容器通过 https 访问 nginx
kubectl exec $(kubectl get pod -l app=sleep -o jsonpath={.items..metadata.name}) -c sleep -- curl https://my-nginx -k
istio 的好处是您不需要在 python 应用程序中进行任何代码更改。 Istio 代理端汽车将执行必要的操作来启用 mTLS 等安全功能。
关于kubernetes - 如何在 istio 中实现安全的服务间通信?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59907689/