• Egress 网关的 TLS 发起过程
    • 开始之前
    • 使用 Egress 网关发起 TLS
      • 清理 TLS 发起示例的内容
    • 使用 Egress 网关执行双向 TLS 的发起
      • 生成客户端和服务端的证书及私钥
      • 部署一个双向 TLS 服务器
        • 部署一个容器来测试 NGINX Deployment
      • 重新部署带有客户端证书的 Egress 网关
      • 为 Egress 流量配置双向 TLS 的发起
      • 清理双向 TLS 发起的例子
    • 清理
    • 相关内容

    Egress 网关的 TLS 发起过程

    Egress 流量 TLS 示例中展示了如何配置 Istio 来发起 TLS,用于和外部进行通信。配置 Egress 网关示例中展示了如何使用独立的 egress 网关服务来对 Egress 流量进行转发。这个例子中结合了前面的两个,描述了如何配置 Egress 网关,来发起对外的 TLS 访问。

    开始之前

    • 依照安装指南的介绍,部署 Istio。

    • 启动 sleep 示例应用,这一应用将作为后续步骤中的测试工具,用于发起对外连接。

    如果启用了 Sidecar 的自动注入功能,使用下面的命令:

    Zip

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

    否则就只能用手工注入的方式来部署 sleep 应用了:

    Zip

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

    记录一下 Pod 名称,后面的步骤中会使用 exec 进入 Pod 执行 curl 命令。

    • 创建一个环境变量,保存用于向外部服务发送流量的 Pod 名称。

    如果使用的是 sleep 应用,运行:

    1. $ export SOURCE_POD=$(kubectl get pod -l app=sleep -o jsonpath={.items..metadata.name})
    • 部署 Istio egress 网关

    使用 Egress 网关发起 TLS

    本节描述了如何执行和在 Egress 流量中发起 TLS 示例中一样的过程,只不过这次使用的是 Egress 网关,而不是 Sidecar。

    • edition.cnn.com 定义一个 ServiceEntry
    1. $ kubectl apply -f - <<EOF
    2. apiVersion: networking.istio.io/v1alpha3
    3. kind: ServiceEntry
    4. metadata:
    5. name: cnn
    6. spec:
    7. hosts:
    8. - edition.cnn.com
    9. ports:
    10. - number: 80
    11. name: http
    12. protocol: HTTP
    13. - number: 443
    14. name: https
    15. protocol: HTTPS
    16. resolution: DNS
    17. EOF
    • 发送请求到 http://edition.cnn.com/politics,确认一下新建的 ServiceEntry 已经正常工作。
    1. $ kubectl exec -it $SOURCE_POD -c sleep -- curl -sL -o /dev/null -D - http://edition.cnn.com/politics
    2. HTTP/1.1 301 Moved Permanently
    3. ...
    4. location: https://edition.cnn.com/politics
    5. ...
    6. command terminated with exit code 35

    如果输出内容中看到了 301 Moved Permanently,表示 ServiceEntry 已经成功配置。

    • edition.cnn.com 创建一个 Egress 网关,端口为 443,然后创建一个 DestinationRule,将 Sidecar 的请求重定向到 Egress 网关。

    你可能会想启用双向 TLS,这样源 Pod 和 Egress 网关之间的流量就会被加密了。另外双向 TLS 启用之后,Egress 网关就能够监控到源 Pod 的身份,并根据这一身份执行 Mixer 策略了。

    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: 80
    12. name: https
    13. protocol: HTTPS
    14. hosts:
    15. - edition.cnn.com
    16. tls:
    17. mode: MUTUAL
    18. serverCertificate: /etc/certs/cert-chain.pem
    19. privateKey: /etc/certs/key.pem
    20. caCertificates: /etc/certs/root-cert.pem
    21. ---
    22. apiVersion: networking.istio.io/v1alpha3
    23. kind: DestinationRule
    24. metadata:
    25. name: egressgateway-for-cnn
    26. spec:
    27. host: istio-egressgateway.istio-system.svc.cluster.local
    28. subsets:
    29. - name: cnn
    30. trafficPolicy:
    31. loadBalancer:
    32. simple: ROUND_ROBIN
    33. portLevelSettings:
    34. - port:
    35. number: 80
    36. tls:
    37. mode: ISTIO_MUTUAL
    38. sni: edition.cnn.com
    39. EOF
    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: 80
    12. name: http-port-for-tls-origination
    13. protocol: HTTP
    14. hosts:
    15. - edition.cnn.com
    16. ---
    17. apiVersion: networking.istio.io/v1alpha3
    18. kind: DestinationRule
    19. metadata:
    20. name: egressgateway-for-cnn
    21. spec:
    22. host: istio-egressgateway.istio-system.svc.cluster.local
    23. subsets:
    24. - name: cnn
    25. EOF
    • 定义一个 VirtualService 把流量传递给 Egress 网关,然后创建一个 DestinationRule 来为发往 edition.cnn.com 的流量发起 TLS:
    1. $ kubectl apply -f - <<EOF
    2. apiVersion: networking.istio.io/v1alpha3
    3. kind: VirtualService
    4. metadata:
    5. name: direct-cnn-through-egress-gateway
    6. spec:
    7. hosts:
    8. - edition.cnn.com
    9. gateways:
    10. - istio-egressgateway
    11. - mesh
    12. http:
    13. - match:
    14. - gateways:
    15. - mesh
    16. port: 80
    17. route:
    18. - destination:
    19. host: istio-egressgateway.istio-system.svc.cluster.local
    20. subset: cnn
    21. port:
    22. number: 80
    23. weight: 100
    24. - match:
    25. - gateways:
    26. - istio-egressgateway
    27. port: 80
    28. route:
    29. - destination:
    30. host: edition.cnn.com
    31. port:
    32. number: 443
    33. weight: 100
    34. ---
    35. apiVersion: networking.istio.io/v1alpha3
    36. kind: DestinationRule
    37. metadata:
    38. name: originate-tls-for-edition-cnn-com
    39. spec:
    40. host: edition.cnn.com
    41. trafficPolicy:
    42. loadBalancer:
    43. simple: ROUND_ROBIN
    44. portLevelSettings:
    45. - port:
    46. number: 443
    47. tls:
    48. mode: SIMPLE # initiates HTTPS for connections to edition.cnn.com
    49. EOF
    • 发送请求到 http://edition.cnn.com/politics.
    1. $ kubectl exec -it $SOURCE_POD -c sleep -- curl -sL -o /dev/null -D - http://edition.cnn.com/politics
    2. HTTP/1.1 200 OK
    3. ...
    4. content-length: 150793
    5. ...

    输出内容应该和出口流量的 TLS 一文中的描述一致,消除了 301 Moved Permanently 消息。

    • 检查 istio-egressgateway Pod 的日志,会看到跟我们请求相关的内容。如果 Istio 部署在 istio-system 命名空间,输出日志的命令是:
    1. $ kubectl logs -l istio=egressgateway -c istio-proxy -n istio-system | tail

    应该会看到类似的内容:

    1. "[2018-06-14T13:49:36.340Z] "GET /politics HTTP/1.1" 200 - 0 148528 5096 90 "172.30.146.87" "curl/7.35.0" "c6bfdfc3-07ec-9c30-8957-6904230fd037" "edition.cnn.com" "151.101.65.67:443"

    清理 TLS 发起示例的内容

    删除前面创建的配置对象:

    1. $ kubectl delete gateway istio-egressgateway
    2. $ kubectl delete serviceentry cnn
    3. $ kubectl delete virtualservice direct-cnn-through-egress-gateway
    4. $ kubectl delete destinationrule originate-tls-for-edition-cnn-com
    5. $ kubectl delete destinationrule egressgateway-for-cnn

    使用 Egress 网关执行双向 TLS 的发起

    和前面一节内容类似,这一节中讲述的是配置一个 Egress 网关来为外部服务进行 TLS 发起,不同的是,这次发起的是双向 TLS。

    这个例子相对复杂一些,需要一些特定的准备工作:

    • 生成客户端和服务端证书。
    • 部署一个支持双向 TLS 的外部服务。
    • 重新部署包含双向 TLS 证书的 Egress 网关。然后就可以配置外发流量,通过 Egress 网关来执行 TLS 的发起。

    生成客户端和服务端的证书及私钥

    • 克隆 https://github.com/nicholasjackson/mtls-go-example 仓库:
    1. $ git clone https://github.com/nicholasjackson/mtls-go-example
    • 进入源码目录:
    1. $ cd mtls-go-example
    • nginx.example.com 生成证书,注意用密码替换下面的 password
    1. $ ./generate.sh nginx.example.com password

    所有提示都输入 y

    • 把证书移动到 nginx.example.com 目录:
    1. $ mkdir ../nginx.example.com && mv 1_root 2_intermediate 3_application 4_client ../nginx.example.com
    • 回到前面的目录:
    1. $ cd ..

    部署一个双向 TLS 服务器

    要模拟一个支持双向 TLS 协议的外部服务,可以在 Kubernetes 集群上部署一个 NGINX,但这个服务要排除在服务网格之外,例如部署到一个没有进行 Istio 自动注入的命名空间里。

    • 创建一个 Istio 服务网格范围之外的命名空间,命名为 mesh-external。注意不要在这个命名空间里启用自动注入。
    1. $ kubectl create namespace mesh-external
    • 创建一个 Kubernetes Secrets,用于保存服务和 CA 的证书。
    1. $ kubectl create -n mesh-external secret tls nginx-server-certs --key nginx.example.com/3_application/private/nginx.example.com.key.pem --cert nginx.example.com/3_application/certs/nginx.example.com.cert.pem
    2. $ kubectl create -n mesh-external secret generic nginx-ca-certs --from-file=nginx.example.com/2_intermediate/certs/ca-chain.cert.pem
    • 为 NGINX 服务器创建一个配置文件:
    1. $ cat <<EOF > ./nginx.conf
    2. events {
    3. }
    4. http {
    5. log_format main '$remote_addr - $remote_user [$time_local] $status '
    6. '"$request" $body_bytes_sent "$http_referer" '
    7. '"$http_user_agent" "$http_x_forwarded_for"';
    8. access_log /var/log/nginx/access.log main;
    9. error_log /var/log/nginx/error.log;
    10. server {
    11. listen 443 ssl;
    12. root /usr/share/nginx/html;
    13. index index.html;
    14. server_name nginx.example.com;
    15. ssl_certificate /etc/nginx-server-certs/tls.crt;
    16. ssl_certificate_key /etc/nginx-server-certs/tls.key;
    17. ssl_client_certificate /etc/nginx-ca-certs/ca-chain.cert.pem;
    18. ssl_verify_client on;
    19. }
    20. }
    21. EOF
    • 创建一个 Kubernetes ConfigMap,用于保存 NGINX 服务器的配置:
    1. $ kubectl create configmap nginx-configmap -n mesh-external --from-file=nginx.conf=./nginx.conf
    • 部署 NGINX 服务器:
    1. $ kubectl apply -f - <<EOF
    2. apiVersion: v1
    3. kind: Service
    4. metadata:
    5. name: my-nginx
    6. namespace: mesh-external
    7. labels:
    8. run: my-nginx
    9. spec:
    10. ports:
    11. - port: 443
    12. protocol: TCP
    13. selector:
    14. run: my-nginx
    15. ---
    16. apiVersion: apps/v1
    17. kind: Deployment
    18. metadata:
    19. name: my-nginx
    20. namespace: mesh-external
    21. spec:
    22. selector:
    23. matchLabels:
    24. run: my-nginx
    25. replicas: 1
    26. template:
    27. metadata:
    28. labels:
    29. run: my-nginx
    30. spec:
    31. containers:
    32. - name: my-nginx
    33. image: nginx
    34. ports:
    35. - containerPort: 443
    36. volumeMounts:
    37. - name: nginx-config
    38. mountPath: /etc/nginx
    39. readOnly: true
    40. - name: nginx-server-certs
    41. mountPath: /etc/nginx-server-certs
    42. readOnly: true
    43. - name: nginx-ca-certs
    44. mountPath: /etc/nginx-ca-certs
    45. readOnly: true
    46. volumes:
    47. - name: nginx-config
    48. configMap:
    49. name: nginx-configmap
    50. - name: nginx-server-certs
    51. secret:
    52. secretName: nginx-server-certs
    53. - name: nginx-ca-certs
    54. secret:
    55. secretName: nginx-ca-certs
    56. EOF
    • nginx.example.com 定义一个 ServiceEntryVirtualService,让 Istio 把流向 nginx.example.com 的流量转发到你的 NGINX 服务器:
    1. $ kubectl apply -f - <<EOF
    2. apiVersion: networking.istio.io/v1alpha3
    3. kind: ServiceEntry
    4. metadata:
    5. name: nginx
    6. spec:
    7. hosts:
    8. - nginx.example.com
    9. ports:
    10. - number: 80
    11. name: http
    12. protocol: HTTP
    13. - number: 443
    14. name: https
    15. protocol: HTTPS
    16. resolution: DNS
    17. endpoints:
    18. - address: my-nginx.mesh-external.svc.cluster.local
    19. ports:
    20. https: 443
    21. ---
    22. apiVersion: networking.istio.io/v1alpha3
    23. kind: VirtualService
    24. metadata:
    25. name: nginx
    26. spec:
    27. hosts:
    28. - nginx.example.com
    29. tls:
    30. - match:
    31. - port: 443
    32. sni_hosts:
    33. - nginx.example.com
    34. route:
    35. - destination:
    36. host: nginx.example.com
    37. port:
    38. number: 443
    39. weight: 100
    40. EOF

    部署一个容器来测试 NGINX Deployment

    • 创建 Kubernetes Secrets 来保存客户端和 CA 的证书:
    1. $ kubectl create secret tls nginx-client-certs --key nginx.example.com/4_client/private/nginx.example.com.key.pem --cert nginx.example.com/4_client/certs/nginx.example.com.cert.pem
    2. $ kubectl create secret generic nginx-ca-certs --from-file=nginx.example.com/2_intermediate/certs/ca-chain.cert.pem
    • 部署 sleep 示例应用,加载客户端和 CA 证书,用于测试向 NGINX 服务器发送流量:
    1. $ kubectl apply -f - <<EOF
    2. # Copyright 2017 Istio Authors
    3. #
    4. # Licensed under the Apache License, Version 2.0 (the "License");
    5. # you may not use this file except in compliance with the License.
    6. # You may obtain a copy of the License at
    7. #
    8. # http://www.apache.org/licenses/LICENSE-2.0
    9. #
    10. # Unless required by applicable law or agreed to in writing, software
    11. # distributed under the License is distributed on an "AS IS" BASIS,
    12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13. # See the License for the specific language governing permissions and
    14. # limitations under the License.
    15. ##################################################################################################
    16. # Sleep service
    17. ##################################################################################################
    18. apiVersion: v1
    19. kind: Service
    20. metadata:
    21. name: sleep
    22. labels:
    23. app: sleep
    24. spec:
    25. ports:
    26. - port: 80
    27. name: http
    28. selector:
    29. app: sleep
    30. ---
    31. apiVersion: extensions/v1beta1
    32. kind: Deployment
    33. metadata:
    34. name: sleep
    35. spec:
    36. replicas: 1
    37. template:
    38. metadata:
    39. labels:
    40. app: sleep
    41. spec:
    42. containers:
    43. - name: sleep
    44. image: tutum/curl
    45. command: ["/bin/sleep","infinity"]
    46. imagePullPolicy: IfNotPresent
    47. volumeMounts:
    48. - name: nginx-client-certs
    49. mountPath: /etc/nginx-client-certs
    50. readOnly: true
    51. - name: nginx-ca-certs
    52. mountPath: /etc/nginx-ca-certs
    53. readOnly: true
    54. volumes:
    55. - name: nginx-client-certs
    56. secret:
    57. secretName: nginx-client-certs
    58. - name: nginx-ca-certs
    59. secret:
    60. secretName: nginx-ca-certs
    61. EOF
    • 定义一个环境变量来保存 sleep Pod 的名称:
    1. $ export SOURCE_POD=$(kubectl get pod -l app=sleep -o jsonpath={.items..metadata.name})
    • 使用 sleep Pod 向 NGINX 服务器发送流量。因为 nginx.example.com 并不存在,DNS 也无法解析,所以在 curl 命令中使用了 —resolve 参数来手工完成解析。传递给 —resolve 的 IP(1.1.1.1)无关紧要,只要不是 127.0.0.1 即可。而正常情况下,目标主机的解析是靠 DNS 完成的,就无需这种参数了。
    1. $ kubectl exec -it $SOURCE_POD -c sleep -- curl -v --resolve nginx.example.com:443:1.1.1.1 --cacert /etc/nginx-ca-certs/ca-chain.cert.pem --cert /etc/nginx-client-certs/tls.crt --key /etc/nginx-client-certs/tls.key https://nginx.example.com
    2. ...
    3. Server certificate:
    4. subject: C=US; ST=Denial; L=Springfield; O=Dis; CN=nginx.example.com
    5. start date: 2018-08-16 04:31:20 GMT
    6. expire date: 2019-08-26 04:31:20 GMT
    7. common name: nginx.example.com (matched)
    8. issuer: C=US; ST=Denial; O=Dis; CN=nginx.example.com
    9. SSL certificate verify ok.
    10. > GET / HTTP/1.1
    11. > User-Agent: curl/7.35.0
    12. > Host: nginx.example.com
    13. ...
    14. < HTTP/1.1 200 OK
    15. < Server: nginx/1.15.2
    16. ...
    17. <!DOCTYPE html>
    18. <html>
    19. <head>
    20. <title>Welcome to nginx!</title>
    21. ...
    • 检查服务器,看它是不是需要客户端证书:
    1. $ kubectl exec -it $(kubectl get pod -l app=sleep -o jsonpath={.items..metadata.name}) -c sleep -- curl -k --resolve nginx.example.com:443:1.1.1.1 https://nginx.example.com
    2. <html>
    3. <head><title>400 No required SSL certificate was sent</title></head>
    4. <body bgcolor="white">
    5. <center><h1>400 Bad Request</h1></center>
    6. <center>No required SSL certificate was sent</center>
    7. <hr><center>nginx/1.15.2</center>
    8. </body>
    9. </html>

    重新部署带有客户端证书的 Egress 网关

    • 创建 Kubernetes Secrets 来保存客户端和 CA 证书:
    1. $ kubectl create -n istio-system secret tls nginx-client-certs --key nginx.example.com/4_client/private/nginx.example.com.key.pem --cert nginx.example.com/4_client/certs/nginx.example.com.cert.pem
    2. $ kubectl create -n istio-system secret generic nginx-ca-certs --from-file=nginx.example.com/2_intermediate/certs/ca-chain.cert.pem
    • 生成 istio-egressgateway,加载新的 Secret,参数和生成 istio.yaml 时候一致:
    1. $ helm template install/kubernetes/helm/istio/ --name istio --namespace istio-system -x charts/gateways/templates/deployment.yaml --set gateways.istio-ingressgateway.enabled=false \
    2. --set gateways.istio-egressgateway.enabled=true \
    3. --set 'gateways.istio-egressgateway.secretVolumes[0].name'=egressgateway-certs \
    4. --set 'gateways.istio-egressgateway.secretVolumes[0].secretName'=istio-egressgateway-certs \
    5. --set 'gateways.istio-egressgateway.secretVolumes[0].mountPath'=/etc/istio/egressgateway-certs \
    6. --set 'gateways.istio-egressgateway.secretVolumes[1].name'=egressgateway-ca-certs \
    7. --set 'gateways.istio-egressgateway.secretVolumes[1].secretName'=istio-egressgateway-ca-certs \
    8. --set 'gateways.istio-egressgateway.secretVolumes[1].mountPath'=/etc/istio/egressgateway-ca-certs \
    9. --set 'gateways.istio-egressgateway.secretVolumes[2].name'=nginx-client-certs \
    10. --set 'gateways.istio-egressgateway.secretVolumes[2].secretName'=nginx-client-certs \
    11. --set 'gateways.istio-egressgateway.secretVolumes[2].mountPath'=/etc/nginx-client-certs \
    12. --set 'gateways.istio-egressgateway.secretVolumes[3].name'=nginx-ca-certs \
    13. --set 'gateways.istio-egressgateway.secretVolumes[3].secretName'=nginx-ca-certs \
    14. --set 'gateways.istio-egressgateway.secretVolumes[3].mountPath'=/etc/nginx-ca-certs > \
    15. ./istio-egressgateway.yaml
    • 重新部署 istio-egressgateway
    1. $ kubectl apply -f ./istio-egressgateway.yaml
    2. deployment "istio-egressgateway" configured
    • 校验证书和私钥,是否被成功加载到 istio-egressgateway Pod 之中:
    1. $ kubectl exec -it -n istio-system $(kubectl -n istio-system get pods -l istio=egressgateway -o jsonpath='{.items[0].metadata.name}') -- ls -al /etc/nginx-client-certs /etc/nginx-ca-certs

    /etc/istio/nginx-client-certs 中应该存在 tls.crttls.keyca-chain.cert.pem 则应该存在于 /etc/istio/nginx-ca-certs

    为 Egress 流量配置双向 TLS 的发起

    • nginx.example.com 创建 Egress 网关,端口为 443,使用 DestinationRuleVirtualService 将流量引入 Egress 网关,并从 Egress 网关发到外部服务。
    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: https
    13. protocol: HTTPS
    14. hosts:
    15. - nginx.example.com
    16. tls:
    17. mode: MUTUAL
    18. serverCertificate: /etc/certs/cert-chain.pem
    19. privateKey: /etc/certs/key.pem
    20. caCertificates: /etc/certs/root-cert.pem
    21. ---
    22. apiVersion: networking.istio.io/v1alpha3
    23. kind: DestinationRule
    24. metadata:
    25. name: egressgateway-for-nginx
    26. spec:
    27. host: istio-egressgateway.istio-system.svc.cluster.local
    28. subsets:
    29. - name: nginx
    30. trafficPolicy:
    31. loadBalancer:
    32. simple: ROUND_ROBIN
    33. portLevelSettings:
    34. - port:
    35. number: 443
    36. tls:
    37. mode: ISTIO_MUTUAL
    38. sni: nginx.example.com
    39. EOF
    • 定义一个 VirtualService 来把流量转发到 Egress 网关,DestinationRule 用于执行双向 TLS 的发起:
    1. $ kubectl apply -f - <<EOF
    2. apiVersion: networking.istio.io/v1alpha3
    3. kind: VirtualService
    4. metadata:
    5. name: direct-nginx-through-egress-gateway
    6. spec:
    7. hosts:
    8. - nginx.example.com
    9. gateways:
    10. - istio-egressgateway
    11. - mesh
    12. http:
    13. - match:
    14. - gateways:
    15. - mesh
    16. port: 80
    17. route:
    18. - destination:
    19. host: istio-egressgateway.istio-system.svc.cluster.local
    20. subset: nginx
    21. port:
    22. number: 443
    23. weight: 100
    24. - match:
    25. - gateways:
    26. - istio-egressgateway
    27. port: 443
    28. route:
    29. - destination:
    30. host: nginx.example.com
    31. port:
    32. number: 443
    33. weight: 100
    34. ---
    35. apiVersion: networking.istio.io/v1alpha3
    36. kind: DestinationRule
    37. metadata:
    38. name: originate-mtls-for-nginx
    39. spec:
    40. host: nginx.example.com
    41. trafficPolicy:
    42. loadBalancer:
    43. simple: ROUND_ROBIN
    44. portLevelSettings:
    45. - port:
    46. number: 443
    47. tls:
    48. mode: MUTUAL
    49. clientCertificate: /etc/nginx-client-certs/tls.crt
    50. privateKey: /etc/nginx-client-certs/tls.key
    51. caCertificates: /etc/nginx-ca-certs/ca-chain.cert.pem
    52. sni: nginx.example.com
    53. EOF
    • 发送 HTTP 请求到 http://nginx.example.com
    1. $ kubectl exec -it $SOURCE_POD -c sleep -- curl -s --resolve nginx.example.com:80:1.1.1.1 http://nginx.example.com
    2. <!DOCTYPE html>
    3. <html>
    4. <head>
    5. <title>Welcome to nginx!</title>
    6. ...
    • 输出 istio-egressgateway Pod 的日志,查看和我们发出的请求相关的内容。如果 Istio 部署在 istio-system 命名空间里,输出日志的命令是:
    1. $ kubectl logs -l istio=egressgateway -n istio-system | grep 'nginx.example.com' | grep HTTP

    应该会看到类似的内容:

    1. [2018-08-19T18:20:40.096Z] "GET / HTTP/1.1" 200 - 0 612 7 5 "172.30.146.114" "curl/7.35.0" "b942b587-fac2-9756-8ec6-303561356204" "nginx.example.com" "172.21.72.197:443"

    清理双向 TLS 发起的例子

    • 删除创建的 Kubernetes 资源:
    1. $ kubectl delete secret nginx-server-certs nginx-ca-certs -n mesh-external
    2. $ kubectl delete secret nginx-client-certs nginx-ca-certs
    3. $ kubectl delete secret nginx-client-certs nginx-ca-certs -n istio-system
    4. $ kubectl delete configmap nginx-configmap -n mesh-external
    5. $ kubectl delete service my-nginx -n mesh-external
    6. $ kubectl delete deployment my-nginx -n mesh-external
    7. $ kubectl delete namespace mesh-external
    8. $ kubectl delete gateway istio-egressgateway
    9. $ kubectl delete serviceentry nginx
    10. $ kubectl delete virtualservice direct-nginx-through-egress-gateway
    11. $ kubectl delete destinationrule originate-mtls-for-nginx
    12. $ kubectl delete destinationrule egressgateway-for-nginx
    • 删除证书目录,以及克隆到本地的代码仓库:
    1. $ rm -rf nginx.example.com mtls-go-example
    • 删除用在这个例子中生成的配置文件:
    1. $ rm -f ./nginx.conf ./istio-egressgateway.yaml

    清理

    删除 sleepServiceDeployment

    1. $ kubectl delete service sleep
    2. $ kubectl delete deployment sleep

    相关内容

    Egress gateway 性能测试

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

    使用外部 MongoDB 服务

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

    HTTP Egress 流量监控和访问策略

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

    使用外部 TCP 服务

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

    使用外部 Web 服务

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

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

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