@@ -5,7 +5,7 @@ title: Services
5
5
feature :
6
6
title : 服务发现与负载均衡
7
7
description : >
8
- 无需修改您的应用程序即可使用陌生的服务发现机制。Kubernetes 为容器提供了自己的 IP 地址和一个 DNS 名称,并且可以在它们之间实现负载平衡 。
8
+ 无需修改您的应用程序即可使用陌生的服务发现机制。Kubernetes 为容器提供了自己的 IP 地址和一个 DNS 名称,并且可以在它们之间实现负载均衡 。
9
9
10
10
content_type : concept
11
11
weight : 10
@@ -328,6 +328,27 @@ Endpoint 切片是一种 API 资源,可以为 Endpoint 提供更可扩展的
328
328
329
329
Endpoint 切片提供了附加的属性和功能,这些属性和功能在 [Endpoint 切片](/docs/concepts/services-networking/endpoint-slices/)中进行了详细描述。
330
330
331
+ <!--
332
+ # ## Application protocol
333
+
334
+ {{< feature-state for_k8s_version="v1.18" state="alpha" >}}
335
+
336
+ The AppProtocol field provides a way to specify an application protocol to be
337
+ used for each Service port.
338
+
339
+ As an alpha feature, this field is not enabled by default. To use this field,
340
+ enable the `ServiceAppProtocol` [feature
341
+ gate](/docs/reference/command-line-tools-reference/feature-gates/).
342
+ -->
343
+ # ## 应用程序协议
344
+
345
+ {{< feature-state for_k8s_version="v1.18" state="alpha" >}}
346
+
347
+ AppProtocol 字段提供了一种为每个 Service 端口指定应用程序协议的方式。
348
+
349
+ 作为一个 alpha 特性,该字段默认未启用。要使用该字段,请启用 `ServiceAppProtocol` [特性开关]
350
+ (/docs/reference/command-line-tools-reference/feature-gates/)。
351
+
331
352
<!--
332
353
# # Virtual IPs and service proxies
333
354
@@ -868,6 +889,25 @@ to just expose one or more nodes' IPs directly.
868
889
869
890
Note that this Service is visible as `<NodeIP>:spec.ports[*].nodePort`
870
891
and `.spec.clusterIP:spec.ports[*].port`. (If the `--nodeport-addresses` flag in kube-proxy is set, <NodeIP> would be filtered NodeIP(s).)
892
+
893
+ For example :
894
+ ` ` ` yaml
895
+ apiVersion: v1
896
+ kind: Service
897
+ metadata:
898
+ name: my-service
899
+ spec:
900
+ type: NodePort
901
+ selector:
902
+ app: MyApp
903
+ ports:
904
+ # By default and for convenience, the ` targetPort` is set to the same value as the `port` field.
905
+ - port : 80
906
+ targetPort : 80
907
+ # Optional field
908
+ # By default and for convenience, the Kubernetes control plane will allocate a port from a range (default: 30000-32767)
909
+ nodePort : 30007
910
+ ` ` `
871
911
-->
872
912
873
913
### NodePort 类型
@@ -891,6 +931,25 @@ and `.spec.clusterIP:spec.ports[*].port`. (If the `--nodeport-addresses` flag in
891
931
892
932
需要注意的是,Service 能够通过 `<NodeIP>:spec.ports[*].nodePort` 和 `spec.clusterIp:spec.ports[*].port` 而对外可见。
893
933
934
+ 例如:
935
+ ` ` ` yaml
936
+ apiVersion: v1
937
+ kind: Service
938
+ metadata:
939
+ name: my-service
940
+ spec:
941
+ type: NodePort
942
+ selector:
943
+ app: MyApp
944
+ ports:
945
+ # 默认情况下,为了方便起见,` targetPort` 被设置为与 `port` 字段相同的值。
946
+ - port : 80
947
+ targetPort : 80
948
+ # 可选字段
949
+ # 默认情况下,为了方便起见,Kubernetes 控制平面会从某个范围内分配一个端口号(默认:30000-32767)
950
+ nodePort : 30007
951
+ ` ` `
952
+
894
953
<!--
895
954
### Type LoadBalancer {#loadbalancer}
896
955
@@ -1032,6 +1091,16 @@ metadata:
1032
1091
[...]
1033
1092
` ` `
1034
1093
{{% /tab %}}
1094
+ {{% tab name="IBM Cloud" %}}
1095
+ ` ` ` yaml
1096
+ [...]
1097
+ metadata:
1098
+ name: my-service
1099
+ annotations:
1100
+ service.kubernetes.io/ibm-load-balancer-cloud-provider-ip-type: "private"
1101
+ [...]
1102
+ ` ` `
1103
+ {{% /tab %}}
1035
1104
{{% tab name="OpenStack" %}}
1036
1105
` ` ` yaml
1037
1106
[...]
@@ -1561,7 +1630,7 @@ worth understanding.
1561
1630
One of the primary philosophies of Kubernetes is that you should not be
1562
1631
exposed to situations that could cause your actions to fail through no fault
1563
1632
of your own. For the design of the Service resource, this means not making
1564
- you choose your own port number for a if that choice might collide with
1633
+ you choose your own port number if that choice might collide with
1565
1634
someone else's choice. That is an isolation failure.
1566
1635
1567
1636
In order to allow you to choose a port number for your Services, we must
@@ -1576,7 +1645,7 @@ fail with a message indicating an IP address could not be allocated.
1576
1645
1577
1646
In the control plane, a background controller is responsible for creating that
1578
1647
map (needed to support migrating from older versions of Kubernetes that used
1579
- in-memory locking). Kubernetes also uses controllers to checking for invalid
1648
+ in-memory locking). Kubernetes also uses controllers to check for invalid
1580
1649
assignments (eg due to administrator intervention) and for cleaning up allocated
1581
1650
IP addresses that are no longer used by any Services.
1582
1651
@@ -1585,15 +1654,16 @@ IP addresses that are no longer used by any Services.
1585
1654
# ## 避免冲突
1586
1655
1587
1656
Kubernetes 最主要的哲学之一,是用户不应该暴露那些能够导致他们操作失败、但又不是他们的过错的场景。
1588
- 这种场景下,让我们来看一下网络端口 —— 用户不应该必须选择一个端口号,而且该端口还有可能与其他用户的冲突。
1589
- 这就是说,在彼此隔离状态下仍然会出现失败。
1657
+ 对于 Service 资源的设计,这意味着如果用户的选择有可能与他人冲突,那就不要让用户自行选择端口号。
1658
+ 这是一个隔离性的失败。
1659
+
1660
+ 为了使用户能够为他们的 Service 选择一个端口号,我们必须确保不能有2个 Service 发生冲突。
1661
+ Kubernetes 通过为每个 Service 分配它们自己的 IP 地址来实现。
1590
1662
1591
- 为了使用户能够为他们的 ` Service` 选择一个端口号,我们必须确保不能有2个 `Service` 发生冲突 。
1592
- 我们可以通过为每个 ` Service` 分配它们自己的 IP 地址来实现 。
1663
+ 为了保证每个 Service 被分配到一个唯一的 IP,需要一个内部的分配器能够原子地更新 {{< glossary_tooltip term_id="etcd" >}} 中的一个全局分配映射表,这个更新操作要先于创建每一个 Service 。
1664
+ 为了使 Service 能够获取到 IP,这个映射表对象必须在注册中心存在,否则创建 Service 将会失败,指示一个 IP 不能被分配 。
1593
1665
1594
- 为了保证每个 `Service` 被分配到一个唯一的 IP,需要一个内部的分配器能够原子地更新 etcd 中的一个全局分配映射表,这个更新操作要先于创建每一个 `Service`。
1595
- 为了使 `Service` 能够获取到 IP,这个映射表对象必须在注册中心存在,否则创建 `Service` 将会失败,指示一个 IP 不能被分配。
1596
- 一个后台 Controller 的职责是创建映射表(从 Kubernetes 的旧版本迁移过来,旧版本中是通过在内存中加锁的方式实现),并检查由于管理员干预和清除任意 IP 造成的不合理分配,这些 IP 被分配了但当前没有 `Service` 使用它们。
1666
+ 在控制平面中,一个后台 Controller 的职责是创建映射表(需要支持从使用了内存锁的 Kubernetes 的旧版本迁移过来)。同时 Kubernetes 会通过控制器检查不合理的分配(如管理员干预导致的)以及清理已被分配但不再被任何 Service 使用的 IP 地址。
1597
1667
1598
1668
<!--
1599
1669
# ## Service IP addresses {#ips-and-vips}
0 commit comments