mirror of https://github.com/istio/istio.io.git
[zh] Replace sleep with curl in tasks/traffic-management/ (#15795)
* [zh] Replace sleep with curl in tasks/traffic-management/ * apply suggestions from wilsonwu
This commit is contained in:
parent
7b1ad175e3
commit
972db801d3
|
@ -27,18 +27,18 @@ test: yes
|
|||
使用 `demo` [安装配置文件](/zh/docs/setup/additional-setup/config-profiles/)或者
|
||||
[启用 Envoy 的访问记录](/zh/docs/tasks/observability/logs/access-log/#enable-envoy-s-access-logging)。
|
||||
|
||||
* 部署 [sleep]({{< github_tree >}}/samples/sleep) 这个示例应用,用作发送请求的测试源。
|
||||
* 部署 [curl]({{< github_tree >}}/samples/curl) 这个示例应用,用作发送请求的测试源。
|
||||
如果您启用了[自动注入 Sidecar](/zh/docs/setup/additional-setup/sidecar-injection/#automatic-sidecar-injection),
|
||||
使用以下的命令来部署示例应用:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl apply -f @samples/sleep/sleep.yaml@
|
||||
$ kubectl apply -f @samples/curl/curl.yaml@
|
||||
{{< /text >}}
|
||||
|
||||
否则,在部署 `sleep` 应用前,使用以下命令手动注入 Sidecar:
|
||||
否则,在部署 `curl` 应用前,使用以下命令手动注入 Sidecar:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl apply -f <(istioctl kube-inject -f @samples/sleep/sleep.yaml@)
|
||||
$ kubectl apply -f <(istioctl kube-inject -f @samples/curl/curl.yaml@)
|
||||
{{< /text >}}
|
||||
|
||||
{{< tip >}}
|
||||
|
@ -48,7 +48,7 @@ test: yes
|
|||
* 设置环境变量 `SOURCE_POD`,值为您的源 Pod 的名称:
|
||||
|
||||
{{< text bash >}}
|
||||
$ export SOURCE_POD=$(kubectl get pod -l app=sleep -o jsonpath='{.items..metadata.name}')
|
||||
$ export SOURCE_POD=$(kubectl get pod -l app=curl -o jsonpath='{.items..metadata.name}')
|
||||
{{< /text >}}
|
||||
|
||||
## Envoy 转发流量到外部服务{#envoy-passthrough-to-external-services}
|
||||
|
@ -86,7 +86,7 @@ Istio 代理允许调用未知的服务。如果这个选项设置为 `REGISTRY_
|
|||
1. 从 `SOURCE_POD` 向外部 HTTPS 服务发出两个请求,确保能够得到状态码为 `200` 的响应:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl exec "$SOURCE_POD" -c sleep -- curl -sSI https://www.google.com | grep "HTTP/"; kubectl exec "$SOURCE_POD" -c sleep -- curl -sI https://edition.cnn.com | grep "HTTP/"
|
||||
$ kubectl exec "$SOURCE_POD" -c curl -- curl -sSI https://www.google.com | grep "HTTP/"; kubectl exec "$SOURCE_POD" -c curl -- curl -sI https://edition.cnn.com | grep "HTTP/"
|
||||
HTTP/2 200
|
||||
HTTP/2 200
|
||||
{{< /text >}}
|
||||
|
@ -135,7 +135,7 @@ Istio 代理允许调用未知的服务。如果这个选项设置为 `REGISTRY_
|
|||
1. 从 `SOURCE_POD` 向外部 HTTPS 服务发出几个请求,验证它们现在是否被阻止:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl exec "$SOURCE_POD" -c sleep -- curl -sI https://www.google.com | grep "HTTP/"; kubectl exec "$SOURCE_POD" -c sleep -- curl -sI https://edition.cnn.com | grep "HTTP/"
|
||||
$ kubectl exec "$SOURCE_POD" -c curl -- curl -sI https://www.google.com | grep "HTTP/"; kubectl exec "$SOURCE_POD" -c curl -- curl -sI https://edition.cnn.com | grep "HTTP/"
|
||||
command terminated with exit code 35
|
||||
command terminated with exit code 35
|
||||
{{< /text >}}
|
||||
|
@ -181,7 +181,7 @@ Istio 代理允许调用未知的服务。如果这个选项设置为 `REGISTRY_
|
|||
1. 从 `SOURCE_POD` 向外部的 HTTP 服务发出一个请求:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl exec "$SOURCE_POD" -c sleep -- curl -sS http://httpbin.org/headers
|
||||
$ kubectl exec "$SOURCE_POD" -c curl -- curl -sS http://httpbin.org/headers
|
||||
{
|
||||
"headers": {
|
||||
"Accept": "*/*",
|
||||
|
@ -229,7 +229,7 @@ Istio 代理允许调用未知的服务。如果这个选项设置为 `REGISTRY_
|
|||
1. 从 `SOURCE_POD` 往外部 HTTPS 服务发送请求:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl exec "$SOURCE_POD" -c sleep -- curl -sSI https://www.google.com | grep "HTTP/"
|
||||
$ kubectl exec "$SOURCE_POD" -c curl -- curl -sSI https://www.google.com | grep "HTTP/"
|
||||
HTTP/2 200
|
||||
{{< /text >}}
|
||||
|
||||
|
@ -253,7 +253,7 @@ Istio 代理允许调用未知的服务。如果这个选项设置为 `REGISTRY_
|
|||
endpoint 发出 **curl** 请求:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl exec "$SOURCE_POD" -c sleep -- time curl -o /dev/null -sS -w "%{http_code}\n" http://httpbin.org/delay/5
|
||||
$ kubectl exec "$SOURCE_POD" -c curl -- time curl -o /dev/null -sS -w "%{http_code}\n" http://httpbin.org/delay/5
|
||||
200
|
||||
real 0m5.024s
|
||||
user 0m0.003s
|
||||
|
@ -321,7 +321,7 @@ EOF
|
|||
3) 几秒后,重新发出 **curl** 请求:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl exec "$SOURCE_POD" -c sleep -- time curl -o /dev/null -sS -w "%{http_code}\n" http://httpbin.org/delay/5
|
||||
$ kubectl exec "$SOURCE_POD" -c curl -- time curl -o /dev/null -sS -w "%{http_code}\n" http://httpbin.org/delay/5
|
||||
504
|
||||
real 0m3.149s
|
||||
user 0m0.004s
|
||||
|
@ -506,14 +506,14 @@ $ istioctl install <flags-you-used-to-install-Istio> --set values.global.proxy.i
|
|||
|
||||
### 访问外部服务 {#access-the-external-services}
|
||||
|
||||
由于绕行配置仅影响新的部署,因此您需要按照[开始之前](#before-you-begin)部分中的说明重新部署 `sleep` 程序。
|
||||
由于绕行配置仅影响新的部署,因此您需要按照[开始之前](#before-you-begin)部分中的说明重新部署 `curl` 程序。
|
||||
|
||||
在更新 `istio-sidecar-injector` configmap 和重新部署 `sleep` 程序后,
|
||||
在更新 `istio-sidecar-injector` configmap 和重新部署 `curl` 程序后,
|
||||
Istio Sidecar 将仅拦截和管理集群中的内部请求。任何外部请求都会绕过 Sidecar,
|
||||
并直接到达其预期的目的地。举个例子:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl exec "$SOURCE_POD" -c sleep -- curl -sS http://httpbin.org/headers
|
||||
$ kubectl exec "$SOURCE_POD" -c curl -- curl -sS http://httpbin.org/headers
|
||||
{
|
||||
"headers": {
|
||||
"Accept": "*/*",
|
||||
|
@ -569,8 +569,8 @@ $ istioctl install <flags-you-used-to-install-Istio>
|
|||
|
||||
## 清理 {#cleanup}
|
||||
|
||||
关闭服务 [sleep]({{< github_tree >}}/samples/sleep):
|
||||
关闭服务 [curl]({{< github_tree >}}/samples/curl):
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl delete -f @samples/sleep/sleep.yaml@
|
||||
$ kubectl delete -f @samples/curl/curl.yaml@
|
||||
{{< /text >}}
|
||||
|
|
|
@ -23,27 +23,27 @@ Istio 来通过专门的 Egress 网关服务引导出口流量。
|
|||
|
||||
* 遵照[安装指南](/zh/docs/setup/)中的指令,安装 Istio。
|
||||
|
||||
* 启动 [sleep]({{< github_tree >}}/samples/sleep) 样本应用,作为外部请求的测试源。
|
||||
* 启动 [curl]({{< github_tree >}}/samples/curl) 样本应用,作为外部请求的测试源。
|
||||
|
||||
若已开启[自动 Sidecar 注入](/zh/docs/setup/additional-setup/sidecar-injection/#automatic-sidecar-injection),执行
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl apply -f @samples/sleep/sleep.yaml@
|
||||
$ kubectl apply -f @samples/curl/curl.yaml@
|
||||
{{< /text >}}
|
||||
|
||||
否则,必须在部署 `sleep` 应用之前手动注入 Sidecar:
|
||||
否则,必须在部署 `curl` 应用之前手动注入 Sidecar:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl apply -f <(istioctl kube-inject -f @samples/sleep/sleep.yaml@)
|
||||
$ kubectl apply -f <(istioctl kube-inject -f @samples/curl/curl.yaml@)
|
||||
{{< /text >}}
|
||||
|
||||
注意每一个可以执行 `exec` 和 `curl` 操作的 Pod,都需要注入。
|
||||
|
||||
* 创建一个 shell 变量,来保存向外部服务发送请求的源 Pod 的名称。
|
||||
若使用 [sleep]({{< github_tree >}}/samples/sleep) 样例,运行:
|
||||
若使用 [curl]({{< github_tree >}}/samples/curl) 样例,运行:
|
||||
|
||||
{{< text bash >}}
|
||||
$ export SOURCE_POD=$(kubectl get pod -l app=sleep -o jsonpath={.items..metadata.name})
|
||||
$ export SOURCE_POD=$(kubectl get pod -l app=curl -o jsonpath={.items..metadata.name})
|
||||
{{< /text >}}
|
||||
|
||||
* 对于 macOS 用户,确认您使用的是 `openssl` 版本 1.1 或更高版本:
|
||||
|
@ -99,7 +99,7 @@ Sidecar 完成。
|
|||
验证 `ServiceEntry` 已被正确应用。
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl exec -it $SOURCE_POD -c sleep -- curl -sL -o /dev/null -D - http://edition.cnn.com/politics
|
||||
$ kubectl exec -it $SOURCE_POD -c curl -- curl -sL -o /dev/null -D - http://edition.cnn.com/politics
|
||||
HTTP/1.1 301 Moved Permanently
|
||||
...
|
||||
location: https://edition.cnn.com/politics
|
||||
|
@ -314,7 +314,7 @@ EOF
|
|||
6) 发送一个 HTTP 请求至 [http://edition.cnn.com/politics](https://edition.cnn.com/politics)。
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl exec -it $SOURCE_POD -c sleep -- curl -sL -o /dev/null -D - http://edition.cnn.com/politics
|
||||
$ kubectl exec -it $SOURCE_POD -c curl -- curl -sL -o /dev/null -D - http://edition.cnn.com/politics
|
||||
HTTP/1.1 200 OK
|
||||
...
|
||||
{{< /text >}}
|
||||
|
@ -981,7 +981,7 @@ kubernetes://client-credential-cacert Cert Chain ACTIVE true
|
|||
6) 发送一个 HTTP 请求到 `http://my-nginx.mesh-external.svc.cluster.local`:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl exec "$(kubectl get pod -l app=sleep -o jsonpath={.items..metadata.name})" -c sleep -- curl -sS http://my-nginx.mesh-external.svc.cluster.local
|
||||
$ kubectl exec "$(kubectl get pod -l app=curl -o jsonpath={.items..metadata.name})" -c curl -- curl -sS http://my-nginx.mesh-external.svc.cluster.local
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
|
@ -1088,8 +1088,8 @@ $ kubectl delete referencegrant my-nginx-reference-grant -n mesh-external
|
|||
|
||||
## 清除 {#cleanup}
|
||||
|
||||
删除 `sleep` 的 Service 和 Deployment:
|
||||
删除 `curl` 的 Service 和 Deployment:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl delete -f @samples/sleep/sleep.yaml@
|
||||
$ kubectl delete -f @samples/curl/curl.yaml@
|
||||
{{< /text >}}
|
||||
|
|
|
@ -43,10 +43,10 @@ Egress 网关节点,用它引导所有的出站流量,可以使应用节点
|
|||
则会启用 Egress 网关和访问日志。
|
||||
{{< /tip >}}
|
||||
|
||||
* 部署 [sleep]({{< github_tree >}}/samples/sleep) 示例应用,用作发送请求的测试源。
|
||||
* 部署 [curl]({{< github_tree >}}/samples/curl) 示例应用,用作发送请求的测试源。
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl apply -f @samples/sleep/sleep.yaml@
|
||||
$ kubectl apply -f @samples/curl/curl.yaml@
|
||||
{{< /text >}}
|
||||
|
||||
{{< tip >}}
|
||||
|
@ -56,7 +56,7 @@ Egress 网关节点,用它引导所有的出站流量,可以使应用节点
|
|||
* 将 `SOURCE_POD` 环境变量设置为源 Pod 的名称:
|
||||
|
||||
{{< text bash >}}
|
||||
$ export SOURCE_POD=$(kubectl get pod -l app=sleep -o jsonpath={.items..metadata.name})
|
||||
$ export SOURCE_POD=$(kubectl get pod -l app=curl -o jsonpath={.items..metadata.name})
|
||||
{{< /text >}}
|
||||
|
||||
{{< warning >}}
|
||||
|
@ -145,7 +145,7 @@ Egress 网关节点,用它引导所有的出站流量,可以使应用节点
|
|||
验证 `ServiceEntry` 是否已正确应用。
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl exec "$SOURCE_POD" -c sleep -- curl -sSL -o /dev/null -D - http://edition.cnn.com/politics
|
||||
$ kubectl exec "$SOURCE_POD" -c curl -- curl -sSL -o /dev/null -D - http://edition.cnn.com/politics
|
||||
...
|
||||
HTTP/1.1 301 Moved Permanently
|
||||
...
|
||||
|
@ -316,7 +316,7 @@ EOF
|
|||
5) 重新发送 HTTP 请求到 [http://edition.cnn.com/politics](https://edition.cnn.com/politics)。
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl exec "$SOURCE_POD" -c sleep -- curl -sSL -o /dev/null -D - http://edition.cnn.com/politics
|
||||
$ kubectl exec "$SOURCE_POD" -c curl -- curl -sSL -o /dev/null -D - http://edition.cnn.com/politics
|
||||
...
|
||||
HTTP/1.1 301 Moved Permanently
|
||||
...
|
||||
|
@ -453,7 +453,7 @@ $ kubectl delete httproute forward-cnn-from-egress-gateway
|
|||
验证您的 `ServiceEntry` 是否已正确生效。
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl exec "$SOURCE_POD" -c sleep -- curl -sSL -o /dev/null -D - https://edition.cnn.com/politics
|
||||
$ kubectl exec "$SOURCE_POD" -c curl -- curl -sSL -o /dev/null -D - https://edition.cnn.com/politics
|
||||
...
|
||||
HTTP/2 200
|
||||
Content-Type: text/html; charset=utf-8
|
||||
|
@ -603,7 +603,7 @@ EOF
|
|||
输出结果应该和之前一样。
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl exec "$SOURCE_POD" -c sleep -- curl -sSL -o /dev/null -D - https://edition.cnn.com/politics
|
||||
$ kubectl exec "$SOURCE_POD" -c curl -- curl -sSL -o /dev/null -D - https://edition.cnn.com/politics
|
||||
...
|
||||
HTTP/2 200
|
||||
Content-Type: text/html; charset=utf-8
|
||||
|
@ -698,7 +698,7 @@ Egress 网关发起的出站流量([下一节](#apply-Kubernetes-network-polic
|
|||
|
||||
本节中展示了如何创建 [Kubernetes 网络策略](https://kubernetes.io/zh-cn/docs/concepts/services-networking/network-policies/)来阻止绕过
|
||||
Egress 网关的出站流量。为了测试网络策略,首先创建一个 `test-egress` 命名空间,
|
||||
并在其中部署 [sleep]({{< github_tree >}}/samples/sleep) 示例应用,
|
||||
并在其中部署 [curl]({{< github_tree >}}/samples/curl) 示例应用,
|
||||
然后尝试发送一个会通过安全网关的外部服务请求。
|
||||
|
||||
1. 参考[用 Egress Gateway 发起 HTTPS 请求](#egress-gateway-for-http-traffic)一节中的步骤。
|
||||
|
@ -709,25 +709,25 @@ Egress 网关的出站流量。为了测试网络策略,首先创建一个 `te
|
|||
$ kubectl create namespace test-egress
|
||||
{{< /text >}}
|
||||
|
||||
1. 将 [sleep]({{< github_tree >}}/samples/sleep) 样例部署到 `test-egress` 命名空间。
|
||||
1. 将 [curl]({{< github_tree >}}/samples/curl) 样例部署到 `test-egress` 命名空间。
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl apply -n test-egress -f @samples/sleep/sleep.yaml@
|
||||
$ kubectl apply -n test-egress -f @samples/curl/curl.yaml@
|
||||
{{< /text >}}
|
||||
|
||||
1. 检查生成的 Pod,其中应该只有一个容器,也就是说没有注入 Istio Sidecar:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl get pod "$(kubectl get pod -n test-egress -l app=sleep -o jsonpath={.items..metadata.name})" -n test-egress
|
||||
$ kubectl get pod "$(kubectl get pod -n test-egress -l app=curl -o jsonpath={.items..metadata.name})" -n test-egress
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
sleep-776b7bcdcd-z7mc4 1/1 Running 0 18m
|
||||
curl-776b7bcdcd-z7mc4 1/1 Running 0 18m
|
||||
{{< /text >}}
|
||||
|
||||
1. 从 `test-egress` 命名空间的 `sleep` Pod 中向 [https://edition.cnn.com/politics](https://edition.cnn.com/politics)
|
||||
1. 从 `test-egress` 命名空间的 `curl` Pod 中向 [https://edition.cnn.com/politics](https://edition.cnn.com/politics)
|
||||
发送 HTTPS 请求。因为没有任何限制,所以这一请求应该会成功:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl exec "$(kubectl get pod -n test-egress -l app=sleep -o jsonpath={.items..metadata.name})" -n test-egress -c sleep -- curl -s -o /dev/null -w "%{http_code}\n" https://edition.cnn.com/politics
|
||||
$ kubectl exec "$(kubectl get pod -n test-egress -l app=curl -o jsonpath={.items..metadata.name})" -n test-egress -c curl -- curl -s -o /dev/null -w "%{http_code}\n" https://edition.cnn.com/politics
|
||||
200
|
||||
{{< /text >}}
|
||||
|
||||
|
@ -836,12 +836,12 @@ EOF
|
|||
{{< /tabset >}}
|
||||
|
||||
9) 重新发送前面的 HTTPS 请求到 [https://edition.cnn.com/politics](https://edition.cnn.com/politics)。
|
||||
这次请求就不会成功了,这是因为流量被网络策略拦截了。`sleep` Pod 无法绕过 `istio-egressgateway`。
|
||||
这次请求就不会成功了,这是因为流量被网络策略拦截了。`curl` Pod 无法绕过 `istio-egressgateway`。
|
||||
要访问 `edition.cnn.com`,只能通过 Istio Sidecar 代理,让流量经过 `istio-egressgateway`
|
||||
才能完成。这种配置表明,即使一些恶意的 Pod 绕过了 Sidecar,也会被网络策略拦截,而无法访问到外部站点。
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl exec "$(kubectl get pod -n test-egress -l app=sleep -o jsonpath={.items..metadata.name})" -n test-egress -c sleep -- curl -v -sS https://edition.cnn.com/politics
|
||||
$ kubectl exec "$(kubectl get pod -n test-egress -l app=curl -o jsonpath={.items..metadata.name})" -n test-egress -c curl -- curl -v -sS https://edition.cnn.com/politics
|
||||
Hostname was NOT found in DNS cache
|
||||
Trying 151.101.65.67...
|
||||
Trying 2a04:4e42:200::323...
|
||||
|
@ -855,18 +855,18 @@ EOF
|
|||
connect to 151.101.65.67 port 443 failed: Connection timed out
|
||||
{{< /text >}}
|
||||
|
||||
10) 接下来在 `test-egress` 命名空间的 `sleep` Pod 上注入 Sidecar,启用
|
||||
10) 接下来在 `test-egress` 命名空间的 `curl` Pod 上注入 Sidecar,启用
|
||||
`test-egress` 命名空间的自动注入:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl label namespace test-egress istio-injection=enabled
|
||||
{{< /text >}}
|
||||
|
||||
11) 重新部署 `sleep`:
|
||||
11) 重新部署 `curl`:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl delete deployment sleep -n test-egress
|
||||
$ kubectl apply -f @samples/sleep/sleep.yaml@ -n test-egress
|
||||
$ kubectl delete deployment curl -n test-egress
|
||||
$ kubectl apply -f @samples/curl/curl.yaml@ -n test-egress
|
||||
{{< /text >}}
|
||||
|
||||
12) 检查生成的 Pod,其中应该有了两个容器,其中包含了注入的 sidecar(`istio-proxy`):
|
||||
|
@ -876,11 +876,11 @@ EOF
|
|||
{{< tab name="Istio APIs" category-value="istio-apis" >}}
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl get pod "$(kubectl get pod -n test-egress -l app=sleep -o jsonpath={.items..metadata.name})" -n test-egress -o jsonpath='{.spec.containers[*].name}'
|
||||
sleep istio-proxy
|
||||
$ kubectl get pod "$(kubectl get pod -n test-egress -l app=curl -o jsonpath={.items..metadata.name})" -n test-egress -o jsonpath='{.spec.containers[*].name}'
|
||||
curl istio-proxy
|
||||
{{< /text >}}
|
||||
|
||||
在 `default` 命名空间中创建一个与 `sleep` Pod 类似的目标规则,用来引导
|
||||
在 `default` 命名空间中创建一个与 `curl` Pod 类似的目标规则,用来引导
|
||||
`test-egress` 命名空间内的流量经过 Egress 网关:
|
||||
|
||||
{{< text bash >}}
|
||||
|
@ -901,8 +901,8 @@ EOF
|
|||
{{< tab name="Gateway API" category-value="gateway-api" >}}
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl get pod "$(kubectl get pod -n test-egress -l app=sleep -o jsonpath={.items..metadata.name})" -n test-egress -o jsonpath='{.spec.containers[*].name}'
|
||||
sleep istio-proxy
|
||||
$ kubectl get pod "$(kubectl get pod -n test-egress -l app=curl -o jsonpath={.items..metadata.name})" -n test-egress -o jsonpath='{.spec.containers[*].name}'
|
||||
curl istio-proxy
|
||||
{{< /text >}}
|
||||
|
||||
{{< /tab >}}
|
||||
|
@ -914,7 +914,7 @@ sleep istio-proxy
|
|||
Gateway 最终把流量转发到 `edition.cnn.com`。
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl exec "$(kubectl get pod -n test-egress -l app=sleep -o jsonpath={.items..metadata.name})" -n test-egress -c sleep -- curl -sS -o /dev/null -w "%{http_code}\n" https://edition.cnn.com/politics
|
||||
$ kubectl exec "$(kubectl get pod -n test-egress -l app=curl -o jsonpath={.items..metadata.name})" -n test-egress -c curl -- curl -sS -o /dev/null -w "%{http_code}\n" https://edition.cnn.com/politics
|
||||
200
|
||||
{{< /text >}}
|
||||
|
||||
|
@ -965,7 +965,7 @@ $ kubectl logs -l gateway.networking.k8s.io/gateway-name=cnn-egress-gateway -c i
|
|||
{{< tab name="Istio APIs" category-value="istio-apis" >}}
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl delete -f @samples/sleep/sleep.yaml@ -n test-egress
|
||||
$ kubectl delete -f @samples/curl/curl.yaml@ -n test-egress
|
||||
$ kubectl delete destinationrule egressgateway-for-cnn -n test-egress
|
||||
$ kubectl delete networkpolicy allow-egress-to-istio-system-and-kube-dns -n test-egress
|
||||
$ kubectl label namespace kube-system kube-system-
|
||||
|
@ -978,7 +978,7 @@ $ kubectl delete namespace test-egress
|
|||
{{< tab name="Gateway API" category-value="gateway-api" >}}
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl delete -f @samples/sleep/sleep.yaml@ -n test-egress
|
||||
$ kubectl delete -f @samples/curl/curl.yaml@ -n test-egress
|
||||
$ kubectl delete networkpolicy allow-egress-to-istio-system-and-kube-dns -n test-egress
|
||||
$ kubectl label namespace kube-system kube-system-
|
||||
$ kubectl label namespace istio-system istio-
|
||||
|
@ -994,8 +994,8 @@ $ kubectl delete namespace test-egress
|
|||
|
||||
## 清理 {#cleanup}
|
||||
|
||||
关闭 [sleep]({{< github_tree >}}/samples/sleep) 服务:
|
||||
关闭 [curl]({{< github_tree >}}/samples/curl) 服务:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl delete -f @samples/sleep/sleep.yaml@
|
||||
$ kubectl delete -f @samples/curl/curl.yaml@
|
||||
{{< /text >}}
|
||||
|
|
|
@ -36,16 +36,16 @@ Kubernetes [ExternalName](https://kubernetes.io/zh-cn/docs/concepts/services-net
|
|||
$ kubectl create namespace without-istio
|
||||
{{< /text >}}
|
||||
|
||||
* 在命名空间 `without-istio` 中启动 [sleep]({{< github_tree >}}/samples/sleep) 示例。
|
||||
* 在命名空间 `without-istio` 中启动 [curl]({{< github_tree >}}/samples/curl) 示例。
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl apply -f @samples/sleep/sleep.yaml@ -n without-istio
|
||||
$ kubectl apply -f @samples/curl/curl.yaml@ -n without-istio
|
||||
{{< /text >}}
|
||||
|
||||
* 要发送请求,可以创建环境变量 `SOURCE_POD_WITHOUT_ISTIO` 来保存源 Pod 的名称:
|
||||
|
||||
{{< text bash >}}
|
||||
$ export SOURCE_POD_WITHOUT_ISTIO="$(kubectl get pod -n without-istio -l app=sleep -o jsonpath={.items..metadata.name})"
|
||||
$ export SOURCE_POD_WITHOUT_ISTIO="$(kubectl get pod -n without-istio -l app=curl -o jsonpath={.items..metadata.name})"
|
||||
{{< /text >}}
|
||||
|
||||
* 验证是否未注入 Istio Sidecar,即 Pod 中有一个容器:
|
||||
|
@ -53,7 +53,7 @@ Kubernetes [ExternalName](https://kubernetes.io/zh-cn/docs/concepts/services-net
|
|||
{{< text bash >}}
|
||||
$ kubectl get pod "$SOURCE_POD_WITHOUT_ISTIO" -n without-istio
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
sleep-66c8d79ff5-8tqrl 1/1 Running 0 32s
|
||||
curl-66c8d79ff5-8tqrl 1/1 Running 0 32s
|
||||
{{< /text >}}
|
||||
|
||||
## Kubernetes ExternalName 服务访问外部服务{#ks-external-name-service-to-access-an-external-service}
|
||||
|
@ -89,7 +89,7 @@ Kubernetes [ExternalName](https://kubernetes.io/zh-cn/docs/concepts/services-net
|
|||
[Kubernetes DNS 格式用于服务](https://v1-13.docs.kubernetes.io/docs/concepts/services-networking/dns-pod-service/#a-records):`<service name>.<namespace>.svc.cluster.local`。
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl exec "$SOURCE_POD_WITHOUT_ISTIO" -n without-istio -c sleep -- curl -sS my-httpbin.default.svc.cluster.local/headers
|
||||
$ kubectl exec "$SOURCE_POD_WITHOUT_ISTIO" -n without-istio -c curl -- curl -sS my-httpbin.default.svc.cluster.local/headers
|
||||
{
|
||||
"headers": {
|
||||
"Accept": "*/*",
|
||||
|
@ -122,7 +122,7 @@ Kubernetes [ExternalName](https://kubernetes.io/zh-cn/docs/concepts/services-net
|
|||
另请注意 `Host` header 等于您的服务的主机名。
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl exec "$SOURCE_POD" -c sleep -- curl -sS my-httpbin.default.svc.cluster.local/headers
|
||||
$ kubectl exec "$SOURCE_POD" -c curl -- curl -sS my-httpbin.default.svc.cluster.local/headers
|
||||
{
|
||||
"headers": {
|
||||
"Accept": "*/*",
|
||||
|
@ -133,7 +133,7 @@ Kubernetes [ExternalName](https://kubernetes.io/zh-cn/docs/concepts/services-net
|
|||
"X-B3-Spanid": "5795fab599dca0b8",
|
||||
"X-B3-Traceid": "5079ad3a4af418915795fab599dca0b8",
|
||||
"X-Envoy-Peer-Metadata": "...",
|
||||
"X-Envoy-Peer-Metadata-Id": "sidecar~10.28.1.74~sleep-6bdb595bcb-drr45.default~default.svc.cluster.local"
|
||||
"X-Envoy-Peer-Metadata-Id": "sidecar~10.28.1.74~curl-6bdb595bcb-drr45.default~default.svc.cluster.local"
|
||||
}
|
||||
}
|
||||
{{< /text >}}
|
||||
|
@ -194,7 +194,7 @@ $ kubectl delete service my-httpbin
|
|||
使用 `curl` 的 `--resolve` 选项通过集群 IP 访问 `wikipedia.org`:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl exec "$SOURCE_POD_WITHOUT_ISTIO" -n without-istio -c sleep -- curl -sS --resolve en.wikipedia.org:443:"$(kubectl get service my-wikipedia -o jsonpath='{.spec.clusterIP}')" https://en.wikipedia.org/wiki/Main_Page | grep -o "<title>.*</title>"
|
||||
$ kubectl exec "$SOURCE_POD_WITHOUT_ISTIO" -n without-istio -c curl -- curl -sS --resolve en.wikipedia.org:443:"$(kubectl get service my-wikipedia -o jsonpath='{.spec.clusterIP}')" https://en.wikipedia.org/wiki/Main_Page | grep -o "<title>.*</title>"
|
||||
<title>Wikipedia, the free encyclopedia</title>
|
||||
{{< /text >}}
|
||||
|
||||
|
@ -218,7 +218,7 @@ $ kubectl delete service my-httpbin
|
|||
1. 使用 Istio Sidecar 从源 Pod 中通过 Kubernetes 服务的集群 IP 访问 `wikipedia.org`:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl exec "$SOURCE_POD" -c sleep -- curl -sS --resolve en.wikipedia.org:443:"$(kubectl get service my-wikipedia -o jsonpath='{.spec.clusterIP}')" https://en.wikipedia.org/wiki/Main_Page | grep -o "<title>.*</title>"
|
||||
$ kubectl exec "$SOURCE_POD" -c curl -- curl -sS --resolve en.wikipedia.org:443:"$(kubectl get service my-wikipedia -o jsonpath='{.spec.clusterIP}')" https://en.wikipedia.org/wiki/Main_Page | grep -o "<title>.*</title>"
|
||||
<title>Wikipedia, the free encyclopedia</title>
|
||||
{{< /text >}}
|
||||
|
||||
|
@ -226,7 +226,7 @@ $ kubectl delete service my-httpbin
|
|||
`Connected to en.wikipedia.org (172.21.156.230)`,其中提到了在您的服务输出中作为集群 IP 打印的 IP。
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl exec "$SOURCE_POD" -c sleep -- curl -sS -v --resolve en.wikipedia.org:443:"$(kubectl get service my-wikipedia -o jsonpath='{.spec.clusterIP}')" https://en.wikipedia.org/wiki/Main_Page -o /dev/null
|
||||
$ kubectl exec "$SOURCE_POD" -c curl -- curl -sS -v --resolve en.wikipedia.org:443:"$(kubectl get service my-wikipedia -o jsonpath='{.spec.clusterIP}')" https://en.wikipedia.org/wiki/Main_Page -o /dev/null
|
||||
* Added en.wikipedia.org:443:172.21.156.230 to DNS cache
|
||||
* Hostname en.wikipedia.org was found in DNS cache
|
||||
* Trying 172.21.156.230...
|
||||
|
@ -245,16 +245,16 @@ $ kubectl delete service my-wikipedia
|
|||
|
||||
## 清理{#cleanup}
|
||||
|
||||
1. 停止服务 [sleep]({{< github_tree >}}/samples/sleep):
|
||||
1. 停止服务 [curl]({{< github_tree >}}/samples/curl):
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl delete -f @samples/sleep/sleep.yaml@
|
||||
$ kubectl delete -f @samples/curl/curl.yaml@
|
||||
{{< /text >}}
|
||||
|
||||
1. 停止命名空间 `without-istio` 中的服务 [sleep]({{< github_tree >}}/samples/sleep):
|
||||
1. 停止命名空间 `without-istio` 中的服务 [curl]({{< github_tree >}}/samples/curl):
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl delete -f @samples/sleep/sleep.yaml@ -n without-istio
|
||||
$ kubectl delete -f @samples/curl/curl.yaml@ -n without-istio
|
||||
{{< /text >}}
|
||||
|
||||
1. 删除命名空间 `without-istio`:
|
||||
|
|
|
@ -30,28 +30,28 @@ test: yes
|
|||
|
||||
* 根据[安装指南](/zh/docs/setup/)中的说明部署 Istio。
|
||||
|
||||
* 启动 [sleep]({{< github_tree >}}/samples/sleep) 示例应用,该应用将用作外部调用的测试源。
|
||||
* 启动 [curl]({{< github_tree >}}/samples/curl) 示例应用,该应用将用作外部调用的测试源。
|
||||
|
||||
如果启用了 [Sidecar 的自动注入功能](/zh/docs/setup/additional-setup/sidecar-injection/#automatic-sidecar-injection),
|
||||
运行以下命令部署 `sleep` 应用:
|
||||
运行以下命令部署 `curl` 应用:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl apply -f @samples/sleep/sleep.yaml@
|
||||
$ kubectl apply -f @samples/curl/curl.yaml@
|
||||
{{< /text >}}
|
||||
|
||||
否则在部署 `sleep` 应用之前,您必须手动注入 Sidecar。
|
||||
否则在部署 `curl` 应用之前,您必须手动注入 Sidecar。
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl apply -f <(istioctl kube-inject -f @samples/sleep/sleep.yaml@)
|
||||
$ kubectl apply -f <(istioctl kube-inject -f @samples/curl/curl.yaml@)
|
||||
{{< /text >}}
|
||||
|
||||
请注意,实际上任何可以执行 `exec` 和 `curl` 的 Pod 都可以用来完成这一任务。
|
||||
|
||||
* 创建一个环境变量来保存用于将请求发送到外部服务 Pod 的名称。
|
||||
如果您使用的是 [sleep]({{< github_tree >}}/samples/sleep) 示例应用,请运行:
|
||||
如果您使用的是 [curl]({{< github_tree >}}/samples/curl) 示例应用,请运行:
|
||||
|
||||
{{< text bash >}}
|
||||
$ export SOURCE_POD=$(kubectl get pod -l app=sleep -o jsonpath={.items..metadata.name})
|
||||
$ export SOURCE_POD=$(kubectl get pod -l app=curl -o jsonpath={.items..metadata.name})
|
||||
{{< /text >}}
|
||||
|
||||
## 配置对外部服务的访问 {#configuring-access-to-an-external-service}
|
||||
|
@ -85,7 +85,7 @@ test: yes
|
|||
1. 向外部的 HTTP 服务发送请求:
|
||||
|
||||
{{< text syntax=bash snip_id=curl_simple >}}
|
||||
$ kubectl exec "${SOURCE_POD}" -c sleep -- curl -sSL -o /dev/null -D - http://edition.cnn.com/politics
|
||||
$ kubectl exec "${SOURCE_POD}" -c curl -- curl -sSL -o /dev/null -D - http://edition.cnn.com/politics
|
||||
HTTP/1.1 301 Moved Permanently
|
||||
...
|
||||
location: https://edition.cnn.com/politics
|
||||
|
@ -156,7 +156,7 @@ test: yes
|
|||
1. 如上一节一样,向 `http://edition.cnn.com/politics` 发送 HTTP 请求:
|
||||
|
||||
{{< text syntax=bash snip_id=curl_origination_http >}}
|
||||
$ kubectl exec "${SOURCE_POD}" -c sleep -- curl -sSL -o /dev/null -D - http://edition.cnn.com/politics
|
||||
$ kubectl exec "${SOURCE_POD}" -c curl -- curl -sSL -o /dev/null -D - http://edition.cnn.com/politics
|
||||
HTTP/1.1 200 OK
|
||||
...
|
||||
{{< /text >}}
|
||||
|
@ -173,7 +173,7 @@ test: yes
|
|||
1. 请注意,使用 HTTPS 访问外部服务的应用程序将继续像以前一样工作:
|
||||
|
||||
{{< text syntax=bash snip_id=curl_origination_https >}}
|
||||
$ kubectl exec "${SOURCE_POD}" -c sleep -- curl -sSL -o /dev/null -D - https://edition.cnn.com/politics
|
||||
$ kubectl exec "${SOURCE_POD}" -c curl -- curl -sSL -o /dev/null -D - https://edition.cnn.com/politics
|
||||
HTTP/2 200
|
||||
...
|
||||
{{< /text >}}
|
||||
|
@ -206,7 +206,7 @@ $ kubectl delete destinationrule edition-cnn-com
|
|||
|
||||
1. 生成客户端和服务器证书
|
||||
1. 部署支持双向 TLS 协议的外部服务
|
||||
1. 将客户端(sleep Pod)配置为使用在步骤 1 中创建的凭据
|
||||
1. 将客户端(curl Pod)配置为使用在步骤 1 中创建的凭据
|
||||
|
||||
完成上述前置操作后,您可以将外部流量配置为经由该 Sidecar,执行 TLS 发起。
|
||||
|
||||
|
@ -382,7 +382,7 @@ $ kubectl delete destinationrule edition-cnn-com
|
|||
EOF
|
||||
{{< /text >}}
|
||||
|
||||
### 配置客户端 —— sleep Pod {#configure-the-client-sleep-pod}
|
||||
### 配置客户端 —— curl Pod {#configure-the-client-curl-pod}
|
||||
|
||||
1. 创建 Kubernetes [Secret](https://kubernetes.io/zh-cn/docs/concepts/configuration/secret/)
|
||||
来保存客户端的证书:
|
||||
|
@ -396,11 +396,11 @@ $ kubectl delete destinationrule edition-cnn-com
|
|||
|
||||
{{< boilerplate crl-tip >}}
|
||||
|
||||
1. 创建必需的 `RBAC` 以确保在上述步骤中创建的密钥对客户端 Pod 是可访问的,在本例中是 `sleep`。
|
||||
1. 创建必需的 `RBAC` 以确保在上述步骤中创建的密钥对客户端 Pod 是可访问的,在本例中是 `curl`。
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl create role client-credential-role --resource=secret --verb=list
|
||||
$ kubectl create rolebinding client-credential-role-binding --role=client-credential-role --serviceaccount=default:sleep
|
||||
$ kubectl create rolebinding client-credential-role-binding --role=client-credential-role --serviceaccount=default:curl
|
||||
{{< /text >}}
|
||||
|
||||
### 为 Sidecar 上的出口流量配置双向 TLS 源 {#configure-mutual-tls-origination-for-egress-traffic-at-sidecar}
|
||||
|
@ -434,7 +434,7 @@ $ kubectl delete destinationrule edition-cnn-com
|
|||
spec:
|
||||
workloadSelector:
|
||||
matchLabels:
|
||||
app: sleep
|
||||
app: curl
|
||||
host: my-nginx.mesh-external.svc.cluster.local
|
||||
trafficPolicy:
|
||||
loadBalancer:
|
||||
|
@ -455,7 +455,7 @@ $ kubectl delete destinationrule edition-cnn-com
|
|||
1. 验证凭据是否已提供给 Sidecar 并且处于活跃状态:
|
||||
|
||||
{{< text bash >}}
|
||||
$ istioctl proxy-config secret deploy/sleep | grep client-credential
|
||||
$ istioctl proxy-config secret deploy/curl | grep client-credential
|
||||
kubernetes://client-credential Cert Chain ACTIVE true 1 2024-06-04T12:15:20Z 2023-06-05T12:15:20Z
|
||||
kubernetes://client-credential-cacert Cert Chain ACTIVE true 10792363984292733914 2024-06-04T12:15:19Z 2023-06-05T12:15:19Z
|
||||
{{< /text >}}
|
||||
|
@ -463,7 +463,7 @@ $ kubectl delete destinationrule edition-cnn-com
|
|||
1. 发送一个 HTTP 请求到 `http://my-nginx.mesh-external.svc.cluster.local`:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl exec "$(kubectl get pod -l app=sleep -o jsonpath={.items..metadata.name})" -c sleep -- curl -sS http://my-nginx.mesh-external.svc.cluster.local
|
||||
$ kubectl exec "$(kubectl get pod -l app=curl -o jsonpath={.items..metadata.name})" -c curl -- curl -sS http://my-nginx.mesh-external.svc.cluster.local
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
|
@ -471,10 +471,10 @@ $ kubectl delete destinationrule edition-cnn-com
|
|||
...
|
||||
{{< /text >}}
|
||||
|
||||
1. 检查 `sleep` Pod 的日志中是否有与我们的请求相对应的行:
|
||||
1. 检查 `curl` Pod 的日志中是否有与我们的请求相对应的行:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl logs -l app=sleep -c istio-proxy | grep 'my-nginx.mesh-external.svc.cluster.local'
|
||||
$ kubectl logs -l app=curl -c istio-proxy | grep 'my-nginx.mesh-external.svc.cluster.local'
|
||||
{{< /text >}}
|
||||
|
||||
您应看到一行类似以下的输出:
|
||||
|
@ -514,9 +514,9 @@ $ kubectl delete destinationrule edition-cnn-com
|
|||
|
||||
## 清理常用配置 {#cleanup-common-configuration}
|
||||
|
||||
删除 `sleep` Service 和 Deployment:
|
||||
删除 `curl` Service 和 Deployment:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl delete service sleep
|
||||
$ kubectl delete deployment sleep
|
||||
$ kubectl delete service curl
|
||||
$ kubectl delete deployment curl
|
||||
{{< /text >}}
|
||||
|
|
|
@ -93,11 +93,11 @@ test: yes
|
|||
EOF
|
||||
{{< /text >}}
|
||||
|
||||
1. 在 `external` 命名空间中部署 [sleep]({{< github_tree >}}/samples/sleep) 示例,以测试到代理的通信量,
|
||||
1. 在 `external` 命名空间中部署 [curl]({{< github_tree >}}/samples/curl) 示例,以测试到代理的通信量,
|
||||
而不进行 Istio 流量控制。
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl apply -n external -f @samples/sleep/sleep.yaml@
|
||||
$ kubectl apply -n external -f @samples/curl/curl.yaml@
|
||||
{{< /text >}}
|
||||
|
||||
1. 获取代理 Pod 的 IP 地址并定义 `PROXY_IP` 环境变量来存储它:
|
||||
|
@ -112,10 +112,10 @@ test: yes
|
|||
$ export PROXY_PORT=3128
|
||||
{{< /text >}}
|
||||
|
||||
1. 从 `external` 命名空间中的 sleep Pod 通过代理向外部服务发送请求:
|
||||
1. 从 `external` 命名空间中的 curl Pod 通过代理向外部服务发送请求:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl exec -it $(kubectl get pod -n external -l app=sleep -o jsonpath={.items..metadata.name}) -n external -- sh -c "HTTPS_PROXY=$PROXY_IP:$PROXY_PORT curl https://en.wikipedia.org/wiki/Main_Page" | grep -o "<title>.*</title>"
|
||||
$ kubectl exec -it $(kubectl get pod -n external -l app=curl -o jsonpath={.items..metadata.name}) -n external -- 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>
|
||||
{{< /text >}}
|
||||
|
||||
|
@ -158,10 +158,10 @@ test: yes
|
|||
EOF
|
||||
{{< /text >}}
|
||||
|
||||
1. 从 `external` 命名空间中的 sleep Pod 发送请求。因为 sleep Pod 有 Sidecar,可以让 Istio 控制其流量。
|
||||
1. 从 `external` 命名空间中的 curl Pod 发送请求。因为 curl Pod 有 Sidecar,可以让 Istio 控制其流量。
|
||||
|
||||
{{< text bash >}}
|
||||
$ 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>"
|
||||
$ kubectl exec -it $SOURCE_POD -c curl -- 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>
|
||||
{{< /text >}}
|
||||
|
||||
|
@ -191,16 +191,16 @@ test: yes
|
|||
|
||||
## 清理 {#cleanup}
|
||||
|
||||
1. 关闭 [sleep]({{< github_tree >}}/samples/sleep) 服务:
|
||||
1. 关闭 [curl]({{< github_tree >}}/samples/curl) 服务:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl delete -f @samples/sleep/sleep.yaml@
|
||||
$ kubectl delete -f @samples/curl/curl.yaml@
|
||||
{{< /text >}}
|
||||
|
||||
1. 关闭 `external` 命名空间中的 [sleep]({{< github_tree >}}/samples/sleep) 服务:
|
||||
1. 关闭 `external` 命名空间中的 [curl]({{< github_tree >}}/samples/curl) 服务:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl delete -f @samples/sleep/sleep.yaml@ -n external
|
||||
$ kubectl delete -f @samples/curl/curl.yaml@ -n external
|
||||
{{< /text >}}
|
||||
|
||||
1. 关闭 Squid 代理,删除 ConfigMap 和配置文件:
|
||||
|
|
|
@ -56,18 +56,18 @@ $ istioctl install --set profile=minimal -y \
|
|||
|
||||
{{< /tabset >}}
|
||||
|
||||
* 部署 [sleep]({{< github_tree >}}/samples/sleep) 示例应用程序,以用作发送请求的测试源。
|
||||
* 部署 [curl]({{< github_tree >}}/samples/curl) 示例应用程序,以用作发送请求的测试源。
|
||||
如果您开启了 [Sidecar 自动注入](/zh/docs/setup/additional-setup/sidecar-injection/#automatic-sidecar-injection),
|
||||
运行以下命令以部署示例应用程序:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl apply -f @samples/sleep/sleep.yaml@
|
||||
$ kubectl apply -f @samples/curl/curl.yaml@
|
||||
{{< /text >}}
|
||||
|
||||
否则,在使用以下命令部署 `sleep` 应用程序之前,手动注入 Sidecar:
|
||||
否则,在使用以下命令部署 `curl` 应用程序之前,手动注入 Sidecar:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl apply -f <(istioctl kube-inject -f @samples/sleep/sleep.yaml@)
|
||||
$ kubectl apply -f <(istioctl kube-inject -f @samples/curl/curl.yaml@)
|
||||
{{< /text >}}
|
||||
|
||||
{{< tip >}}
|
||||
|
@ -77,7 +77,7 @@ $ istioctl install --set profile=minimal -y \
|
|||
* 将 `SOURCE_POD` 环境变量设置为您的源 Pod 的名称:
|
||||
|
||||
{{< text bash >}}
|
||||
$ export SOURCE_POD=$(kubectl get pod -l app=sleep -o jsonpath={.items..metadata.name})
|
||||
$ export SOURCE_POD=$(kubectl get pod -l app=curl -o jsonpath={.items..metadata.name})
|
||||
{{< /text >}}
|
||||
|
||||
## 引导流量流向 Wildcard 主机 {#configure-direct-traffic-to-a-wildcard-host}
|
||||
|
@ -116,7 +116,7 @@ $ istioctl install --set profile=minimal -y \
|
|||
[https://en.wikipedia.org](https://en.wikipedia.org) and [https://de.wikipedia.org](https://de.wikipedia.org):
|
||||
|
||||
{{< text bash >}}
|
||||
$ 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>"'
|
||||
$ kubectl exec -it $SOURCE_POD -c curl -- 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>"'
|
||||
<title>Wikipedia, the free encyclopedia</title>
|
||||
<title>Wikipedia – Die freie Enzyklopädie</title>
|
||||
{{< /text >}}
|
||||
|
@ -302,7 +302,7 @@ EOF
|
|||
[https://en.wikipedia.org](https://en.wikipedia.org) 和 [https://de.wikipedia.org](https://de.wikipedia.org):
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl exec "$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>"'
|
||||
$ kubectl exec "$SOURCE_POD" -c curl -- 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>"'
|
||||
<title>Wikipedia, the free encyclopedia</title>
|
||||
<title>Wikipedia – Die freie Enzyklopädie</title>
|
||||
{{< /text >}}
|
||||
|
@ -380,10 +380,10 @@ Istio 网关只能将流量路由配置到预定义的主机、预定义的 IP
|
|||
|
||||
## 清理 {#cleanup}
|
||||
|
||||
* 关闭 [sleep]({{< github_tree >}}/samples/sleep) 服务:
|
||||
* 关闭 [curl]({{< github_tree >}}/samples/curl) 服务:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl delete -f @samples/sleep/sleep.yaml@
|
||||
$ kubectl delete -f @samples/curl/curl.yaml@
|
||||
{{< /text >}}
|
||||
|
||||
* 从您的集群中卸载 Istio:
|
||||
|
|
|
@ -202,12 +202,12 @@ EOF
|
|||
|
||||
现在已经部署和配置了 httpbin 服务器,启动两个客户端来测试网格内部和外部的端到端连接:
|
||||
|
||||
1. 在与 httpbin 服务相同的命名空间(test)中的内部客户端(sleep),已注入 Sidecar。
|
||||
1. 在 default 命名空间(即服务网格外部)中的外部客户端(sleep)。
|
||||
1. 在与 httpbin 服务相同的命名空间(test)中的内部客户端(curl),已注入 Sidecar。
|
||||
1. 在 default 命名空间(即服务网格外部)中的外部客户端(curl)。
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl apply -f samples/sleep/sleep.yaml
|
||||
$ kubectl -n test apply -f samples/sleep/sleep.yaml
|
||||
$ kubectl apply -f samples/curl/curl.yaml
|
||||
$ kubectl -n test apply -f samples/curl/curl.yaml
|
||||
{{< /text >}}
|
||||
|
||||
运行以下命令以验证一切都已启动并正在运行,并且配置正确。
|
||||
|
@ -215,21 +215,21 @@ $ kubectl -n test apply -f samples/sleep/sleep.yaml
|
|||
{{< text bash >}}
|
||||
$ kubectl get pods
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
sleep-557747455f-xx88g 1/1 Running 0 4m14s
|
||||
curl-557747455f-xx88g 1/1 Running 0 4m14s
|
||||
{{< /text >}}
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl get pods -n test
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
httpbin-5bbdbd6588-z9vbs 2/2 Running 0 8m44s
|
||||
sleep-557747455f-brzf6 2/2 Running 0 6m57s
|
||||
curl-557747455f-brzf6 2/2 Running 0 6m57s
|
||||
{{< /text >}}
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl get svc -n test
|
||||
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
|
||||
httpbin ClusterIP 10.100.78.113 <none> 8443/TCP,8080/TCP 10m
|
||||
sleep ClusterIP 10.110.35.153 <none> 80/TCP 8m49s
|
||||
curl ClusterIP 10.110.35.153 <none> 80/TCP 8m49s
|
||||
{{< /text >}}
|
||||
|
||||
在以下命令中,将 `httpbin-5bbdbd6588-z9vbs` 替换为 httpbin Pod 的名称。
|
||||
|
@ -246,8 +246,8 @@ file-root:/etc/istio/tls-ca-certs/ca.crt Cert Cha
|
|||
### 在 8080 端口上验证内部网格连通性 {#verify-internal-mesh-connectivity-on-port-8080}
|
||||
|
||||
{{< text bash >}}
|
||||
$ export INTERNAL_CLIENT=$(kubectl -n test get pod -l app=sleep -o jsonpath={.items..metadata.name})
|
||||
$ kubectl -n test exec "${INTERNAL_CLIENT}" -c sleep -- curl -IsS "http://httpbin:8080/status/200"
|
||||
$ export INTERNAL_CLIENT=$(kubectl -n test get pod -l app=curl -o jsonpath={.items..metadata.name})
|
||||
$ kubectl -n test exec "${INTERNAL_CLIENT}" -c curl -- curl -IsS "http://httpbin:8080/status/200"
|
||||
HTTP/1.1 200 OK
|
||||
server: envoy
|
||||
date: Mon, 24 Oct 2022 09:04:52 GMT
|
||||
|
@ -261,19 +261,19 @@ x-envoy-upstream-service-time: 5
|
|||
### 在 8443 端口上验证外部到内部网格的连通性 {#verify-external-to-internal-mesh-connectivity-on-port-8443}
|
||||
|
||||
要验证来自外部客户端的 mTLS 流量,首先将 CA 证书和客户端证书/密钥复制到在 default
|
||||
命名空间中运行的 sleep 客户端。
|
||||
命名空间中运行的 curl 客户端。
|
||||
|
||||
{{< text bash >}}
|
||||
$ export EXTERNAL_CLIENT=$(kubectl get pod -l app=sleep -o jsonpath={.items..metadata.name})
|
||||
$ export EXTERNAL_CLIENT=$(kubectl get pod -l app=curl -o jsonpath={.items..metadata.name})
|
||||
$ kubectl cp client.test.svc.cluster.local.key default/"${EXTERNAL_CLIENT}":/tmp/
|
||||
$ kubectl cp client.test.svc.cluster.local.crt default/"${EXTERNAL_CLIENT}":/tmp/
|
||||
$ kubectl cp example.com.crt default/"${EXTERNAL_CLIENT}":/tmp/ca.crt
|
||||
{{< /text >}}
|
||||
|
||||
现在证书可用于外部 sleep 客户端,您可以使用以下命令验证该客户端到内部 httpbin 服务的连通性。
|
||||
现在证书可用于外部 curl 客户端,您可以使用以下命令验证该客户端到内部 httpbin 服务的连通性。
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl exec "${EXTERNAL_CLIENT}" -c sleep -- curl -IsS --cacert /tmp/ca.crt --key /tmp/client.test.svc.cluster.local.key --cert /tmp/client.test.svc.cluster.local.crt -HHost:httpbin.test.svc.cluster.local "https://httpbin.test.svc.cluster.local:8443/status/200"
|
||||
$ kubectl exec "${EXTERNAL_CLIENT}" -c curl -- curl -IsS --cacert /tmp/ca.crt --key /tmp/client.test.svc.cluster.local.key --cert /tmp/client.test.svc.cluster.local.crt -HHost:httpbin.test.svc.cluster.local "https://httpbin.test.svc.cluster.local:8443/status/200"
|
||||
server: istio-envoy
|
||||
date: Mon, 24 Oct 2022 09:05:31 GMT
|
||||
content-type: text/html; charset=utf-8
|
||||
|
@ -287,7 +287,7 @@ x-envoy-decorator-operation: ingress-sidecar.test:9080/*
|
|||
除了通过入口端口 8443 验证外部 mTLS 连通性之外,验证端口 8080 不接受任何外部 mTLS 流量也很重要。
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl exec "${EXTERNAL_CLIENT}" -c sleep -- curl -IsS --cacert /tmp/ca.crt --key /tmp/client.test.svc.cluster.local.key --cert /tmp/client.test.svc.cluster.local.crt -HHost:httpbin.test.svc.cluster.local "http://httpbin.test.svc.cluster.local:8080/status/200"
|
||||
$ kubectl exec "${EXTERNAL_CLIENT}" -c curl -- curl -IsS --cacert /tmp/ca.crt --key /tmp/client.test.svc.cluster.local.key --cert /tmp/client.test.svc.cluster.local.crt -HHost:httpbin.test.svc.cluster.local "http://httpbin.test.svc.cluster.local:8080/status/200"
|
||||
curl: (56) Recv failure: Connection reset by peer
|
||||
command terminated with exit code 56
|
||||
{{< /text >}}
|
||||
|
@ -298,11 +298,11 @@ command terminated with exit code 56
|
|||
|
||||
{{< text bash >}}
|
||||
$ kubectl delete secret httpbin-mtls-termination httpbin-mtls-termination-cacert -n test
|
||||
$ kubectl delete service httpbin sleep -n test
|
||||
$ kubectl delete deployment httpbin sleep -n test
|
||||
$ kubectl delete service httpbin curl -n test
|
||||
$ kubectl delete deployment httpbin curl -n test
|
||||
$ kubectl delete namespace test
|
||||
$ kubectl delete service sleep
|
||||
$ kubectl delete deployment sleep
|
||||
$ kubectl delete service curl
|
||||
$ kubectl delete deployment curl
|
||||
{{< /text >}}
|
||||
|
||||
1. 删除证书和私钥:
|
||||
|
|
|
@ -126,13 +126,13 @@ $ kubectl apply --context="${CTX_R3_Z4}" -n sample \
|
|||
-f helloworld-region3.zone4.yaml
|
||||
{{< /text >}}
|
||||
|
||||
## 部署 `Sleep` {#deploy-sleep}
|
||||
## 部署 `curl` {#deploy-curl}
|
||||
|
||||
部署 `Sleep` 应用到 `region1` `zone1`:
|
||||
部署 `curl` 应用到 `region1` `zone1`:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl apply --context="${CTX_R1_Z1}" \
|
||||
-f @samples/sleep/sleep.yaml@ -n sample
|
||||
-f @samples/curl/curl.yaml@ -n sample
|
||||
{{< /text >}}
|
||||
|
||||
## 等待 `HelloWorld` Pod {#wait-for-helloworld-pods}
|
||||
|
|
|
@ -12,7 +12,7 @@ owner: istio/wg-networking-maintainers
|
|||
|
||||
在继续之前,请确保完成[开始之前](/zh/docs/tasks/traffic-management/locality-load-balancing/before-you-begin)这一节所包含的步骤。
|
||||
|
||||
在这个任务中,您将使用 `region1` `zone1` 中的 `Sleep` Pod 作为 `HelloWorld` 服务的请求源。
|
||||
在这个任务中,您将使用 `region1` `zone1` 中的 `curl` Pod 作为 `HelloWorld` 服务的请求源。
|
||||
您将使用以下分布在不同的地域配置Istio:
|
||||
|
||||
地区 | 区域 | 流量(%)
|
||||
|
@ -60,12 +60,12 @@ EOF
|
|||
|
||||
## 验证分布 {#verify-the-distribution}
|
||||
|
||||
从 `Sleep` Pod 调用 `HelloWorld` 服务:
|
||||
从 `curl` Pod 调用 `HelloWorld` 服务:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl exec --context="${CTX_R1_Z1}" -n sample -c sleep \
|
||||
$ kubectl exec --context="${CTX_R1_Z1}" -n sample -c curl \
|
||||
"$(kubectl get pod --context="${CTX_R1_Z1}" -n sample -l \
|
||||
app=sleep -o jsonpath='{.items[0].metadata.name}')" \
|
||||
app=curl -o jsonpath='{.items[0].metadata.name}')" \
|
||||
-- curl -sSL helloworld.sample:5000/hello
|
||||
{{< /text >}}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ owner: istio/wg-networking-maintainers
|
|||
|
||||
在开始之前,一定要完成[开始之前](/zh/docs/tasks/traffic-management/locality-load-balancing/before-you-begin)这一节包含的步骤。
|
||||
|
||||
在此任务中,您将使用 `Sleep` Pod 在 `region1.zone1` 作为请求源发送到 `HelloWorld` 服务。
|
||||
在此任务中,您将使用 `curl` Pod 在 `region1.zone1` 作为请求源发送到 `HelloWorld` 服务。
|
||||
然后,您将触发故障,这些故障将按照以下顺序导致不同地域之间的故障转移:
|
||||
|
||||
{{< image width="75%"
|
||||
|
@ -21,7 +21,7 @@ owner: istio/wg-networking-maintainers
|
|||
>}}
|
||||
|
||||
在内部,[Envoy 优先级](https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/upstream/load_balancing/priority.html)用于控制故障转移。
|
||||
这些优先级将按照以下方式分配来自 `Sleep` Pod(在 `region1` `zone1`)的流量:
|
||||
这些优先级将按照以下方式分配来自 `curl` Pod(在 `region1` `zone1`)的流量:
|
||||
|
||||
优先级 | 地域 | 细节
|
||||
-------- | -------- | -------
|
||||
|
@ -74,12 +74,12 @@ EOF
|
|||
|
||||
## 验证流量保持在 `region1.zone1` {#verify-traffic-stays-in-region1zone1}
|
||||
|
||||
从 `Sleep` Pod 调用 `HelloWorld` 服务:
|
||||
从 `curl` Pod 调用 `HelloWorld` 服务:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl exec --context="${CTX_R1_Z1}" -n sample -c sleep \
|
||||
$ kubectl exec --context="${CTX_R1_Z1}" -n sample -c curl \
|
||||
"$(kubectl get pod --context="${CTX_R1_Z1}" -n sample -l \
|
||||
app=sleep -o jsonpath='{.items[0].metadata.name}')" \
|
||||
app=curl -o jsonpath='{.items[0].metadata.name}')" \
|
||||
-- curl -sSL helloworld.sample:5000/hello
|
||||
Hello version: region1.zone1, instance: helloworld-region1.zone1-86f77cd7b-cpxhv
|
||||
{{< /text >}}
|
||||
|
@ -100,12 +100,12 @@ $ kubectl --context="${CTX_R1_Z1}" exec \
|
|||
-n sample -c istio-proxy -- curl -sSL -X POST 127.0.0.1:15000/drain_listeners
|
||||
{{< /text >}}
|
||||
|
||||
从 `Sleep` Pod 调用 `HelloWorld` 服务:
|
||||
从 `curl` Pod 调用 `HelloWorld` 服务:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl exec --context="${CTX_R1_Z1}" -n sample -c sleep \
|
||||
$ kubectl exec --context="${CTX_R1_Z1}" -n sample -c curl \
|
||||
"$(kubectl get pod --context="${CTX_R1_Z1}" -n sample -l \
|
||||
app=sleep -o jsonpath='{.items[0].metadata.name}')" \
|
||||
app=curl -o jsonpath='{.items[0].metadata.name}')" \
|
||||
-- curl -sSL helloworld.sample:5000/hello
|
||||
Hello version: region1.zone2, instance: helloworld-region1.zone2-86f77cd7b-cpxhv
|
||||
{{< /text >}}
|
||||
|
@ -123,12 +123,12 @@ $ kubectl --context="${CTX_R1_Z2}" exec \
|
|||
-n sample -c istio-proxy -- curl -sSL -X POST 127.0.0.1:15000/drain_listeners
|
||||
{{< /text >}}
|
||||
|
||||
从 `Sleep` Pod 调用 `HelloWorld` 服务:
|
||||
从 `curl` Pod 调用 `HelloWorld` 服务:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl exec --context="${CTX_R1_Z1}" -n sample -c sleep \
|
||||
$ kubectl exec --context="${CTX_R1_Z1}" -n sample -c curl \
|
||||
"$(kubectl get pod --context="${CTX_R1_Z1}" -n sample -l \
|
||||
app=sleep -o jsonpath='{.items[0].metadata.name}')" \
|
||||
app=curl -o jsonpath='{.items[0].metadata.name}')" \
|
||||
-- curl -sSL helloworld.sample:5000/hello
|
||||
Hello version: region2.zone3, instance: helloworld-region2.zone3-86f77cd7b-cpxhv
|
||||
{{< /text >}}
|
||||
|
@ -146,12 +146,12 @@ $ kubectl --context="${CTX_R2_Z3}" exec \
|
|||
-n sample -c istio-proxy -- curl -sSL -X POST 127.0.0.1:15000/drain_listeners
|
||||
{{< /text >}}
|
||||
|
||||
从 `Sleep` Pod 调用 `HelloWorld` 服务:
|
||||
从 `curl` Pod 调用 `HelloWorld` 服务:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl exec --context="${CTX_R1_Z1}" -n sample -c sleep \
|
||||
$ kubectl exec --context="${CTX_R1_Z1}" -n sample -c curl \
|
||||
"$(kubectl get pod --context="${CTX_R1_Z1}" -n sample -l \
|
||||
app=sleep -o jsonpath='{.items[0].metadata.name}')" \
|
||||
app=curl -o jsonpath='{.items[0].metadata.name}')" \
|
||||
-- curl -sSL helloworld.sample:5000/hello
|
||||
Hello version: region3.zone4, instance: helloworld-region3.zone4-86f77cd7b-cpxhv
|
||||
{{< /text >}}
|
||||
|
|
|
@ -101,28 +101,28 @@ test: yes
|
|||
EOF
|
||||
{{< /text >}}
|
||||
|
||||
1. 部署用于向 `httpbin` 服务发送请求的 `sleep` 工作负载:
|
||||
1. 部署用于向 `httpbin` 服务发送请求的 `curl` 工作负载:
|
||||
|
||||
{{< text bash >}}
|
||||
$ cat <<EOF | kubectl create -f -
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: sleep
|
||||
name: curl
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: sleep
|
||||
app: curl
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: sleep
|
||||
app: curl
|
||||
spec:
|
||||
containers:
|
||||
- name: sleep
|
||||
- name: curl
|
||||
image: curlimages/curl
|
||||
command: ["/bin/sleep","3650d"]
|
||||
command: ["/bin/curl","3650d"]
|
||||
imagePullPolicy: IfNotPresent
|
||||
EOF
|
||||
{{< /text >}}
|
||||
|
@ -224,7 +224,7 @@ test: yes
|
|||
1. 现在所有流量都指向 `httpbin:v1` 服务,并向此服务发送请求:
|
||||
|
||||
{{< text bash json >}}
|
||||
$ kubectl exec deploy/sleep -c sleep -- curl -sS http://httpbin:8000/headers
|
||||
$ kubectl exec deploy/curl -c curl -- curl -sS http://httpbin:8000/headers
|
||||
{
|
||||
"headers": {
|
||||
"Accept": "*/*",
|
||||
|
@ -338,7 +338,7 @@ test: yes
|
|||
1. 发送流量:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl exec deploy/sleep -c sleep -- curl -sS http://httpbin:8000/headers
|
||||
$ kubectl exec deploy/curl -c curl -- curl -sS http://httpbin:8000/headers
|
||||
{{< /text >}}
|
||||
|
||||
现在您应看到 `v1` 和 `v2` 版本中都有了访问日志。
|
||||
|
@ -381,9 +381,9 @@ test: yes
|
|||
|
||||
{{< /tabset >}}
|
||||
|
||||
1. 删除 `httpbin` 和 `sleep` Deployment 以及 `httpbin` 服务:
|
||||
1. 删除 `httpbin` 和 `curl` Deployment 以及 `httpbin` 服务:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl delete deploy httpbin-v1 httpbin-v2 sleep
|
||||
$ kubectl delete deploy httpbin-v1 httpbin-v2 curl
|
||||
$ kubectl delete svc httpbin
|
||||
{{< /text >}}
|
||||
|
|
|
@ -34,10 +34,10 @@ test: yes
|
|||
$ kubectl create namespace istio-io-tcp-traffic-shifting
|
||||
{{< /text >}}
|
||||
|
||||
1. 部署 [sleep]({{< github_tree >}}/samples/sleep) 示例应用程序,作为发送请求的测试源。
|
||||
1. 部署 [curl]({{< github_tree >}}/samples/curl) 示例应用程序,作为发送请求的测试源。
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl apply -f @samples/sleep/sleep.yaml@ -n istio-io-tcp-traffic-shifting
|
||||
$ kubectl apply -f @samples/curl/curl.yaml@ -n istio-io-tcp-traffic-shifting
|
||||
{{< /text >}}
|
||||
|
||||
1. 部署 `tcp-echo` 微服务的 `v1` 和 `v2` 版本。
|
||||
|
@ -98,9 +98,9 @@ $ export TCP_INGRESS_PORT=$(kubectl get gtw tcp-echo-gateway -n istio-io-tcp-tra
|
|||
3) 通过发送一些 TCP 流量来确认 `tcp-echo` 服务已启动且正在运行。
|
||||
|
||||
{{< text bash >}}
|
||||
$ export SLEEP=$(kubectl get pod -l app=sleep -n istio-io-tcp-traffic-shifting -o jsonpath={.items..metadata.name})
|
||||
$ export curl=$(kubectl get pod -l app=curl -n istio-io-tcp-traffic-shifting -o jsonpath={.items..metadata.name})
|
||||
$ for i in {1..20}; do \
|
||||
kubectl exec "$SLEEP" -c sleep -n istio-io-tcp-traffic-shifting -- sh -c "(date; sleep 1) | nc $INGRESS_HOST $TCP_INGRESS_PORT"; \
|
||||
kubectl exec "$curl" -c curl -n istio-io-tcp-traffic-shifting -- sh -c "(date; curl 1) | nc $INGRESS_HOST $TCP_INGRESS_PORT"; \
|
||||
done
|
||||
one Mon Nov 12 23:24:57 UTC 2022
|
||||
one Mon Nov 12 23:25:00 UTC 2022
|
||||
|
@ -208,9 +208,9 @@ spec:
|
|||
6) 发送更多 TCP 流量到 `tcp-echo` 微服务。
|
||||
|
||||
{{< text bash >}}
|
||||
$ export SLEEP=$(kubectl get pod -l app=sleep -n istio-io-tcp-traffic-shifting -o jsonpath={.items..metadata.name})
|
||||
$ export curl=$(kubectl get pod -l app=curl -n istio-io-tcp-traffic-shifting -o jsonpath={.items..metadata.name})
|
||||
$ for i in {1..20}; do \
|
||||
kubectl exec "$SLEEP" -c sleep -n istio-io-tcp-traffic-shifting -- sh -c "(date; sleep 1) | nc $INGRESS_HOST $TCP_INGRESS_PORT"; \
|
||||
kubectl exec "$curl" -c curl -n istio-io-tcp-traffic-shifting -- sh -c "(date; curl 1) | nc $INGRESS_HOST $TCP_INGRESS_PORT"; \
|
||||
done
|
||||
one Mon Nov 12 23:38:45 UTC 2022
|
||||
two Mon Nov 12 23:38:47 UTC 2022
|
||||
|
@ -263,10 +263,10 @@ $ kubectl delete -f @samples/tcp-echo/gateway-api/tcp-echo-all-v1.yaml@ -n istio
|
|||
|
||||
{{< /tabset >}}
|
||||
|
||||
2) 移除 `sleep` 样例、`tcp-echo` 应用和测试命名空间:
|
||||
2) 移除 `curl` 样例、`tcp-echo` 应用和测试命名空间:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl delete -f @samples/sleep/sleep.yaml@ -n istio-io-tcp-traffic-shifting
|
||||
$ kubectl delete -f @samples/curl/curl.yaml@ -n istio-io-tcp-traffic-shifting
|
||||
$ kubectl delete -f @samples/tcp-echo/tcp-echo-services.yaml@ -n istio-io-tcp-traffic-shifting
|
||||
$ kubectl delete namespace istio-io-tcp-traffic-shifting
|
||||
{{< /text >}}
|
||||
|
|
Loading…
Reference in New Issue