diff --git a/content/zh-cn/docs/concepts/services-networking/endpoint-slices.md b/content/zh-cn/docs/concepts/services-networking/endpoint-slices.md index db020d326c..d49e0aa9e3 100644 --- a/content/zh-cn/docs/concepts/services-networking/endpoint-slices.md +++ b/content/zh-cn/docs/concepts/services-networking/endpoint-slices.md @@ -9,7 +9,6 @@ description: >- EndpointSlice API 是 Kubernetes 用于扩缩 Service 以处理大量后端的机制,还允许集群高效更新其健康后端的列表。 --- - Kubernetes 的 _EndpointSlice_ API 提供了一种简单的方法来跟踪 -Kubernetes 集群中的网络端点(network endpoints)。EndpointSlices 为 -[Endpoints](/zh-cn/docs/concepts/services-networking/service/#endpoints) -提供了一种可扩缩和可拓展的替代方案。 +Kubernetes 集群中的网络端点(network endpoints)。 @@ -49,8 +45,8 @@ endpoints. The control plane automatically creates EndpointSlices for any Kubernetes Service that has a {{< glossary_tooltip text="selector" term_id="selector" >}} specified. These EndpointSlices include references to all the Pods that match the Service selector. EndpointSlices group -network endpoints together by unique combinations of protocol, port number, and -Service name. +network endpoints together by unique combinations of IP family, protocol, +port number, and Service name. The name of a EndpointSlice object must be a valid [DNS subdomain name](/docs/concepts/overview/working-with-objects/names#dns-subdomain-names). @@ -63,7 +59,7 @@ Kubernetes Service. 控制面会自动为设置了{{< glossary_tooltip text="选择算符" term_id="selector" >}}的 Kubernetes Service 创建 EndpointSlice。 这些 EndpointSlice 将包含对与 Service 选择算符匹配的所有 Pod 的引用。 -EndpointSlice 通过唯一的协议、端口号和 Service 名称将网络端点组织在一起。 +EndpointSlice 通过唯一的 IP 地址簇、协议、端口号和 Service 名称将网络端点组织在一起。 EndpointSlice 的名称必须是合法的 [DNS 子域名](/zh-cn/docs/concepts/overview/working-with-objects/names#dns-subdomain-names)。 @@ -98,7 +94,7 @@ more than 100 endpoints each. You can configure this with the {{< glossary_tooltip text="kube-controller-manager" term_id="kube-controller-manager" >}} flag, up to a maximum of 1000. -EndpointSlices can act as the source of truth for +EndpointSlices act as the source of truth for {{< glossary_tooltip term_id="kube-proxy" text="kube-proxy" >}} when it comes to how to route internal traffic. --> @@ -106,18 +102,17 @@ how to route internal traffic. 你可以使用 {{< glossary_tooltip text="kube-controller-manager" term_id="kube-controller-manager" >}} 的 `--max-endpoints-per-slice` 标志设置此值,最大值为 1000。 -当涉及如何路由内部流量时,EndpointSlice 可以充当 +当涉及如何路由内部流量时,EndpointSlice 充当 {{< glossary_tooltip term_id="kube-proxy" text="kube-proxy" >}} 的决策依据。 ### 地址类型 -EndpointSlice 支持三种地址类型: +EndpointSlice 支持两种地址类型: * IPv4 * IPv6 -* FQDN (完全合格的域名) 每个 `EndpointSlice` 对象代表一个特定的 IP 地址类型。如果你有一个支持 IPv4 和 IPv6 的 Service, 那么将至少有两个 `EndpointSlice` 对象(一个用于 IPv4,一个用于 IPv6)。 @@ -138,79 +132,66 @@ EndpointSlice 支持三种地址类型: ### Conditions The EndpointSlice API stores conditions about endpoints that may be useful for consumers. -The three conditions are `ready`, `serving`, and `terminating`. +The three conditions are `serving`, `terminating`, and `ready`. --> ### 状况 EndpointSlice API 存储了可能对使用者有用的、有关端点的状况。 -这三个状况分别是 `ready`、`serving` 和 `terminating`。 - - -#### Ready(就绪) - -`ready` 状况是映射 Pod 的 `Ready` 状况的。 -对于处于运行中的 Pod,它的 `Ready` 状况被设置为 `True`,应该将此 EndpointSlice 状况也设置为 `true`。 -出于兼容性原因,当 Pod 处于终止过程中,`ready` 永远不会为 `true`。 -消费者应参考 `serving` 状况来检查处于终止中的 Pod 的就绪情况。 -该规则的唯一例外是将 `spec.publishNotReadyAddresses` 设置为 `true` 的 Service。 -这些 Service 的端点将始终将 `ready` 状况设置为 `true`。 +这三个状况分别是 `serving`、`terminating` 和 `ready`。 #### Serving(服务中) {{< feature-state for_k8s_version="v1.26" state="stable" >}} -`serving` 状况几乎与 `ready` 状况相同,不同之处在于它不考虑终止状态。 -如果 EndpointSlice API 的使用者关心 Pod 终止时的就绪情况,就应检查 `serving` 状况。 - -{{< note >}} -尽管 `serving` 与 `ready` 几乎相同,但是它是为防止破坏 `ready` 的现有含义而增加的。 -如果对于处于终止中的端点,`ready` 可能是 `true`,那么对于现有的客户端来说可能是有些意外的, -因为从始至终,Endpoints 或 EndpointSlice API 从未包含处于终止中的端点。 -出于这个原因,`ready` 对于处于终止中的端点 **总是** `false`, -并且在 v1.20 中添加了新的状况 `serving`,以便客户端可以独立于 `ready` -的现有语义来跟踪处于终止中的 Pod 的就绪情况。 -{{< /note >}} +`serving` 状况表示端点目前正在提供响应,且因此应将其用作 Service 流量的目标。 +对于由 Pod 支持的端点,此状况对应于 Pod 的 `Ready` 状况。 #### Terminating(终止中) -{{< feature-state for_k8s_version="v1.22" state="beta" >}} +{{< feature-state for_k8s_version="v1.26" state="stable" >}} -`Terminating` 是表示端点是否处于终止中的状况。 -对于 Pod 来说,这是设置了删除时间戳的 Pod。 + +`terminating` 状况表示端点正在终止中。对于由 Pod 支持的端点, +当 Pod 首次被删除时(即收到删除时间戳时,但很可能在容器实际退出之前),会设置此状况。 + +服务代理通常会忽略处于 `terminating` 状态的端点,但如果所有可用端点都处于 `terminating`, +服务代理可能仍会将流量路由到同时具有 `serving` 和 `terminating` 的端点。 +(这样有助于在底层 Pod 滚动更新过程中确保 Service 流量不会中断。) + + +#### Ready(就绪) + +`ready` 状况本质上是检查 "`serving` 且不是 `terminating`" 的一种简化方式 +(不过对于将 `spec.publishNotReadyAddresses` 设置为 `true` 的 Service,`ready` 状况始终设置为 `true`)。 -在 v1 API 中,逐个端点设置的 `topology` 实际上被去除, -以鼓励使用专用的字段 `nodeName` 和 `zone`。 - - -对 `EndpointSlice` 对象的 `endpoint` 字段设置任意的拓扑结构信息这一操作已被废弃, -不再被 v1 API 所支持。取而代之的是 v1 API 所支持的 `nodeName` 和 `zone` -这些独立的字段。这些字段可以在不同的 API 版本之间自动完成转译。 -例如,v1beta1 API 中 `topology` 字段的 `topology.kubernetes.io/zone` -取值可以在 v1 API 中通过 `zone` 字段访问。 -{{< /note >}} - -### EndpointSlice 镜像 {#endpointslice-mirroring} - -在某些场合,应用会创建定制的 Endpoints 资源。为了保证这些应用不需要并发的更改 -Endpoints 和 EndpointSlice 资源,集群的控制面将大多数 Endpoints -映射到对应的 EndpointSlice 之上。 - - -控制面对 Endpoints 资源进行映射的例外情况有: - -* Endpoints 资源上标签 `endpointslice.kubernetes.io/skip-mirror` 值为 `true`。 -* Endpoints 资源包含标签 `control-plane.alpha.kubernetes.io/leader`。 -* 对应的 Service 资源不存在。 -* 对应的 Service 的选择算符不为空。 - - -每个 Endpoints 资源可能会被转译到多个 EndpointSlices 中去。 -当 Endpoints 资源中包含多个子网或者包含多个 IP 协议族(IPv4 和 IPv6)的端点时, -就有可能发生这种状况。 -每个子网最多有 1000 个地址会被镜像到 EndpointSlice 中。 - ### EndpointSlices 的分布问题 {#distribution-of-endpointslices} 每个 EndpointSlice 都有一组端口值,适用于资源内的所有端点。 当为 Service 使用命名端口时,Pod 可能会就同一命名端口获得不同的端口号, -因而需要不同的 EndpointSlice。这有点像 Endpoints 用来对子网进行分组的逻辑。 +因而需要不同的 EndpointSlice。 -## 与 Endpoints 的比较 {#motivation} -原来的 Endpoints API 提供了在 Kubernetes 中跟踪网络端点的一种简单而直接的方法。随着 Kubernetes -集群和{{< glossary_tooltip text="服务" term_id="service" >}}逐渐开始为更多的后端 Pod 处理和发送请求, -原来的 API 的局限性变得越来越明显。最明显的是那些因为要处理大量网络端点而带来的挑战。 +### EndpointSlice 镜像 {#endpointslice-mirroring} + +{{< feature-state for_k8s_version="v1.33" state="deprecated" >}} -由于任一 Service 的所有网络端点都保存在同一个 Endpoints 对象中,这些 Endpoints -对象可能变得非常巨大。对于保持稳定的服务(长时间使用同一组端点),影响不太明显; -即便如此,Kubernetes 的一些使用场景也没有得到很好的服务。 +EndpointSlice API 是旧版 Endpoints API 的替代方案。 +为了保持与旧版控制器和用户工作负载的兼容性 +(例如期望由 {{}} 基于 Endpoints 资源来路由流量), +集群的控制平面会将大多数用户创建的 Endpoints 资源镜像到相应的 EndpointSlice 中。 -当某 Service 存在很多后端端点并且该工作负载频繁扩缩或上线新更改时,对该 Service 的单个 Endpoints -对象的每次更新都意味着(在控制平面内以及在节点和 API 服务器之间)Kubernetes 集群组件之间会出现大量流量。 -这种额外的流量在 CPU 使用方面也有开销。 +(不过,与 Endpoints API 的其他部分一样,此特性也已被弃用。 +对于无选择算符的 Service,用户如果需要手动指定端点,应该直接创建 EndpointSlice 资源, +而不是创建 Endpoints 资源并允许其被镜像。) -使用 EndpointSlices 时,添加或移除单个 Pod 对于正监视变更的客户端会触发相同数量的更新, -但这些更新消息的大小在大规模场景下要小得多。 +控制面对 Endpoints 资源进行映射的例外情况有: + +* Endpoints 资源上标签 `endpointslice.kubernetes.io/skip-mirror` 值为 `true`。 +* Endpoints 资源包含标签 `control-plane.alpha.kubernetes.io/leader`。 +* 对应的 Service 资源不存在。 +* 对应的 Service 的选择算符不为空。 -EndpointSlices 还支持围绕双栈网络和拓扑感知路由等新功能的创新。 +每个 Endpoints 资源可能会被转译到多个 EndpointSlices 中去。 +当 Endpoints 资源中包含多个子网或者包含多个 IP 协议族(IPv4 和 IPv6)的端点时, +就有可能发生这种状况。 +每个子网最多有 1000 个地址会被镜像到 EndpointSlice 中。 ## {{% heading "whatsnext" %}}