mirror of https://github.com/istio/istio.io.git
[zh] sync /traffic-management/ingress/gateway-api/ (#12755)
This commit is contained in:
parent
245c034b55
commit
05e2035c40
|
@ -5,18 +5,21 @@ weight: 50
|
|||
aliases:
|
||||
- /zh/docs/tasks/traffic-management/ingress/service-apis/
|
||||
- /latest/zh/docs/tasks/traffic-management/ingress/service-apis/
|
||||
keywords: [traffic-management,ingress]
|
||||
keywords: [traffic-management,ingress, gateway-api]
|
||||
owner: istio/wg-networking-maintainers
|
||||
test: yes
|
||||
---
|
||||
|
||||
本文描述 Istio 和 Kubernetes API 之间的差异,并提供了一个简单的例子,向您演示如何配置 Istio 以使用 Gateway API 在服务网格集群外部暴露服务。
|
||||
本文描述 Istio 和 Kubernetes API 之间的差异,并提供了一个简单的例子,
|
||||
向您演示如何配置 Istio 以使用 Gateway API 在服务网格集群外部暴露服务。
|
||||
请注意,这些 API 是 Kubernetes [Service](https://kubernetes.io/zh-cn/docs/concepts/services-networking/service/)
|
||||
和 [Ingress](https://kubernetes.io/zh-cn/docs/concepts/services-networking/ingress/) API 的积极发展演进。
|
||||
|
||||
{{< tip >}}
|
||||
许多 Istio 流量管理文档均囊括了 Istio 或 Kubernetes API 的使用说明(例如请参阅[控制入站流量](/zh/docs/tasks/traffic-management/ingress/ingress-control))。
|
||||
通过参照[入门指南](/zh/docs/setup/additional-setup/getting-started/),您甚至从一开始就可以使用 Gateway API。
|
||||
许多 Istio 流量管理文档均囊括了 Istio 或 Kubernetes API 的使用说明
|
||||
(例如请参阅[控制入站流量](/zh/docs/tasks/traffic-management/ingress/ingress-control))。
|
||||
通过参照[入门指南](/zh/docs/setup/additional-setup/getting-started/),
|
||||
您甚至从一开始就可以使用 Gateway API。
|
||||
{{< /tip >}}
|
||||
|
||||
## 设置 {#setup}
|
||||
|
@ -24,7 +27,7 @@ test: yes
|
|||
1. 在大多数 Kubernetes 集群中,默认情况下不会安装 Gateway API。如果 Gateway API CRD 不存在,请安装:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl get crd gateways.gateway.networking.k8s.io || \
|
||||
$ kubectl get crd gateways.gateway.networking.k8s.io &> /dev/null || \
|
||||
{ kubectl kustomize "github.com/kubernetes-sigs/gateway-api/config/crd?ref={{< k8s_gateway_api_version >}}" | kubectl apply -f -; }
|
||||
{{< /text >}}
|
||||
|
||||
|
@ -43,13 +46,14 @@ Gateway API 与 Istio API (如 Gateway 和 VirtualService)有很多相似之
|
|||
以构建标准化的,独立于供应商的 API。
|
||||
这些 API 通常与 Istio Gateway 和 VirtualService 具有相同的用途,但有一些关键的区别:
|
||||
|
||||
* Istio API 中的`Gateway` 仅配置已部署的现有网关 Deployment/Service,
|
||||
而在 Gateway API 中的`Gateway` 资源不仅配置也会部署网关。
|
||||
有关更多信息,请参阅具体 [部署方法](#deployment-methods) 。
|
||||
* Istio API 中的 `Gateway` 仅配置已部署的现有网关 Deployment/Service,
|
||||
而在 Gateway API 中的 `Gateway` 资源不仅配置也会部署网关。
|
||||
有关更多信息,请参阅具体[部署方法](#deployment-methods) 。
|
||||
* 在 Istio `VirtualService` 中,所有协议都在单一的资源中配置,
|
||||
* 而在 Gateway API 中,每种协议类型都有自己的资源,例如 `HTTPRoute` 和 `TCPRoute`。
|
||||
* 虽然 Gateway API 提供了大量丰富的路由功能,但它还没有涵盖 Istio 的全部特性。
|
||||
因此,正在进行的工作是扩展 API 以覆盖这些用例,以及利用 API 的[可拓展性](https://gateway-api.sigs.k8s.io/#gateway-api-concepts)
|
||||
因此,正在进行的工作是扩展 API 以覆盖这些用例,以及利用 API
|
||||
的[可拓展性](https://gateway-api.sigs.k8s.io/#gateway-api-concepts)
|
||||
来更好地暴露 Istio 的功能。
|
||||
|
||||
## 配置网关 {#configuring-a-gateway}
|
||||
|
@ -58,13 +62,13 @@ Gateway API 与 Istio API (如 Gateway 和 VirtualService)有很多相似之
|
|||
|
||||
在本例中,我们将部署一个简单的应用程序,并使用 `Gateway` 将其暴露到外部。
|
||||
|
||||
1. 首先部署一个测试应用:
|
||||
1. 首先部署一个 `httpbin` 测试应用:
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl apply -f @samples/httpbin/httpbin.yaml@
|
||||
{{< /text >}}
|
||||
|
||||
1. 部署 Gateway API 配置:
|
||||
1. 部署 Gateway API 配置,包括单个暴露的路由(即 `/get`):
|
||||
|
||||
{{< text bash >}}
|
||||
$ kubectl create namespace istio-ingress
|
||||
|
@ -113,7 +117,7 @@ Gateway API 与 Istio API (如 Gateway 和 VirtualService)有很多相似之
|
|||
$ export INGRESS_HOST=$(kubectl get gateways.gateway.networking.k8s.io gateway -n istio-ingress -ojsonpath='{.status.addresses[*].value}')
|
||||
{{< /text >}}
|
||||
|
||||
1. 使用 *curl* 访问 *httpbin* 服务:
|
||||
1. 使用 *curl* 访问 `httpbin` 服务:
|
||||
|
||||
{{< text bash >}}
|
||||
$ curl -s -I -HHost:httpbin.example.com "http://$INGRESS_HOST/get"
|
||||
|
@ -123,7 +127,7 @@ Gateway API 与 Istio API (如 Gateway 和 VirtualService)有很多相似之
|
|||
{{< /text >}}
|
||||
|
||||
请注意,使用 `-H` 标志可以将 *Host* HTTP 标头设置为
|
||||
"httpbin.example.com"。这一步是必需的,因为 `HTTPRoute` 已配置为处理"httpbin.example.com"的请求,
|
||||
"httpbin.example.com"。这一步是必需的,因为 `HTTPRoute` 已配置为处理 "httpbin.example.com" 的请求,
|
||||
但是在测试环境中,该主机没有 DNS 绑定,只是将请求发送到入口 IP。
|
||||
|
||||
1. 访问其他没有被显式暴露的 URL 时,将看到 HTTP 404 错误:
|
||||
|
@ -182,8 +186,8 @@ Gateway API 与 Istio API (如 Gateway 和 VirtualService)有很多相似之
|
|||
|
||||
## 部署方法{#deployment-methods}
|
||||
|
||||
在上面的示例中,在配置网关之前,您不需要安装 ingress 网关 `Deployment`。
|
||||
因为在默认配置中会根据 `Gateway` 配置自动分发网关`Deployment` 和 `Service`。
|
||||
在上面的示例中,在配置网关之前,您不需要安装 Ingress 网关 `Deployment`。
|
||||
因为在默认配置中会根据 `Gateway` 配置自动分发网关 `Deployment` 和 `Service`。
|
||||
但是对于高级别的用例,仍然允许手动部署。
|
||||
|
||||
### 自动部署{#automated-deployment}
|
||||
|
@ -194,10 +198,11 @@ Gateway API 与 Istio API (如 Gateway 和 VirtualService)有很多相似之
|
|||
这些资源可以通过以下几种方式进行定义:
|
||||
|
||||
* 将`Gateway` 上的注释和标签复制到 `Service` 和 `Deployment`。
|
||||
这就允许配置从上述字段中读取到的内容,如配置[内部负载均衡器](https://kubernetes.io/zh/docs/concepts/services-networking/service/#internal-load-balancer)等。
|
||||
这就允许配置从上述字段中读取到的内容,
|
||||
如配置[内部负载均衡器](https://kubernetes.io/zh-cn/docs/concepts/services-networking/service/#internal-load-balancer)等。
|
||||
* Istio 提供了一个额外的注释来配置生成的资源:
|
||||
|
||||
|Annotation| 用途 |
|
||||
|注解 | 用途 |
|
||||
|----------|-------|
|
||||
|`networking.istio.io/service-type`|控制 `Service.spec.type` 字段。 例如,设置 `ClusterIP` 为不对外暴露服务,将会默认为`LoadBalancer`。|
|
||||
|
||||
|
@ -215,17 +220,80 @@ Gateway API 与 Istio API (如 Gateway 和 VirtualService)有很多相似之
|
|||
...
|
||||
{{< /text >}}
|
||||
|
||||
请注意:仅能指定一个地址。
|
||||
请注意:仅能指定一个地址。
|
||||
|
||||
* (高级用法)生成的 Pod 配置可以通过[自定义注入模板](/zh/docs/setup/additional-setup/sidecar-injection/#custom-templates-experimental)进行配置。
|
||||
|
||||
#### 资源附加和扩缩{#resource-attachment-and-scaling}
|
||||
|
||||
{{< warning >}}
|
||||
资源附加目前是实验性的功能。
|
||||
{{< /warning >}}
|
||||
|
||||
资源可以附加到 `Gateway` 进行自定义。
|
||||
然而,大多数 Kubernetes 资源目前不支持直接附加到 `Gateway`,
|
||||
但这些资源可以转为直接被附加到相应生成的 `Deployment` 和 `Service`。
|
||||
这个操作比较简单,因为这两种资源被生成时名称为 `<gateway name>-<gateway class name>`
|
||||
且带有标签 `istio.io/gateway-name: <gateway name>`。
|
||||
|
||||
例如,参照以下部署类别为 `HorizontalPodAutoscaler` 和 `PodDisruptionBudget` 的 `Gateway`:
|
||||
|
||||
{{< text yaml >}}
|
||||
apiVersion: gateway.networking.k8s.io/v1beta1
|
||||
kind: Gateway
|
||||
metadata:
|
||||
name: gateway
|
||||
spec:
|
||||
gatewayClassName: istio
|
||||
listeners:
|
||||
- name: default
|
||||
hostname: "*.example.com"
|
||||
port: 80
|
||||
protocol: HTTP
|
||||
allowedRoutes:
|
||||
namespaces:
|
||||
from: All
|
||||
---
|
||||
apiVersion: autoscaling/v2
|
||||
kind: HorizontalPodAutoscaler
|
||||
metadata:
|
||||
name: gateway
|
||||
spec:
|
||||
# 通过引用与生成的 Deployment 匹配
|
||||
# 注意不要使用 `kind: Gateway`
|
||||
scaleTargetRef:
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
name: gateway-istio
|
||||
minReplicas: 2
|
||||
maxReplicas: 5
|
||||
metrics:
|
||||
- type: Resource
|
||||
resource:
|
||||
name: cpu
|
||||
target:
|
||||
type: Utilization
|
||||
averageUtilization: 50
|
||||
---
|
||||
apiVersion: policy/v1
|
||||
kind: PodDisruptionBudget
|
||||
metadata:
|
||||
name: gateway
|
||||
spec:
|
||||
minAvailable: 1
|
||||
selector:
|
||||
# Match the generated Deployment by label
|
||||
matchLabels:
|
||||
istio.io/gateway-name: gateway
|
||||
{{< /text >}}
|
||||
|
||||
### 手动部署{#manual-deployment}
|
||||
|
||||
如果您不希望使用自动部署,可以进行[手动配置](/zh/docs/setup/additional-setup/gateway/) `Deployment` 和 `Service`。
|
||||
|
||||
完成此选项后,您将需要手动将 `Gateway` 链接到 `Service`,并保持它们的端口配置同步。
|
||||
|
||||
要将 `Gateway` 链接到 `Service`,需要将 `addresses` 字段配置为指向**单个**主机名。
|
||||
要将 `Gateway` 链接到 `Service`,需要将 `addresses` 字段配置为指向**单个** `Hostname`。
|
||||
|
||||
{{< text yaml >}}
|
||||
apiVersion: gateway.networking.k8s.io/v1beta1
|
||||
|
@ -274,7 +342,7 @@ spec:
|
|||
|
||||
有关更多详情和示例,请参阅其他[流量管理](/zh/docs/tasks/traffic-management/)。
|
||||
|
||||
## 清理 {#cleanup}
|
||||
## 清理{#cleanup}
|
||||
|
||||
1. 卸载 Istio 和 `httpbin` 示例:
|
||||
|
||||
|
|
Loading…
Reference in New Issue