From 98c7d48a11cef127f57b1b365313b658e134fddc Mon Sep 17 00:00:00 2001 From: Tim Bannister Date: Thu, 16 Feb 2023 19:35:00 +0000 Subject: [PATCH] Revise Service concept Co-authored-by: Shannon Kularathna --- .../concepts/services-networking/service.md | 69 +++++++++++-------- 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/content/en/docs/concepts/services-networking/service.md b/content/en/docs/concepts/services-networking/service.md index 9037f466286eb..5096598e90937 100644 --- a/content/en/docs/concepts/services-networking/service.md +++ b/content/en/docs/concepts/services-networking/service.md @@ -71,14 +71,15 @@ balancer in between your application and the backend Pods. ## Defining a Service -A Service in Kubernetes is a REST object, similar to a Pod. Like all of the -REST objects, you can `POST` a Service definition to the API server to create -a new instance. -The name of a Service object must be a valid -[RFC 1035 label name](/docs/concepts/overview/working-with-objects/names#rfc-1035-label-names). +A Service in Kubernetes is an +{{< glossary_tooltip text="object" term_id="object" >}} +(the same way that a Pod or a ConfigMap is an object). You can create, +view or modify Service definitions using the Kubernetes API. Usually +you use a tool such as `kubectl` to make those API calls for you. -For example, suppose you have a set of Pods where each listens on TCP port 9376 -and contains a label `app.kubernetes.io/name=MyApp`: +For example, suppose you have a set of Pods that each listen on TCP port 9376 +and are labelled as `app.kubernetes.io/name=MyApp`. You can define a Service to +publish that TCP listener: ```yaml apiVersion: v1 @@ -94,16 +95,20 @@ spec: targetPort: 9376 ``` -This specification creates a new Service object named "my-service", which -targets TCP port 9376 on any Pod with the `app.kubernetes.io/name=MyApp` label. +That manifest creates a new Service named "my-service", which +targets TCP port 9376 on any Pod with the `app.kubernetes.io/name: MyApp` label. + +Kubernetes assigns this Service an IP address (sometimes called the _cluster IP_) +which is used by the virtual IP address mechanism. For more details on that mechanism, +read [Virtual IPs and Service Proxies](/docs/reference/networking/virtual-ips/). -Kubernetes assigns this Service an IP address (sometimes called the "cluster IP"), -which is used by the Service proxies -(see [Virtual IP addressing mechanism](#virtual-ip-addressing-mechanism) below). +The controller for that Service continuously scans for Pods that +match its selector, and then makes any necessary updates to the set of +EndpointSlices for the Service. + +The name of a Service object must be a valid +[RFC 1035 label name](/docs/concepts/overview/working-with-objects/names#rfc-1035-label-names). -The controller for the Service selector continuously scans for Pods that -match its selector, and then POSTs any updates to an Endpoint object -also named "my-service". {{< note >}} A Service can map _any_ incoming `port` to a `targetPort`. By default and @@ -177,8 +182,8 @@ For example: * You are migrating a workload to Kubernetes. While evaluating the approach, you run only a portion of your backends in Kubernetes. -In any of these scenarios you can define a Service _without_ a Pod selector. -For example: +In any of these scenarios you can define a Service _without_ specifying a +selector to match Pods. For example: ```yaml apiVersion: v1 @@ -262,9 +267,9 @@ selector will fail due to this constraint. This prevents the Kubernetes API serv from being used as a proxy to endpoints the caller may not be authorized to access. {{< /note >}} -An ExternalName Service is a special case of Service that does not have +An `ExternalName` Service is a special case of Service that does not have selectors and uses DNS names instead. For more information, see the -[ExternalName](#externalname) section later in this document. +[ExternalName](#externalname) section. ### EndpointSlices @@ -704,7 +709,7 @@ In a split-horizon DNS environment you would need two Services to be able to rou and internal traffic to your endpoints. To set an internal load balancer, add one of the following annotations to your Service -depending on the cloud Service provider you're using. +depending on the cloud service provider you're using: {{< tabs name="service_tabs" >}} {{% tab name="Default" %}} @@ -1151,9 +1156,9 @@ spec: - name: http protocol: TCP port: 80 - targetPort: 9376 + targetPort: 49152 externalIPs: - - 80.11.12.10 + - 198.51.100.32 ``` ## Session stickiness @@ -1178,13 +1183,17 @@ mechanism Kubernetes provides to expose a Service with a virtual IP address. ## {{% heading "whatsnext" %}} -Learn more about the following: -* Follow the [Connecting Applications with Services](/docs/tutorials/services/connect-applications-service/) tutorial -* [Ingress](/docs/concepts/services-networking/ingress/) exposes HTTP and HTTPS routes from outside the cluster to services within the cluster. -* [EndpointSlices](/docs/concepts/services-networking/endpoint-slices/) +Learn more about Services and how they fit into Kubernetes: +* Follow the [Connecting Applications with Services](/docs/tutorials/services/connect-applications-service/) tutorial. +* Read about [Ingress](/docs/concepts/services-networking/ingress/), which + exposes HTTP and HTTPS routes from outside the cluster to Services within + your cluster. +* Read about [Gateway](https://gateway-api.sigs.k8s.io/), an extension to + Kubernetes that provides more flexibility than Ingress. -For more context: +For more context, read: * [Virtual IPs and Service Proxies](/docs/reference/networking/virtual-ips/) -* [API reference](/docs/reference/kubernetes-api/service-resources/service-v1/) for the Service API -* [API reference](/docs/reference/kubernetes-api/service-resources/endpoints-v1/) for the Endpoints API -* [API reference](/docs/reference/kubernetes-api/service-resources/endpoint-slice-v1/) for the EndpointSlice API +* [EndpointSlices](/docs/concepts/services-networking/endpoint-slices/) +* [Service API reference](/docs/reference/kubernetes-api/service-resources/service-v1/) +* [EndpointSlice API reference](/docs/reference/kubernetes-api/service-resources/endpoint-slice-v1/) +* [Endpoint API reference (legacy)](/docs/reference/kubernetes-api/service-resources/endpoints-v1/)