配置对外部服务的访问

首先,使用与 Egress 流量控制任务中的相同的技术,配置对外部服务 edition.cnn.com 的访问。 但这一次我们将使用单个 ServiceEntry 来启用对服务的 HTTP 和 HTTPS 访问。

1、创建一个 ServiceEntry 启用对 edition.cnn.com 的访问:

kubectl apply -f - <<EOF
apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
  name: edition-cnn-com
spec:
  hosts:
  - edition.cnn.com
  ports:
  - number: 80
    name: http-port
    protocol: HTTP
  - number: 443
    name: https-port
    protocol: HTTPS
  resolution: DNS
EOF

2、向外部的 HTTP 服务发送请求:

kubectl exec "${SOURCE_POD}" -c sleep -- curl -sSL -o /dev/null -D - http://edition.cnn.com/politics
HTTP/1.1 301 Moved Permanently
...
location: https://edition.cnn.com/politics
...

HTTP/2 200
...

用于 egress 流量的 TLS 发起

1、重新定义上一节的 ServiceEntryVirtualService 以重写 HTTP 请求端口,并添加一个 DestinationRule 以执行 TLS 发起。

 kubectl apply -f - <<EOF
apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
  name: edition-cnn-com
spec:
  hosts:
  - edition.cnn.com
  ports:
  - number: 80
    name: http-port
    protocol: HTTP
    targetPort: 443
  - number: 443
    name: https-port
    protocol: HTTPS
  resolution: DNS
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: edition-cnn-com
spec:
  host: edition.cnn.com
  trafficPolicy:
    portLevelSettings:
    - port:
        number: 80
      tls:
        mode: SIMPLE # initiates HTTPS when accessing edition.cnn.com
EOF

上面的 DestinationRule 将对端口80和 ServiceEntry 上的HTTP请求执行TLS发起。然后将端口 80 上的请求重定向到目标端口 443。

2、如上一节一样,向 http://edition.cnn.com/politics 发送 HTTP 请求:

kubectl exec "${SOURCE_POD}" -c sleep -- curl -sSL -o /dev/null -D - http://edition.cnn.com/politics
HTTP/1.1 200 OK
...

参考:

https://preliminary.istio.io/latest/zh/docs/tasks/traffic-management/egress/egress-tls-origination/

相关文章:

  • 2021-06-15
  • 2022-12-23
  • 2021-04-24
  • 2021-09-21
  • 2022-12-23
  • 2021-12-05
猜你喜欢
  • 2021-10-22
  • 2022-01-01
  • 2021-07-08
  • 2022-12-23
  • 2021-05-30
  • 2022-12-23
  • 2021-05-23
相关资源
相似解决方案