@@ -429,7 +429,8 @@ as a destination.
429
429
430
430
<!--
431
431
For an EndpointSlice that you create yourself, or in your own code,
432
- you should also pick a value to use for the [`endpointslice.kubernetes.io/managed-by`](/docs/reference/labels-annotations-taints/#endpointslicekubernetesiomanaged-by) label.
432
+ you should also pick a value to use for the label
433
+ [`endpointslice.kubernetes.io/managed-by`](/docs/reference/labels-annotations-taints/#endpointslicekubernetesiomanaged-by).
433
434
If you create your own controller code to manage EndpointSlices, consider using a
434
435
value similar to `"my-domain.example/name-of-controller"`. If you are using a third
435
436
party tool, use the name of the tool in all-lowercase and change spaces and other
@@ -453,7 +454,8 @@ managed by Kubernetes' own control plane.
453
454
# ### Accessing a Service without a selector {#service-no-selector-access}
454
455
455
456
Accessing a Service without a selector works the same as if it had a selector.
456
- In the [example](#services-without-selectors) for a Service without a selector, traffic is routed to one of the two endpoints defined in
457
+ In the [example](#services-without-selectors) for a Service without a selector,
458
+ traffic is routed to one of the two endpoints defined in
457
459
the EndpointSlice manifest : a TCP connection to 10.1.2.3 or 10.4.5.6, on port 9376.
458
460
-->
459
461
# ### 访问没有选择算符的 Service {#service-no-selector-access}
@@ -555,8 +557,7 @@ Endpoints API。
555
557
<!--
556
558
In that case, Kubernetes selects at most 1000 possible backend endpoints to store
557
559
into the Endpoints object, and sets an
558
- {{< glossary_tooltip text="annotation" term_id="annotation" >}} on the
559
- Endpoints :
560
+ {{< glossary_tooltip text="annotation" term_id="annotation" >}} on the Endpoints:
560
561
[`endpoints.kubernetes.io/over-capacity : truncated`](/docs/reference/labels-annotations-taints/#endpoints-kubernetes-io-over-capacity).
561
562
The control plane also removes that annotation if the number of backend Pods drops below 1000.
562
563
-->
@@ -585,8 +586,8 @@ The same API limit means that you cannot manually update an Endpoints to have mo
585
586
586
587
<!--
587
588
The `appProtocol` field provides a way to specify an application protocol for
588
- each Service port. This is used as a hint for implementations to offer richer
589
- behavior for protocols that they understand.
589
+ each Service port. This is used as a hint for implementations to offer
590
+ richer behavior for protocols that they understand.
590
591
The value of this field is mirrored by the corresponding
591
592
Endpoints and EndpointSlice objects.
592
593
-->
@@ -690,7 +691,8 @@ Kubernetes Service 类型允许指定你所需要的 Service 类型。
690
691
: Exposes the Service on a cluster-internal IP. Choosing this value
691
692
makes the Service only reachable from within the cluster. This is the
692
693
default that is used if you don't explicitly specify a `type` for a Service.
693
- You can expose the Service to the public internet using an [Ingress](/docs/concepts/services-networking/ingress/) or a
694
+ You can expose the Service to the public internet using an
695
+ [Ingress](/docs/concepts/services-networking/ingress/) or a
694
696
[Gateway](https://gateway-api.sigs.k8s.io/).
695
697
696
698
[`NodePort`](#type-nodeport)
@@ -734,7 +736,7 @@ Kubernetes Service 类型允许指定你所需要的 Service 类型。
734
736
The `type` field in the Service API is designed as nested functionality - each level
735
737
adds to the previous. However there is an exception to this nested design. You can
736
738
define a `LoadBalancer` Service by
737
- [disabling the load balancer `NodePort` allocation. ](/docs/concepts/services-networking/service/#load-balancer-nodeport-allocation)
739
+ [disabling the load balancer `NodePort` allocation](/docs/concepts/services-networking/service/#load-balancer-nodeport-allocation).
738
740
-->
739
741
服务 API 中的 `type` 字段被设计为层层递进的形式 - 每层都建立在前一层的基础上。
740
742
但是,这种层层递进的形式有一个例外。
@@ -851,6 +853,27 @@ a NodePort value (30007, in this example):
851
853
852
854
以下是 `type : NodePort` 服务的一个清单示例,其中指定了 NodePort 值(在本例中为 30007):
853
855
856
+ <!--
857
+ ` ` ` yaml
858
+ apiVersion: v1
859
+ kind: Service
860
+ metadata:
861
+ name: my-service
862
+ spec:
863
+ type: NodePort
864
+ selector:
865
+ app.kubernetes.io/name: MyApp
866
+ ports:
867
+ - port: 80
868
+ # By default and for convenience, the ` targetPort` is set to
869
+ # the same value as the `port` field.
870
+ targetPort : 80
871
+ # Optional field
872
+ # By default and for convenience, the Kubernetes control plane
873
+ # will allocate a port from a range (default: 30000-32767)
874
+ nodePort : 30007
875
+ ` ` `
876
+ -->
854
877
` ` ` yaml
855
878
apiVersion : v1
856
879
kind : Service
@@ -904,8 +927,7 @@ control plane).
904
927
905
928
If you want to specify particular IP address(es) to proxy the port, you can set the
906
929
` --nodeport-addresses` flag for kube-proxy or the equivalent `nodePortAddresses`
907
- field of the
908
- [kube-proxy configuration file](/docs/reference/config-api/kube-proxy-config.v1alpha1/)
930
+ field of the [kube-proxy configuration file](/docs/reference/config-api/kube-proxy-config.v1alpha1/)
909
931
to particular IP block(s).
910
932
-->
911
933
# ### 为 `type: NodePort` 服务自定义 IP 地址配置 {#service-nodeport-custom-listen-address}
@@ -941,7 +963,8 @@ kube-proxy 应视将其视为所在节点的本机地址。
941
963
<!--
942
964
This Service is visible as `<NodeIP>:spec.ports[*].nodePort` and `.spec.clusterIP:spec.ports[*].port`.
943
965
If the `--nodeport-addresses` flag for kube-proxy or the equivalent field
944
- in the kube-proxy configuration file is set, `<NodeIP>` would be a filtered node IP address (or possibly IP addresses).
966
+ in the kube-proxy configuration file is set, `<NodeIP>` would be a filtered
967
+ node IP address (or possibly IP addresses).
945
968
-->
946
969
此 Service 的可见形式为 `<NodeIP>:spec.ports[*].nodePort` 以及 `.spec.clusterIP:spec.ports[*].port`。
947
970
如果设置了 kube-proxy 的 `--nodeport-addresses` 标志或 kube-proxy 配置文件中的等效字段,
@@ -1024,7 +1047,8 @@ set is ignored.
1024
1047
<!--
1025
1048
The`.spec.loadBalancerIP` field for a Service was deprecated in Kubernetes v1.24.
1026
1049
1027
- This field was under-specified and its meaning varies across implementations. It also cannot support dual-stack networking. This field may be removed in a future API version.
1050
+ This field was under-specified and its meaning varies across implementations.
1051
+ It also cannot support dual-stack networking. This field may be removed in a future API version.
1028
1052
-->
1029
1053
针对 Service 的 `.spec.loadBalancerIP` 字段已在 Kubernetes v1.24 中被弃用。
1030
1054
@@ -1174,109 +1198,91 @@ Select one of the tabs.
1174
1198
{{% tab name="GCP" %}}
1175
1199
1176
1200
` ` ` yaml
1177
- [...]
1178
1201
metadata:
1179
- name: my-service
1180
- annotations:
1181
- networking.gke.io/load-balancer-type: "Internal"
1182
- [...]
1202
+ name: my-service
1203
+ annotations:
1204
+ networking.gke.io/load-balancer-type: "Internal"
1183
1205
` ` `
1184
1206
1185
1207
{{% /tab %}}
1186
1208
{{% tab name="AWS" %}}
1187
1209
1188
1210
` ` ` yaml
1189
- [...]
1190
1211
metadata:
1191
1212
name: my-service
1192
1213
annotations:
1193
1214
service.beta.kubernetes.io/aws-load-balancer-internal: "true"
1194
- [...]
1195
1215
` ` `
1196
1216
1197
1217
{{% /tab %}}
1198
1218
{{% tab name="Azure" %}}
1199
1219
1200
1220
` ` ` yaml
1201
- [...]
1202
1221
metadata:
1203
- name: my-service
1204
- annotations:
1205
- service.beta.kubernetes.io/azure-load-balancer-internal: "true"
1206
- [...]
1222
+ name: my-service
1223
+ annotations:
1224
+ service.beta.kubernetes.io/azure-load-balancer-internal: "true"
1207
1225
` ` `
1208
1226
1209
1227
{{% /tab %}}
1210
1228
{{% tab name="IBM Cloud" %}}
1211
1229
1212
1230
` ` ` yaml
1213
- [...]
1214
1231
metadata:
1215
- name: my-service
1216
- annotations:
1217
- service.kubernetes.io/ibm-load-balancer-cloud-provider-ip-type: "private"
1218
- [...]
1232
+ name: my-service
1233
+ annotations:
1234
+ service.kubernetes.io/ibm-load-balancer-cloud-provider-ip-type: "private"
1219
1235
` ` `
1220
1236
1221
1237
{{% /tab %}}
1222
1238
{{% tab name="OpenStack" %}}
1223
1239
1224
1240
` ` ` yaml
1225
- [...]
1226
1241
metadata:
1227
- name: my-service
1228
- annotations:
1229
- service.beta.kubernetes.io/openstack-internal-load-balancer: "true"
1230
- [...]
1242
+ name: my-service
1243
+ annotations:
1244
+ service.beta.kubernetes.io/openstack-internal-load-balancer: "true"
1231
1245
` ` `
1232
1246
1233
1247
{{% /tab %}}
1234
1248
<!--Baidu Cloud-->
1235
1249
{{% tab name="百度云" %}}
1236
1250
1237
1251
` ` ` yaml
1238
- [...]
1239
1252
metadata:
1240
- name: my-service
1241
- annotations:
1242
- service.beta.kubernetes.io/cce-load-balancer-internal-vpc: "true"
1243
- [...]
1253
+ name: my-service
1254
+ annotations:
1255
+ service.beta.kubernetes.io/cce-load-balancer-internal-vpc: "true"
1244
1256
` ` `
1245
1257
1246
1258
{{% /tab %}}
1247
1259
<!--Tencent Cloud-->
1248
1260
{{% tab name="腾讯云" %}}
1249
1261
1250
1262
` ` ` yaml
1251
- [...]
1252
1263
metadata:
1253
1264
annotations:
1254
1265
service.kubernetes.io/qcloud-loadbalancer-internal-subnetid: subnet-xxxxx
1255
- [...]
1256
1266
` ` `
1257
1267
1258
1268
{{% /tab %}}
1259
1269
<!--Alibaba Cloud-->
1260
1270
{{% tab name="阿里云" %}}
1261
1271
1262
1272
` ` ` yaml
1263
- [...]
1264
1273
metadata:
1265
1274
annotations:
1266
1275
service.beta.kubernetes.io/alibaba-cloud-loadbalancer-address-type: "intranet"
1267
- [...]
1268
1276
` ` `
1269
1277
1270
1278
{{% /tab %}}
1271
1279
{{% tab name="OCI" %}}
1272
1280
1273
1281
` ` ` yaml
1274
- [...]
1275
1282
metadata:
1276
- name: my-service
1277
- annotations:
1278
- service.beta.kubernetes.io/oci-load-balancer-internal: true
1279
- [...]
1283
+ name: my-service
1284
+ annotations:
1285
+ service.beta.kubernetes.io/oci-load-balancer-internal: true
1280
1286
` ` `
1281
1287
{{% /tab %}}
1282
1288
{{< /tabs >}}
@@ -1310,11 +1316,14 @@ spec:
1310
1316
1311
1317
{{< note >}}
1312
1318
<!--
1313
- A Service of `type : ExternalName` accepts an IPv4 address string, but treats that string as a DNS name comprised of digits,
1314
- not as an IP address (the internet does not however allow such names in DNS). Services with external names that resemble IPv4
1319
+ A Service of `type : ExternalName` accepts an IPv4 address string,
1320
+ but treats that string as a DNS name comprised of digits,
1321
+ not as an IP address (the internet does not however allow such names in DNS).
1322
+ Services with external names that resemble IPv4
1315
1323
addresses are not resolved by DNS servers.
1316
1324
1317
- If you want to map a Service directly to a specific IP address, consider using [headless Services](#headless-services).
1325
+ If you want to map a Service directly to a specific IP address, consider using
1326
+ [headless Services](#headless-services).
1318
1327
-->
1319
1328
`type : ExternalName` 的服务接受 IPv4 地址字符串,但将该字符串视为由数字组成的 DNS 名称,
1320
1329
而不是 IP 地址(然而,互联网不允许在 DNS 中使用此类名称)。
@@ -1443,7 +1452,8 @@ finding a Service: environment variables and DNS.
1443
1452
When a Pod is run on a Node, the kubelet adds a set of environment variables
1444
1453
for each active Service. It adds `{SVCNAME}_SERVICE_HOST` and `{SVCNAME}_SERVICE_PORT` variables,
1445
1454
where the Service name is upper-cased and dashes are converted to underscores.
1446
- It also supports variables (see [makeLinkVariables](https://github.com/kubernetes/kubernetes/blob/dd2d12f6dc0e654c15d5db57a5f9f6ba61192726/pkg/kubelet/envvars/envvars.go#L72))
1455
+ It also supports variables
1456
+ (see [makeLinkVariables](https://github.com/kubernetes/kubernetes/blob/dd2d12f6dc0e654c15d5db57a5f9f6ba61192726/pkg/kubelet/envvars/envvars.go#L72))
1447
1457
that are compatible with Docker Engine's
1448
1458
" _[legacy container links](https://docs.docker.com/network/links/)_" feature.
1449
1459
@@ -1674,7 +1684,9 @@ Service 是 Kubernetes REST API 中的顶级资源。你可以找到有关
1674
1684
1675
1685
<!--
1676
1686
Learn more about Services and how they fit into Kubernetes :
1677
- * Follow the [Connecting Applications with Services](/docs/tutorials/services/connect-applications-service/) tutorial.
1687
+
1688
+ * Follow the [Connecting Applications with Services](/docs/tutorials/services/connect-applications-service/)
1689
+ tutorial.
1678
1690
* Read about [Ingress](/docs/concepts/services-networking/ingress/), which
1679
1691
exposes HTTP and HTTPS routes from outside the cluster to Services within
1680
1692
your cluster.
@@ -1691,6 +1703,7 @@ Learn more about Services and how they fit into Kubernetes:
1691
1703
1692
1704
<!--
1693
1705
For more context, read the following :
1706
+
1694
1707
* [Virtual IPs and Service Proxies](/docs/reference/networking/virtual-ips/)
1695
1708
* [EndpointSlices](/docs/concepts/services-networking/endpoint-slices/)
1696
1709
* [Service API reference](/docs/reference/kubernetes-api/service-resources/service-v1/)
@@ -1704,4 +1717,3 @@ For more context, read the following:
1704
1717
* [Service API 参考](/zh-cn/docs/reference/kubernetes-api/service-resources/service-v1/)
1705
1718
* [EndpointSlice API 参考](/zh-cn/docs/reference/kubernetes-api/service-resources/endpoint-slice-v1/)
1706
1719
* [Endpoints API 参考](/zh-cn/docs/reference/kubernetes-api/service-resources/endpoints-v1/)
1707
-
0 commit comments