• 使用通配符主机配置 Egress 流量
    • 背景
    • 开始之前
    • 配置到通配符主机的直接流量
      • 清理到通配符主机的直接流量
    • 配置到通配符主机的 egress gateway
      • 针对单个托管服务器的通配符配置
        • 清理单个托管服务器的通配符配置
      • 任意域名的通配符配置
        • 使用 SNI 代理配置 egress gateway
        • 通过具有 SNI 代理的 egress gateway 配置流量
        • SNI 监控和访问策略
          • 清理监控和策略
        • 清理任意域名的通配符配置
    • 清理
    • 相关内容

    使用通配符主机配置 Egress 流量

    控制 Egress 流量任务和配置 Egress Gateway 示例讲述了如何为类似 edition.cnn.com 的特定主机名配置egress 流量。此示例演示了如何为一组处于公共域(如 *.wikipedia.org)的主机启用 egress 流量,而非单独配置每个主机。

    背景

    假设您希望在 Istio 中为 wikipedia.org 网站的所有语言版本启用 egress 流量。每个特定语言版本的 wikipedia.org都有自己的主机名,例如 en.wikipedia.orgde.wikipedia.org 分别对应英文和德文。您希望通过通用配置项对所有 wikipedia 网站启用 egress 流量,而无需单独配置每个语言的站点。

    开始之前

    • 按照安装指南中的说明安装 Istio。

    • 启动 sleep 示例,它将被用作外部请求的测试源。

    如果您启用了自动 sidecar 注入,请运行

    Zip

    1. $ kubectl apply -f @samples/sleep/sleep.yaml@

    否则,您需要在部署 sleep 应用之前手动注入 sidecar:

    Zip

    1. $ kubectl apply -f <(istioctl kube-inject -f @samples/sleep/sleep.yaml@)

    请注意,任何您能够 execcurl 的 pod 都可以作为示例。

    • 创建一个 shell 变量来保存源 pod 的名称,以便将请求发送到外部服务。如果您使用 sleep 示例,请运行:
    1. $ export SOURCE_POD=$(kubectl get pod -l app=sleep -o jsonpath={.items..metadata.name})

    配置到通配符主机的直接流量

    访问公共域中的一组主机的第一步(也是最简单的一步)是使用通配符主机配置一个简单的 ServiceEntry,并从 sidecar 直接请求 service。当直接请求 service(意即不通过 egress gateway)时,通配符主机的配置和其余主机(例如全限定的)配置并没有什么不同,只是在公共域中有许多主机时会更方便。

    • *.wikipedia.org 定义一个 ServiceEntry 和对应的 VirtualSevice
    1. $ kubectl apply -f - <<EOF
    2. apiVersion: networking.istio.io/v1alpha3
    3. kind: ServiceEntry
    4. metadata:
    5. name: wikipedia
    6. spec:
    7. hosts:
    8. - "*.wikipedia.org"
    9. ports:
    10. - number: 443
    11. name: tls
    12. protocol: TLS
    13. ---
    14. apiVersion: networking.istio.io/v1alpha3
    15. kind: VirtualService
    16. metadata:
    17. name: wikipedia
    18. spec:
    19. hosts:
    20. - "*.wikipedia.org"
    21. tls:
    22. - match:
    23. - port: 443
    24. sni_hosts:
    25. - "*.wikipedia.org"
    26. route:
    27. - destination:
    28. host: "*.wikipedia.org"
    29. port:
    30. number: 443
    31. EOF
    • 发送请求到 https://en.wikipedia.org 和 https://de.wikipedia.org:
    1. $ kubectl exec -it $SOURCE_POD -c sleep -- sh -c 'curl -s https://en.wikipedia.org/wiki/Main_Page | grep -o "<title>.*</title>"; curl -s https://de.wikipedia.org/wiki/Wikipedia:Hauptseite | grep -o "<title>.*</title>"'
    2. <title>Wikipedia, the free encyclopedia</title>
    3. <title>Wikipedia Die freie Enzyklopädie</title>

    清理到通配符主机的直接流量

    1. $ kubectl delete serviceentry wikipedia
    2. $ kubectl delete virtualservice wikipedia

    配置到通配符主机的 egress gateway

    通过 egress gateway 访问通配符主机的配置取决于通配符域名集合和是否由单个公共主机提供。.wikipedia.org 的情况就是如此。所有特定语言的网站都由 wikipedia.org 服务器之一提供服务。您可以将流量路由到任意 .wikipedia.org 网站的 IP,包括 www.wikipedia.org,然后它将设法为任意特定网站提供服务。

    在通常情况下,单个托管服务器并没有提供一个通配符域下的所有域名,此时就需要一个更复杂的配置。

    针对单个托管服务器的通配符配置

    当所有通配符主机都由单个服务器提供服务时,基于 egress gateway 到一个通配符主机的配置和到任意主机的配置非常相似,除了一个例外:配置后的路由目的地址将与配置的主机(通配符)不同。它将使用域名集合的单一服务器主机进行配置。

    • *.wikipedia.org 创建一个 egress Gateway、一个 destination rule 和一 个 virtual service,以将流量定向到 egress gateway,并从 egress gateway 发送到外部 service。
    1. $ kubectl apply -f - <<EOF
    2. apiVersion: networking.istio.io/v1alpha3
    3. kind: Gateway
    4. metadata:
    5. name: istio-egressgateway
    6. spec:
    7. selector:
    8. istio: egressgateway
    9. servers:
    10. - port:
    11. number: 443
    12. name: tls
    13. protocol: TLS
    14. hosts:
    15. - "*.wikipedia.org"
    16. tls:
    17. mode: PASSTHROUGH
    18. ---
    19. apiVersion: networking.istio.io/v1alpha3
    20. kind: DestinationRule
    21. metadata:
    22. name: egressgateway-for-wikipedia
    23. spec:
    24. host: istio-egressgateway.istio-system.svc.cluster.local
    25. subsets:
    26. - name: wikipedia
    27. ---
    28. apiVersion: networking.istio.io/v1alpha3
    29. kind: VirtualService
    30. metadata:
    31. name: direct-wikipedia-through-egress-gateway
    32. spec:
    33. hosts:
    34. - "*.wikipedia.org"
    35. gateways:
    36. - mesh
    37. - istio-egressgateway
    38. tls:
    39. - match:
    40. - gateways:
    41. - mesh
    42. port: 443
    43. sni_hosts:
    44. - "*.wikipedia.org"
    45. route:
    46. - destination:
    47. host: istio-egressgateway.istio-system.svc.cluster.local
    48. subset: wikipedia
    49. port:
    50. number: 443
    51. weight: 100
    52. - match:
    53. - gateways:
    54. - istio-egressgateway
    55. port: 443
    56. sni_hosts:
    57. - "*.wikipedia.org"
    58. route:
    59. - destination:
    60. host: www.wikipedia.org
    61. port:
    62. number: 443
    63. weight: 100
    64. EOF
    • 为目的服务器创建一个 ServiceEntry,即 www.wikipedia.org
    1. $ kubectl apply -f - <<EOF
    2. apiVersion: networking.istio.io/v1alpha3
    3. kind: ServiceEntry
    4. metadata:
    5. name: www-wikipedia
    6. spec:
    7. hosts:
    8. - www.wikipedia.org
    9. ports:
    10. - number: 443
    11. name: tls
    12. protocol: TLS
    13. resolution: DNS
    14. EOF
    • 发送请求到 https://en.wikipedia.org 和 https://de.wikipedia.org:
    1. $ kubectl exec -it $SOURCE_POD -c sleep -- sh -c 'curl -s https://en.wikipedia.org/wiki/Main_Page | grep -o "<title>.*</title>"; curl -s https://de.wikipedia.org/wiki/Wikipedia:Hauptseite | grep -o "<title>.*</title>"'
    2. <title>Wikipedia, the free encyclopedia</title>
    3. <title>Wikipedia Die freie Enzyklopädie</title>
    • 检查 egress gateway 代理的统计数据,找到对应于到 *.wikipedia.org 的请求的 counter。如果 Istio 部署在 istio-systemnamespace 中,打印 counter 的命令为:
    1. $ kubectl exec -it $(kubectl get pod -l istio=egressgateway -n istio-system -o jsonpath='{.items[0].metadata.name}') -c istio-proxy -n istio-system -- curl -s localhost:15000/stats | grep www.wikipedia.org.upstream_cx_total
    2. cluster.outbound|443||www.wikipedia.org.upstream_cx_total: 2

    清理单个托管服务器的通配符配置

    1. $ kubectl delete serviceentry www-wikipedia
    2. $ kubectl delete gateway istio-egressgateway
    3. $ kubectl delete virtualservice direct-wikipedia-through-egress-gateway
    4. $ kubectl delete destinationrule egressgateway-for-wikipedia

    任意域名的通配符配置

    上一节中的配置之所以有效,是因为所有 .wikipedia.org 网站都可以由任何一个 .wikipedia.org 服务器提供服务。然而并非总是如此。例如,您可能希望配置 egress 控制以访问更一般的通配符域名,如 .com 或者 .org

    配置到任意通配符域名的流量为 Istio gateway 带来了挑战。 在上一节中,您将流量定向到 www.wikipedia.org,并且在配置期间,您的 gateway知道此主机。但是,gateway 无法知道它收到请求的任意主机的 IP 地址。这是由于 Envoy 的限制,默认 Istioegress gateway 使用它作为代理。Envoy 将流量路由到预定义的主机、预定义的 IP 地址或请求的原始目标 IP 地址。在 gateway 的情况下,请求的原始目的 IP将会丢失,因为请求会首先路由到 egress gateway,故其目标 IP 地址为 gateway 的 IP 地址。

    因此,基于 Envoy 的 Istio gateway 无法将流量路由到未预先配置的任意主机,也就无法对任意通配符域名执行流量控制。要为 HTTPS 和任何 TLS 启用此类流量控制,除了 Envoy 之外,还需要部署 SNI 转发代理。Envoy 会将发往通配符域名的请求路由到 SNI 转发代理,而 SNI 转发代理将转发请求到 SNI 值指定的目的地。

    具有 SNI 代理的 egress gateway 和 Istio 体系结构的相关部分如下图所示:

    具有 SNI proxy 的 Egress Gateway

    具有 SNI proxy 的 Egress Gateway

    以下部分介绍如何使用 SNI 代理重新部署 egress gateway,然后配置 Istio 通过 gateway 将 HTTPS 流量路由到任意通配符域名。

    使用 SNI 代理配置 egress gateway

    在本节中,您部署的 egress gateway 在标准的 Istio Envoy 代理之外,还会部署一个 SNI 代理。此示例使用 Nginx 作为 SNI代理,但是,任何能够根据任意的、非提前配置的 SNI 值路由流量的 SNI 代理都可以使用。SNI 代理将会监听 8443 端口,您也可以使用任何端口,但需与指定给egress Gateway 的和 VirtualServices 绑定的端口不同。SNI 代理会将流量转发到 443 端口。

    • 为 Nginx SNI 代理创建一个配置文件。当需要时,您可能希望编辑该文件指定附加的 Nginx 配置。请注意,serverlisten 指令指定端口 8443,其 proxy_pass 指令使用 ssl_preread_server_name443 端口及 ssl_prereadon 来启用 SNI 读取。
    1. $ cat <<EOF > ./sni-proxy.conf
    2. user www-data;
    3. events {
    4. }
    5. stream {
    6. log_format log_stream '\$remote_addr [\$time_local] \$protocol [\$ssl_preread_server_name]'
    7. '\$status \$bytes_sent \$bytes_received \$session_time';
    8. access_log /var/log/nginx/access.log log_stream;
    9. error_log /var/log/nginx/error.log;
    10. # tcp forward proxy by SNI
    11. server {
    12. resolver 8.8.8.8 ipv6=off;
    13. listen 127.0.0.1:8443;
    14. proxy_pass \$ssl_preread_server_name:443;
    15. ssl_preread on;
    16. }
    17. }
    18. EOF
    • 创建一个 Kubernetes ConfigMap 来保存Nginx SNI 的配置:
    1. $ kubectl create configmap egress-sni-proxy-configmap -n istio-system --from-file=nginx.conf=./sni-proxy.conf
    • 以下命令将生成 istio-egressgateway-with-sni-proxy.yaml 文件,您可以选择性编辑并部署。
    1. $ cat <<EOF | helm template install/kubernetes/helm/istio/ --name istio-egressgateway-with-sni-proxy --namespace istio-system -x charts/gateways/templates/deployment.yaml -x charts/gateways/templates/service.yaml -x charts/gateways/templates/serviceaccount.yaml -x charts/gateways/templates/autoscale.yaml -x charts/gateways/templates/role.yaml -x charts/gateways/templates/rolebindings.yaml --set global.istioNamespace=istio-system -f - > ./istio-egressgateway-with-sni-proxy.yaml
    2. gateways:
    3. enabled: true
    4. istio-ingressgateway:
    5. enabled: false
    6. istio-egressgateway:
    7. enabled: false
    8. istio-egressgateway-with-sni-proxy:
    9. enabled: true
    10. labels:
    11. app: istio-egressgateway-with-sni-proxy
    12. istio: egressgateway-with-sni-proxy
    13. replicaCount: 1
    14. autoscaleMin: 1
    15. autoscaleMax: 5
    16. cpu:
    17. targetAverageUtilization: 80
    18. serviceAnnotations: {}
    19. type: ClusterIP
    20. ports:
    21. - port: 443
    22. name: https
    23. secretVolumes:
    24. - name: egressgateway-certs
    25. secretName: istio-egressgateway-certs
    26. mountPath: /etc/istio/egressgateway-certs
    27. - name: egressgateway-ca-certs
    28. secretName: istio-egressgateway-ca-certs
    29. mountPath: /etc/istio/egressgateway-ca-certs
    30. configVolumes:
    31. - name: sni-proxy-config
    32. configMapName: egress-sni-proxy-configmap
    33. additionalContainers:
    34. - name: sni-proxy
    35. image: nginx
    36. volumeMounts:
    37. - name: sni-proxy-config
    38. mountPath: /etc/nginx
    39. readOnly: true
    40. EOF
    • 部署新的 egress gateway:
    1. $ kubectl apply -f ./istio-egressgateway-with-sni-proxy.yaml
    2. serviceaccount "istio-egressgateway-with-sni-proxy-service-account" created
    3. role "istio-egressgateway-with-sni-proxy-istio-system" created
    4. rolebinding "istio-egressgateway-with-sni-proxy-istio-system" created
    5. service "istio-egressgateway-with-sni-proxy" created
    6. deployment "istio-egressgateway-with-sni-proxy" created
    7. horizontalpodautoscaler "istio-egressgateway-with-sni-proxy" created
    • 验证新的 egress gateway 工作正常。请注意,pod 包含两个容器(一个是 Envoy 代理,另一个是 SNI 代理)。
    1. $ kubectl get pod -l istio=egressgateway-with-sni-proxy -n istio-system
    2. NAME READY STATUS RESTARTS AGE
    3. istio-egressgateway-with-sni-proxy-79f6744569-pf9t2 2/2 Running 0 17s
    • 创建一个 service entry,指定静态地址为 127.0.0.1 (localhost),并对定向到新 service entry 的流量禁用双向 TLS。
    1. $ kubectl apply -f - <<EOF
    2. apiVersion: networking.istio.io/v1alpha3
    3. kind: ServiceEntry
    4. metadata:
    5. name: sni-proxy
    6. spec:
    7. hosts:
    8. - sni-proxy.local
    9. location: MESH_EXTERNAL
    10. ports:
    11. - number: 8443
    12. name: tcp
    13. protocol: TCP
    14. resolution: STATIC
    15. endpoints:
    16. - address: 127.0.0.1
    17. ---
    18. apiVersion: networking.istio.io/v1alpha3
    19. kind: DestinationRule
    20. metadata:
    21. name: disable-mtls-for-sni-proxy
    22. spec:
    23. host: sni-proxy.local
    24. trafficPolicy:
    25. tls:
    26. mode: DISABLE
    27. EOF

    通过具有 SNI 代理的 egress gateway 配置流量

    • *.wikipedia.org 定义一个 ServiceEntry
    1. $ cat <<EOF | kubectl create -f -
    2. apiVersion: networking.istio.io/v1alpha3
    3. kind: ServiceEntry
    4. metadata:
    5. name: wikipedia
    6. spec:
    7. hosts:
    8. - "*.wikipedia.org"
    9. ports:
    10. - number: 443
    11. name: tls
    12. protocol: TLS
    13. EOF
    • .wikipedia.org 创建一个 egress Gateway,端口为 443,协议为 TLS,并创建一个 virtual service 以将目的为 .wikipedia.org的流量定向到 gateway。
    1. $ kubectl apply -f - <<EOF
    2. apiVersion: networking.istio.io/v1alpha3
    3. kind: Gateway
    4. metadata:
    5. name: istio-egressgateway-with-sni-proxy
    6. spec:
    7. selector:
    8. istio: egressgateway-with-sni-proxy
    9. servers:
    10. - port:
    11. number: 443
    12. name: tls
    13. protocol: TLS
    14. hosts:
    15. - "*.wikipedia.org"
    16. tls:
    17. mode: PASSTHROUGH
    18. ---
    19. apiVersion: networking.istio.io/v1alpha3
    20. kind: DestinationRule
    21. metadata:
    22. name: egressgateway-for-wikipedia
    23. spec:
    24. host: istio-egressgateway-with-sni-proxy.istio-system.svc.cluster.local
    25. subsets:
    26. - name: wikipedia
    27. ---
    28. apiVersion: networking.istio.io/v1alpha3
    29. kind: VirtualService
    30. metadata:
    31. name: direct-wikipedia-through-egress-gateway
    32. spec:
    33. hosts:
    34. - "*.wikipedia.org"
    35. gateways:
    36. - mesh
    37. - istio-egressgateway-with-sni-proxy
    38. tls:
    39. - match:
    40. - gateways:
    41. - mesh
    42. port: 443
    43. sni_hosts:
    44. - "*.wikipedia.org"
    45. route:
    46. - destination:
    47. host: istio-egressgateway-with-sni-proxy.istio-system.svc.cluster.local
    48. subset: wikipedia
    49. port:
    50. number: 443
    51. weight: 100
    52. - match:
    53. - gateways:
    54. - istio-egressgateway-with-sni-proxy
    55. port: 443
    56. sni_hosts:
    57. - "*.wikipedia.org"
    58. route:
    59. - destination:
    60. host: sni-proxy.local
    61. port:
    62. number: 8443
    63. weight: 100
    64. EOF
    • 发送 HTTPS 请求到 https://en.wikipedia.org 和 https://de.wikipedia.org:
    1. $ kubectl exec -it $SOURCE_POD -c sleep -- sh -c 'curl -s https://en.wikipedia.org/wiki/Main_Page | grep -o "<title>.*</title>"; curl -s https://de.wikipedia.org/wiki/Wikipedia:Hauptseite | grep -o "<title>.*</title>"'
    2. <title>Wikipedia, the free encyclopedia</title>
    3. <title>Wikipedia Die freie Enzyklopädie</title>
    • 检查 egress gateway 代理的统计数据,找到对应于到 *.wikipedia.org 的请求的 counter(到 SNI 代理流量的 counter)。如果 Istio 部署在 istio-system namespace 中,打印 counter 的命令为:
    1. $ kubectl exec -it $(kubectl get pod -l istio=egressgateway-with-sni-proxy -n istio-system -o jsonpath='{.items[0].metadata.name}') -c istio-proxy -n istio-system -- curl -s localhost:15000/stats | grep sni-proxy.local.upstream_cx_total
    2. cluster.outbound|8443||sni-proxy.local.upstream_cx_total: 2
    • 检查 SNI 代理的日志。如果 Istio 部署在 istio-system namespace 中,打印日志的命令为:
    1. $ kubectl logs -l istio=egressgateway-with-sni-proxy -n istio-system -c sni-proxy
    2. 127.0.0.1 [01/Aug/2018:15:32:02 +0000] TCP [en.wikipedia.org]200 81513 280 0.600
    3. 127.0.0.1 [01/Aug/2018:15:32:03 +0000] TCP [de.wikipedia.org]200 67745 291 0.659
    • 检查 mixer 日志。如果 Istio 部署在 istio-system namespace 中,打印日志的命令为:
    1. $ kubectl -n istio-system logs -l istio-mixer-type=telemetry -c mixer | grep '"connectionEvent":"open"' | grep '"sourceName":"istio-egressgateway' | grep 'wikipedia.org'; done
    2. {"level":"info","time":"2018-08-26T16:16:34.784571Z","instance":"tcpaccesslog.logentry.istio-system","connectionDuration":"0s","connectionEvent":"open","connection_security_policy":"unknown","destinationApp":"","destinationIp":"127.0.0.1","destinationName":"unknown","destinationNamespace":"default","destinationOwner":"unknown","destinationPrincipal":"cluster.local/ns/istio-system/sa/istio-egressgateway-with-sni-proxy-service-account","destinationServiceHost":"","destinationWorkload":"unknown","protocol":"tcp","receivedBytes":298,"reporter":"source","requestedServerName":"placeholder.wikipedia.org","sentBytes":0,"sourceApp":"istio-egressgateway-with-sni-proxy","sourceIp":"172.30.146.88","sourceName":"istio-egressgateway-with-sni-proxy-7c4f7868fb-rc8pr","sourceNamespace":"istio-system","sourceOwner":"kubernetes://apis/extensions/v1beta1/namespaces/istio-system/deployments/istio-egressgateway-with-sni-proxy","sourcePrincipal":"cluster.local/ns/default/sa/default","sourceWorkload":"istio-egressgateway-with-sni-proxy","totalReceivedBytes":298,"totalSentBytes":0}

    注意 requestedServerName 属性。

    SNI 监控和访问策略

    现在,一旦通过一个 egress gateway 引导 egress 流量,您就可以在 egress 流量上安全的应用监控和访问策略。在本小节中,您将为到 *.wikipedia.org的 egress 流量定义一个 log entry 和访问策略。

    1. $ kubectl apply -f - <<EOF
    2. # Log entry for egress access
    3. apiVersion: "config.istio.io/v1alpha2"
    4. kind: logentry
    5. metadata:
    6.   name: egress-access
    7.   namespace: istio-system
    8. spec:
    9.   severity: '"info"'
    10.   timestamp: context.time | timestamp("2017-01-01T00:00:00Z")
    11.   variables:
    12.     connectionEvent: connection.event | ""
    13.     source: source.labels["app"] | "unknown"
    14.     sourceNamespace: source.namespace | "unknown"
    15.     sourceWorkload: source.workload.name | ""
    16.     sourcePrincipal: source.principal | "unknown"
    17.     requestedServerName: connection.requested_server_name | "unknown"
    18.     destinationApp: destination.labels["app"] | ""
    19.   monitored_resource_type: '"UNSPECIFIED"'
    20. ---
    21. # Handler for info egress access entries
    22. apiVersion: "config.istio.io/v1alpha2"
    23. kind: stdio
    24. metadata:
    25.   name: egress-access-logger
    26.   namespace: istio-system
    27. spec:
    28.   severity_levels:
    29.     info: 0 # output log level as info
    30.   outputAsJson: true
    31. ---
    32. # Rule to handle access to *.wikipedia.org
    33. apiVersion: "config.istio.io/v1alpha2"
    34. kind: rule
    35. metadata:
    36.   name: handle-wikipedia-access
    37.   namespace: istio-system
    38. spec:
    39.   match: source.labels["app"] == "istio-egressgateway-with-sni-proxy" && destination.labels["app"] == "" && connection.event == "open"
    40.   actions:
    41.   - handler: egress-access-logger.stdio
    42.     instances:
    43.       - egress-access.logentry
    44. EOF
    • 发送 HTTPS 请求到 https://en.wikipedia.org 和 https://de.wikipedia.org:
    1. $ kubectl exec -it $SOURCE_POD -c sleep -- sh -c 'curl -s https://en.wikipedia.org/wiki/Main_Page | grep -o "<title>.*</title>"; curl -s https://de.wikipedia.org/wiki/Wikipedia:Hauptseite | grep -o "<title>.*</title>"'
    2. <title>Wikipedia, the free encyclopedia</title>
    3. <title>Wikipedia Die freie Enzyklopädie</title>
    • 检查 mixer 日志。如果 Istio 部署在 istio-system namespace 中,打印日志的命令为:
    1. $ kubectl -n istio-system logs -l istio-mixer-type=telemetry -c mixer | grep 'egress-access.logentry.istio-system'; done
    • 定义一个策略,允许访问除英文版 Wikipedia 之外匹配 *.wikipedia.org 的主机名:
    1. $ cat <<EOF | kubectl create -f -
    2. apiVersion: "config.istio.io/v1alpha2"
    3. kind: listchecker
    4. metadata:
    5. name: wikipedia-checker
    6. namespace: istio-system
    7. spec:
    8. overrides: ["en.wikipedia.org"] # overrides 提供一个静态列表
    9. blacklist: true
    10. ---
    11. apiVersion: "config.istio.io/v1alpha2"
    12. kind: listentry
    13. metadata:
    14. name: requested-server-name
    15. namespace: istio-system
    16. spec:
    17. value: connection.requested_server_name
    18. ---
    19. # Rule to check access to *.wikipedia.org
    20. apiVersion: "config.istio.io/v1alpha2"
    21. kind: rule
    22. metadata:
    23. name: check-wikipedia-access
    24. namespace: istio-system
    25. spec:
    26. match: source.labels["app"] == "istio-egressgateway-with-sni-proxy" && destination.labels["app"] == ""
    27. actions:
    28. - handler: wikipedia-checker.listchecker
    29. instances:
    30. - requested-server-name.listentry
    31. EOF
    • 发送一个 HTTPS 请求到被纳入黑名单的 https://en.wikipedia.org:
    1. $ kubectl exec -it $SOURCE_POD -c sleep -- sh -c 'curl -v https://en.wikipedia.org/wiki/Main_Page'
    2. ...
    3. curl: (35) Unknown SSL protocol error in connection to en.wikipedia.org:443
    4. command terminated with exit code 35
    • 发送 HTTPS 请求到其余网站,例如 https://es.wikipedia.org 和 https://de.wikipedia.org:
    1. $ kubectl exec -it $SOURCE_POD -c sleep -- sh -c 'curl -s https://es.wikipedia.org/wiki/Wikipedia:Portada | grep -o "<title>.*</title>"; curl -s https://de.wikipedia.org/wiki/Wikipedia:Hauptseite | grep -o "<title>.*</title>"'
    2. <title>Wikipedia, la enciclopedia libre</title>
    3. <title>Wikipedia Die freie Enzyklopädie</title>
    清理监控和策略
    1. $ kubectl delete rule handle-wikipedia-access check-wikipedia-access -n istio-system
    2. $ kubectl delete logentry egress-access -n istio-system
    3. $ kubectl delete stdio egress-access-logger -n istio-system
    4. $ kubectl delete listentry requested-server-name -n istio-system
    5. $ kubectl delete listchecker wikipedia-checker -n istio-system

    清理任意域名的通配符配置

    • 删除 *.wikipedia.org 的配置项:
    1. $ kubectl delete serviceentry wikipedia
    2. $ kubectl delete gateway istio-egressgateway-with-sni-proxy
    3. $ kubectl delete virtualservice direct-wikipedia-through-egress-gateway
    4. $ kubectl delete destinationrule egressgateway-for-wikipedia
    • 删除 egressgateway-with-sni-proxy Deployment 的配置项:
    1. $ kubectl delete serviceentry sni-proxy
    2. $ kubectl delete destinationrule disable-mtls-for-sni-proxy
    3. $ kubectl delete -f ./istio-egressgateway-with-sni-proxy.yaml
    4. $ kubectl delete configmap egress-sni-proxy-configmap -n istio-system
    • 删除您创建的配置文件:
    1. $ rm ./istio-egressgateway-with-sni-proxy.yaml
    2. $ rm ./sni-proxy.conf

    清理

    关闭 sleep service:

    Zip

    1. $ kubectl delete -f @samples/sleep/sleep.yaml@

    相关内容

    Egress gateway 性能测试

    评估加入 Egress gateway 对性能造成的影响。

    使用外部 MongoDB 服务

    描述了一个基于 Istio 的 Bookinfo 示例的简单场景。

    HTTP Egress 流量监控和访问策略

    描述如何配置 Istio 进行 HTTP Egress 流量监控和访问策略。

    使用外部 TCP 服务

    描述基于 Istio 的 Bookinfo 示例的简单场景。

    使用外部 Web 服务

    描述基于 Istio Bookinfo 示例的简单场景。

    Egress TLS 流量中的 SNI 监控及策略

    如何为 Egress TLS 流量配置 SNI 监控并应用策略。