mirror of https://github.com/istio/istio.io.git
zh-translation:/docs/tasks/traffic-management/ingress/service-apis/index.md (#9334)
* zh-translation: /zh/docs/tasks/traffic-management/ingress/kubernetes-ingress/index.md * 优化内容,增加页内链接。 * 完善业内跳转id * 修复lint检查问题 * 修复lint问题。 * 解决lint提示spell错误问题。 * 修复 lint提示spelling errors * 翻译zh/docs/tasks/traffic-management/ ingress/secure-ingress/index.md * 修复页面链接问题 * 修复lint检查错误 * 1、修正首字母大写 2、修正首字母大写,补充翻译 * 翻译docs/tasks/traffic-management /ingress/service-apis/index.md * 修复评审问题 * 修复评审错误 * 之前的修改通不过lint检查。 * 修复不能过lint错误。 * 修复lint检查错误 * 修复lint检测问题。 * 修复review错误 * 修复lint错误,主要是大小写和port的翻译问题。 * 空行错误
This commit is contained in:
parent
7f60e07c32
commit
f0d8aa3415
|
@ -6,21 +6,21 @@ keywords: [traffic-management,ingress]
|
|||
owner: istio/wg-networking-maintainers
|
||||
test: yes
|
||||
---
|
||||
此任务描述如何使用[Ingress Resource](https://kubernetes.io/zh/docs/concepts/services-networking/ingress/)入口资源将Istio配置为在服务网格集群之外公开服务。
|
||||
此任务描述如何使用[Ingress Resource](https://kubernetes.io/zh/docs/concepts/services-networking/ingress/)入口资源将 Istio 配置为在服务网格集群之外公开服务。
|
||||
|
||||
{{< tip >}}
|
||||
建议使用[Istio Gateway](/zh/docs/tasks/traffic-management/ingress/ingress-control/)而不是Ingress来利用Istio提供的完整功能集,例如丰富的流量管理和安全功能。
|
||||
建议使用[Istio Gateway](/zh/docs/tasks/traffic-management/ingress/ingress-control/)而不是 Ingress 来利用 Istio 提供的完整功能集,例如丰富的流量管理和安全功能。
|
||||
{{< /tip >}}
|
||||
|
||||
## 准备工作{#before-you-begin}
|
||||
|
||||
请按照[Ingress网关任务](/zh/docs/tasks/traffic-management/ingress/ingress-control/)中的[准备工作](/zh/docs/tasks/traffic-management/ingress/ingress-control/#before-you-begin)、[确定Ingress IP和Ports](/zh/docs/tasks/traffic-management/ingress/ingress-control/#determining-the-ingress-ip-and-ports)的说明进行操作。
|
||||
请按照[Ingress 网关任务](/zh/docs/tasks/traffic-management/ingress/ingress-control/)中的[准备工作](/zh/docs/tasks/traffic-management/ingress/ingress-control/#before-you-begin)、[确定 Ingress IP 和端口](/zh/docs/tasks/traffic-management/ingress/ingress-control/#determining-the-ingress-ip-and-ports)的说明进行操作。
|
||||
|
||||
## 使用Ingress resource配置ingress{#configuring-ingress-using-an-ingress-resource}
|
||||
|
||||
[Kubernetes Ingress 资源](https://kubernetes.io/zh/docs/concepts/services-networking/ingress/)公开了从集群外到集群内服务的HTTP和HTTPS路由。
|
||||
[Kubernetes Ingress 资源](https://kubernetes.io/zh/docs/concepts/services-networking/ingress/)公开了从集群外到集群内服务的 HTTP 和 HTTPS 路由。
|
||||
|
||||
让我们看看如何在端口80上配置`Ingress`以实现HTTP流量。
|
||||
让我们看看如何在端口80上配置 `Ingress` 以实现 HTTP 流量。
|
||||
|
||||
1. 创建一个 `Ingress` 资源:
|
||||
|
||||
|
@ -44,7 +44,7 @@ test: yes
|
|||
EOF
|
||||
{{< /text >}}
|
||||
|
||||
需要使用 `kubernetes.io/ingress.class` 注解来告知Istio网关控制器它应该处理此 `Ingress` ,否则它将被忽略。
|
||||
需要使用 `kubernetes.io/ingress.class` 注解来告知 Istio 网关控制器它应该处理此 `Ingress` ,否则它将被忽略。
|
||||
|
||||
1. 使用 _curl_ 访问 _httpbin_ 服务:
|
||||
|
||||
|
@ -55,9 +55,9 @@ test: yes
|
|||
...
|
||||
{{< /text >}}
|
||||
|
||||
注意,您需要使用 `-H` 标志将 _Host_ 的 HTTP header设置为"httpbin.example.com",因为 `Ingress` 中已经配置为处理访问 "httpbin.example.com"的请求,但是在测试环境中,该host并没有相应的DNS绑定。
|
||||
注意,您需要使用 `-H` 标志将 _Host_ 的 HTTP header 设置为"httpbin.example.com",因为 `Ingress` 中已经配置为处理访问 "httpbin.example.com"的请求,但是在测试环境中,该 host 并没有相应的 DNS 绑定。
|
||||
|
||||
1. 访问未显式公开的其他URL时,将返回HTTP 404错误:
|
||||
1. 访问未显式公开的其他 URL 时,将返回 HTTP 404 错误:
|
||||
|
||||
{{< text bash >}}
|
||||
$ curl -s -I -HHost:httpbin.example.com "http://$INGRESS_HOST:$INGRESS_PORT/headers"
|
||||
|
@ -69,17 +69,17 @@ test: yes
|
|||
|
||||
### TLS {#TLS}
|
||||
|
||||
`Ingress` 支持[TLS](https://kubernetes.io/zh/docs/concepts/services-networking/ingress/#tls)设置。 Istio支持此功能,但是引用的 `Secret` 必须存在于`istio-ingressgateway` 部署的名称空间(通常是 `istio-system` )中。 [cert-manager](/zh/docs/ops/integrations/certmanager/)可用于生成这些证书。
|
||||
`Ingress` 支持[TLS](https://kubernetes.io/zh/docs/concepts/services-networking/ingress/#tls)设置。 Istio 支持此功能,但是引用的 `Secret` 必须存在于`istio-ingressgateway` 部署的名称空间(通常是 `istio-system` )中。 [cert-manager](/zh/docs/ops/integrations/certmanager/)可用于生成这些证书。
|
||||
|
||||
### 指定路径类型{#specifying-path-type}
|
||||
|
||||
Istio默认路径类型为精确匹配,除非路径以 `/*` 或 `.*` 结尾,在这种情况下,路径类型为前缀匹配。不支持其他正则表达式。
|
||||
Istio 默认路径类型为精确匹配,除非路径以 `/*` 或 `.*` 结尾,在这种情况下,路径类型为前缀匹配。不支持其他正则表达式。
|
||||
|
||||
在Kubernetes 1.18中,添加了一个新字段 `pathType` 。这允许将路径明确声明为`Exact` 或 `Prefix`。
|
||||
在 Kubernetes 1.18 中,添加了一个新字段 `pathType` 。这允许将路径明确声明为`Exact` 或 `Prefix`。
|
||||
|
||||
### 指定 `IngressClass` {#specifying-ingress-class}
|
||||
|
||||
在Kubernetes 1.18中,添加了新资源 `IngressClass` ,以替换Ingress资源上的`kubernetes.io/ingress.class`注解。如果使用此资源,则需要将 `controller` 字段设置为 `istio.io/ingress-controller`。例如:
|
||||
在 Kubernetes 1.18 中,添加了新资源 `IngressClass` ,以替换 Ingress 资源上的 `kubernetes.io/ingress.class` 注解。如果使用此资源,则需要将 `controller` 字段设置为 `istio.io/ingress-controller`。例如:
|
||||
|
||||
{{< text yaml >}}
|
||||
apiVersion: networking.k8s.io/v1beta1
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
title: Secure Gateways
|
||||
description: 通过TLS或mTLS将服务公开到服务网格之外。
|
||||
description: 通过 TLS 或 mTLS 将服务公开到服务网格之外。
|
||||
weight: 20
|
||||
aliases:
|
||||
- /zh/docs/tasks/traffic-management/ingress/secure-ingress-sds/
|
||||
|
@ -10,20 +10,20 @@ owner: istio/wg-networking-maintainers
|
|||
test: yes
|
||||
---
|
||||
|
||||
[Ingress流量控制任务](/zh/docs/tasks/traffic-management/ingress/ingress-control)描述了如何配置入口网关以向外部公开HTTP服务。此任务描述如何使用TLS或双向TLS公开安全的HTTPS服务。
|
||||
[Ingress 流量控制任务](/zh/docs/tasks/traffic-management/ingress/ingress-control)描述了如何配置入口网关以向外部公开 HTTP 服务。此任务描述如何使用 TLS 或 mTLS 公开安全的 HTTPS 服务。
|
||||
|
||||
## 准备工作{#before-you-begin}
|
||||
|
||||
1. 执行[准备工作](/zh/docs/tasks/traffic-management/ingress/ingress-control#before-you-begin)中的步骤。完成[Ingress流量控制](/zh/docs/tasks/traffic-management/ingress/ingress-control)中[确定Ingress的IP和Port](/zh/docs/tasks/traffic-management/ingress/ingress-control/#determining-the-ingress-ip-and-ports)部分任务。执行完这些步骤后,您应该已部署Istio和 [httpbin]({{< github_tree >}}/samples/httpbin)服务,并设置了环境变量 `INGRESS_HOST` 和 `SECURE_INGRESS_PORT` 。
|
||||
1. 执行[准备工作](/zh/docs/tasks/traffic-management/ingress/ingress-control#before-you-begin)中的步骤。完成[Ingress 流量控制](/zh/docs/tasks/traffic-management/ingress/ingress-control)中[确定 Ingress 的 IP 和端口](/zh/docs/tasks/traffic-management/ingress/ingress-control/#determining-the-ingress-ip-and-ports)部分任务。执行完这些步骤后,您应该已部署 Istio 和 [httpbin]({{< github_tree >}}/samples/httpbin)服务,并设置了环境变量 `INGRESS_HOST` 和 `SECURE_INGRESS_PORT` 。
|
||||
|
||||
1. 对于macOS用户,请验证您是否使用通过LibreSSL库编译的curl:
|
||||
1. 对于 macOS 用户,请验证您是否使用通过 LibreSSL 库编译的 curl:
|
||||
|
||||
{{< text bash >}}
|
||||
$ curl --version | grep LibreSSL
|
||||
curl 7.54.0 (x86_64-apple-darwin17.0) libcurl/7.54.0 LibreSSL/2.0.20 zlib/1.2.11 nghttp2/1.24.0
|
||||
{{< /text >}}
|
||||
|
||||
如果上述命令输出的是如图所示的LibreSSL版本,则curl命令应按照此任务中的说明正确运行。否则,请尝试使用curl的其他实现,例如在Linux机器上。
|
||||
如果上述命令输出的是如图所示的 LibreSSL 版本,则 curl 命令应按照此任务中的说明正确运行。否则,请尝试使用 curl 的其他实现,例如在 Linux 机器上。
|
||||
|
||||
## 生成客户端和服务器证书和密钥{#generate-client-and-server-certificates-and-keys}
|
||||
|
||||
|
@ -46,7 +46,7 @@ test: yes
|
|||
|
||||
1. 确定已在[准备工作](/zh/docs/tasks/traffic-management/ingress/ingress-control#before-you-begin)环节完成[httpbin]({{< github_tree >}}/samples/httpbin)服务的部署。
|
||||
|
||||
1. 为Ingress网关创建Secret:
|
||||
1. 为 Ingress Gateway 创建 Secret:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl create -n istio-system secret tls httpbin-credential --key=httpbin.example.com.key --cert=httpbin.example.com.crt
|
||||
|
@ -56,7 +56,7 @@ test: yes
|
|||
Secret 名字 **不能** 以 `istio` 或 `prometheus` 开头, 且不能包含 `token` 字段。
|
||||
{{< /warning >}}
|
||||
|
||||
1. 为端口443定义一个带有 `servers:` 部分的网关,并将 `credentialName` 的值指定为 `httpbin-credential`。这些值与secret名称相同。 TLS模式的值应为 `SIMPLE`。
|
||||
1. 为端口443定义一个带有 `servers:` 部分的网关,并将 `credentialName` 的值指定为 `httpbin-credential`。这些值与 Secret 名称相同。 TLS 模式的值应为 `SIMPLE`。
|
||||
|
||||
{{< text bash >}}
|
||||
$ cat <<EOF | kubectl apply -f -
|
||||
|
@ -107,7 +107,7 @@ test: yes
|
|||
EOF
|
||||
{{< /text >}}
|
||||
|
||||
1. 发送HTTPS请求访问 `httpbin` 服务:
|
||||
1. 发送 HTTPS 请求访问 `httpbin` 服务:
|
||||
|
||||
{{< text bash >}}
|
||||
$ curl -v -HHost:httpbin.example.com --resolve "httpbin.example.com:$SECURE_INGRESS_PORT:$INGRESS_HOST" \
|
||||
|
@ -117,7 +117,7 @@ test: yes
|
|||
The `httpbin` service will return the
|
||||
[418 I'm a Teapot](https://tools.ietf.org/html/rfc7168#section-2.3.3) code.
|
||||
|
||||
1. 删除网关的secret,并创建一个新的secret来修改入口网关的凭据。
|
||||
1. 删除网关的 secret,并创建一个新的 secret 来修改入口网关的凭据。
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl -n istio-system delete secret httpbin-credential
|
||||
|
@ -165,11 +165,11 @@ test: yes
|
|||
* curl: (35) error:04FFF06A:rsa routines:CRYPTO_internal:block type is not 01
|
||||
{{< /text >}}
|
||||
|
||||
### 为多个主机配置TLS入口网关 {#configure-a-TLS-ingress-gateway-for-multiple-hosts}
|
||||
### 为多个主机配置 TLS 入口网关 {#configure-a-TLS-ingress-gateway-for-multiple-hosts}
|
||||
|
||||
您可以为多个主机(例如 `httpbin.example.com` 和 `helloworld-v1.example.com` )配置入口网关。入口网关检索与特定凭据名称相对应的唯一凭据。
|
||||
|
||||
1. 要恢复httpbin的凭据,请删除secret并重新创建。
|
||||
1. 要恢复 httpbin 的凭据,请删除 secret 并重新创建。
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl -n istio-system delete secret httpbin-credential
|
||||
|
@ -236,7 +236,7 @@ test: yes
|
|||
$ kubectl create -n istio-system secret tls helloworld-credential --key=helloworld-v1.example.com.key --cert=helloworld-v1.example.com.crt
|
||||
{{< /text >}}
|
||||
|
||||
1. 为端口443定义一个包含两个server定义的网关。将每个端口上的 `credentialName` 的值分别设置为 `httpbin-credential` 和 `helloworld-credential` 。将TLS模式设置为 `SIMPLE`。
|
||||
1. 为端口 443 定义一个包含两个 server 的网关。将每个端口上的 `credentialName` 的值分别设置为 `httpbin-credential` 和 `helloworld-credential` 。将 TLS 模式设置为 `SIMPLE`。
|
||||
|
||||
{{< text bash >}}
|
||||
$ cat <<EOF | kubectl apply -f -
|
||||
|
@ -319,9 +319,9 @@ test: yes
|
|||
`"""`
|
||||
{{< /text >}}
|
||||
|
||||
### 配置双向TLS入口网关 {#configure-a-mutual-TLS-ingress-gateway}
|
||||
### 配置双向 TLS 入口网关 {#configure-a-mutual-TLS-ingress-gateway}
|
||||
|
||||
您可以扩展网关的定义以支持[双向TLS](https://en.wikipedia.org/wiki/Mutual_authentication)。删除入口网关的secret并创建一个新的,以更改入口网关的凭据。服务器使用CA证书来验证其客户端,并且必须使用名称 `cacert` 来持有CA证书。
|
||||
您可以扩展网关的定义以支持[双向TLS](https://en.wikipedia.org/wiki/Mutual_authentication)。删除入口网关的 secret 并创建一个新的,以更改入口网关的凭据。服务器使用 CA 证书来验证其客户端,并且必须使用名称 `cacert` 来持有 CA 证书。
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl -n istio-system delete secret httpbin-credential
|
||||
|
@ -329,7 +329,7 @@ $ kubectl create -n istio-system secret generic httpbin-credential --from-file=t
|
|||
--from-file=tls.crt=httpbin.example.com.crt --from-file=ca.crt=example.com.crt
|
||||
{{< /text >}}
|
||||
|
||||
1. 更改网关的定义, 将TLS模式设置为 `MUTUAL` 。
|
||||
1. 更改网关的定义, 将 TLS 模式设置为 `MUTUAL` 。
|
||||
|
||||
{{< text bash >}}
|
||||
$ cat <<EOF | kubectl apply -f -
|
||||
|
@ -353,7 +353,7 @@ $ kubectl create -n istio-system secret generic httpbin-credential --from-file=t
|
|||
EOF
|
||||
{{< /text >}}
|
||||
|
||||
1. 尝试使用先前的方法发送HTTPS请求,并查看失败的详情:
|
||||
1. 尝试使用先前的方法发送 HTTPS 请求,并查看失败的详情:
|
||||
|
||||
{{< text bash >}}
|
||||
$ curl -v -HHost:httpbin.example.com --resolve "httpbin.example.com:$SECURE_INGRESS_PORT:$INGRESS_HOST" \
|
||||
|
@ -379,7 +379,7 @@ $ kubectl create -n istio-system secret generic httpbin-credential --from-file=t
|
|||
$ openssl x509 -req -days 365 -CA example.com.crt -CAkey example.com.key -set_serial 1 -in client.example.com.csr -out client.example.com.crt
|
||||
{{< /text >}}
|
||||
|
||||
1. 重新发送带客户端证书和私钥的 `curl` 请求。使用--cert标志传递客户端证书,使用--key标志传递私钥。
|
||||
1. 重新发送带客户端证书和私钥的 `curl` 请求。使用 --cert 标志传递客户端证书,使用 --key 标志传递私钥。
|
||||
|
||||
{{< text bash >}}
|
||||
$ curl -v -HHost:httpbin.example.com --resolve "httpbin.example.com:$SECURE_INGRESS_PORT:$INGRESS_HOST" \
|
||||
|
@ -397,11 +397,11 @@ $ kubectl create -n istio-system secret generic httpbin-credential --from-file=t
|
|||
`"""`
|
||||
{{< /text >}}
|
||||
|
||||
Istio支持读取不同的Secret格式,以支持与各种工具(例如[cert-manager](/zh/docs/ops/integrations/certmanager/))的集成:
|
||||
Istio 支持读取不同的 Secret 格式,以支持与各种工具(例如[cert-manager](/zh/docs/ops/integrations/certmanager/))的集成:
|
||||
|
||||
* 如上所述,包含 `tls.key` 和 `tls.crt` 的TLS secret。对于双向TLS,可以使用 `ca.crt` 密钥。
|
||||
* 包含 `key` 和 `cert` 的通用Secret。对于双向TLS,可以使用 `cacert` 密钥。
|
||||
* 包含 `key` 和 `cert` 的通用Secret。对于双向TLS,还可以单独设置名为 `<secret>-cacert` 的通用secret,该secret含 `cacert` 密钥。例如,`httpbin-credential` 包含 `key` 和 `cert`,而 `httpbin-credential-cacert` 包含 `cacert`。
|
||||
* 如上所述,包含 `tls.key` 和 `tls.crt` 的 TLS secret。对于双向 TLS,可以使用 `ca.crt` 密钥。
|
||||
* 包含 `key` 和 `cert` 的通用 Secret。对于双向 TLS,可以使用 `cacert` 密钥。
|
||||
* 包含 `key` 和 `cert` 的通用 Secret。对于双向 TLS,还可以单独设置名为 `<secret>-cacert` 的通用 secret,该 secret 含 `cacert` 密钥。例如,`httpbin-credential` 包含 `key` 和 `cert`,而 `httpbin-credential-cacert` 包含 `cacert`。
|
||||
|
||||
## Troubleshooting {#troubleshooting}
|
||||
|
||||
|
@ -419,15 +419,15 @@ Istio支持读取不同的Secret格式,以支持与各种工具(例如[cert-
|
|||
-n istio-system -o jsonpath='{.items[0].metadata.name}')"
|
||||
{{< /text >}}
|
||||
|
||||
* 如果使用macOS,请按照[准备工作](#before-you-begin)部分中的说明,验证您正在使用通过[LibreSSL](http://www.libressl.org)库编译的curl。
|
||||
* 如果使用 macOS,请按照[准备工作](#before-you-begin)部分中的说明,验证您正在使用通过[LibreSSL](http://www.libressl.org)库编译的 curl。
|
||||
|
||||
* 验证secret是否已在 `istio-system` 命名空间中成功创建:
|
||||
* 验证 secret 是否已在 `istio-system` 命名空间中成功创建:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl -n istio-system get secrets
|
||||
{{< /text >}}
|
||||
|
||||
`httpbin-credential` 和 `helloworld-credential` 应该显示在secret列表中。
|
||||
`httpbin-credential` 和 `helloworld-credential` 应该显示在 secret 列表中。
|
||||
|
||||
* 检查日志以确认入口网关代理已将密钥/证书对推送到入口网关。
|
||||
|
||||
|
@ -436,11 +436,11 @@ Istio支持读取不同的Secret格式,以支持与各种工具(例如[cert-
|
|||
-n istio-system -o jsonpath='{.items[0].metadata.name}')"
|
||||
{{< /text >}}
|
||||
|
||||
日志应显示已添加`httpbin-credential` secret。如果使用双向TLS,则还应显示 `httpbin-credential-cacert` secret。验证日志是否显示网关代理接收到来自入口网关的SDS请求(资源名称为 `httpbin-credential`),且入口网关已获得密钥/证书对。如果使用双向TLS,则日志应显示密钥/证书已发送到入口网关,网关代理已收到带有 `httpbin-credential-cacert`资源名称的SDS请求,并且入口网关已获得根证书。
|
||||
日志应显示已添加`httpbin-credential` secret。如果使用双向 TLS,则还应显示 `httpbin-credential-cacert` secret。验证日志是否显示网关代理接收到来自入口网关的 SDS 请求(资源名称为 `httpbin-credential`),且入口网关已获得密钥/证书对。如果使用双向 TLS,则日志应显示密钥/证书已发送到入口网关,网关代理已收到带有 `httpbin-credential-cacert`资源名称的 SDS 请求,并且入口网关已获得根证书。
|
||||
|
||||
## 清除 {#cleanup}
|
||||
|
||||
1. 删除网关配置,虚拟服务定义和secret:
|
||||
1. 删除网关配置,虚拟服务定义和 secret:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl delete gateway mygateway
|
||||
|
|
|
@ -0,0 +1,112 @@
|
|||
---
|
||||
title: Kubernetes Service APIs
|
||||
description: 描述如何使用 Kubernetes Service APIs 配置 Istio 服务。
|
||||
weight: 50
|
||||
keywords: [traffic-management,ingress]
|
||||
owner: istio/wg-networking-maintainers
|
||||
test: yes
|
||||
---
|
||||
|
||||
此任务描述如何使用 Kubernetes[Service APIs](https://kubernetes-sigs.github.io/gateway-api/)配置 Istio,将服务暴露到 service mesh 集群外。这些 API 是 Kubernetes[Service](https://kubernetes.io/docs/concepts/services-networking/service/)和[Ingress](https://kubernetes.io/docs/concepts/services-networking/ingress/)API 的发展演进。
|
||||
|
||||
## 设置 {#setup}
|
||||
|
||||
1. 调用 Service APIs 创建 CRDs:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl kustomize "github.com/kubernetes-sigs/service-apis/config/crd?ref=v0.1.0" | kubectl apply -f -
|
||||
{{< /text >}}
|
||||
|
||||
1. 安装 Istio 或重新配置 Istio,启动 Service APIs 控制器:
|
||||
|
||||
{{< text bash >}}
|
||||
$ istioctl install --set values.pilot.env.PILOT_ENABLED_SERVICE_APIS=true
|
||||
{{< /text >}}
|
||||
|
||||
1. 请按照 [确定 Ingress IP 和端口](/zh/docs/tasks/traffic-management/ingress/ingress-control/#determining-the-ingress-ip-and-ports)中的说明进行操作,取得入口网关的外部 IP 地址。
|
||||
|
||||
## 配置网关 {#configuring-a-gateway}
|
||||
|
||||
参见 [Service APIs](https://kubernetes-sigs.github.io/gateway-api/)文档中的 APIs 信息.
|
||||
|
||||
1. 部署一个测试应用:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl apply -f @samples/httpbin/httpbin.yaml@
|
||||
{{< /text >}}
|
||||
|
||||
1. 部署 Service APIs 配置:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl apply -f - <<EOF
|
||||
apiVersion: networking.x-k8s.io/v1alpha1
|
||||
kind: GatewayClass
|
||||
metadata:
|
||||
name: istio
|
||||
spec:
|
||||
controller: istio.io/gateway-controller
|
||||
---
|
||||
apiVersion: networking.x-k8s.io/v1alpha1
|
||||
kind: Gateway
|
||||
metadata:
|
||||
name: gateway
|
||||
namespace: istio-system
|
||||
spec:
|
||||
gatewayClassName: istio
|
||||
listeners:
|
||||
- hostname: "*"
|
||||
port: 80
|
||||
protocol: HTTP
|
||||
routes:
|
||||
namespaces:
|
||||
from: All
|
||||
selector:
|
||||
matchLabels:
|
||||
selected: "yes"
|
||||
kind: HTTPRoute
|
||||
---
|
||||
apiVersion: networking.x-k8s.io/v1alpha1
|
||||
kind: HTTPRoute
|
||||
metadata:
|
||||
name: http
|
||||
namespace: default
|
||||
labels:
|
||||
selected: "yes"
|
||||
spec:
|
||||
gateways:
|
||||
allow: All
|
||||
hostnames: ["httpbin.example.com"]
|
||||
rules:
|
||||
- matches:
|
||||
- path:
|
||||
type: Prefix
|
||||
value: /get
|
||||
filters:
|
||||
- type: RequestHeaderModifier
|
||||
requestHeaderModifier:
|
||||
add:
|
||||
my-added-header: added-value
|
||||
forwardTo:
|
||||
- serviceName: httpbin
|
||||
port: 8000
|
||||
EOF
|
||||
{{< /text >}}
|
||||
|
||||
1. 使用 _curl_ 访问刚才部署的 _httpbin_ 服务:
|
||||
|
||||
{{< text bash >}}
|
||||
$ curl -s -I -HHost:httpbin.example.com "http://$INGRESS_HOST:$INGRESS_PORT/get"
|
||||
HTTP/1.1 200 OK
|
||||
server: istio-envoy
|
||||
...
|
||||
{{< /text >}}
|
||||
|
||||
请注意,使用 `-H` 标志可以将 _Host_ HTTP 标头设置为"httpbin.example.com"。这一步是必需的,因为 `HTTPRoute` 已配置为处理"httpbin.example.com"的请求,但是在测试环境中,该主机没有 DNS 绑定,只是将请求发送到入口 IP。
|
||||
|
||||
1. 访问尚未显式公开的任何其他 URL,将会收到 HTTP 404 错误:
|
||||
|
||||
{{< text bash >}}
|
||||
$ curl -s -I -HHost:httpbin.example.com "http://$INGRESS_HOST:$INGRESS_PORT/headers"
|
||||
HTTP/1.1 404 Not Found
|
||||
...
|
||||
{{< /text >}}
|
Loading…
Reference in New Issue