Merge pull request #39499 from sftim/20230216_service_update_part_14
Revise Service concept, part 14
This commit is contained in:
commit
c67a986cf0
|
|
@ -71,14 +71,15 @@ balancer in between your application and the backend Pods.
|
||||||
|
|
||||||
## Defining a Service
|
## Defining a Service
|
||||||
|
|
||||||
A Service in Kubernetes is a REST object, similar to a Pod. Like all of the
|
A Service in Kubernetes is an
|
||||||
REST objects, you can `POST` a Service definition to the API server to create
|
{{< glossary_tooltip text="object" term_id="object" >}}
|
||||||
a new instance.
|
(the same way that a Pod or a ConfigMap is an object). You can create,
|
||||||
The name of a Service object must be a valid
|
view or modify Service definitions using the Kubernetes API. Usually
|
||||||
[RFC 1035 label name](/docs/concepts/overview/working-with-objects/names#rfc-1035-label-names).
|
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
|
For example, suppose you have a set of Pods that each listen on TCP port 9376
|
||||||
and contains a label `app.kubernetes.io/name=MyApp`:
|
and are labelled as `app.kubernetes.io/name=MyApp`. You can define a Service to
|
||||||
|
publish that TCP listener:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
|
|
@ -94,16 +95,20 @@ spec:
|
||||||
targetPort: 9376
|
targetPort: 9376
|
||||||
```
|
```
|
||||||
|
|
||||||
This specification creates a new Service object named "my-service", which
|
Applying this manifest creates a new Service named "my-service", which
|
||||||
targets TCP port 9376 on any Pod with the `app.kubernetes.io/name=MyApp` label.
|
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"),
|
Kubernetes assigns this Service an IP address (the _cluster IP_),
|
||||||
which is used by the Service proxies
|
that is used by the virtual IP address mechanism. For more details on that mechanism,
|
||||||
(see [Virtual IP addressing mechanism](#virtual-ip-addressing-mechanism) below).
|
read [Virtual IPs and Service Proxies](/docs/reference/networking/virtual-ips/).
|
||||||
|
|
||||||
|
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 >}}
|
{{< note >}}
|
||||||
A Service can map _any_ incoming `port` to a `targetPort`. By default and
|
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 are migrating a workload to Kubernetes. While evaluating the approach,
|
||||||
you run only a portion of your backends in Kubernetes.
|
you run only a portion of your backends in Kubernetes.
|
||||||
|
|
||||||
In any of these scenarios you can define a Service _without_ a Pod selector.
|
In any of these scenarios you can define a Service _without_ specifying a
|
||||||
For example:
|
selector to match Pods. For example:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
apiVersion: v1
|
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.
|
from being used as a proxy to endpoints the caller may not be authorized to access.
|
||||||
{{< /note >}}
|
{{< /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
|
selectors and uses DNS names instead. For more information, see the
|
||||||
[ExternalName](#externalname) section later in this document.
|
[ExternalName](#externalname) section.
|
||||||
|
|
||||||
### EndpointSlices
|
### 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.
|
and internal traffic to your endpoints.
|
||||||
|
|
||||||
To set an internal load balancer, add one of the following annotations to your Service
|
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" >}}
|
{{< tabs name="service_tabs" >}}
|
||||||
{{% tab name="Default" %}}
|
{{% tab name="Default" %}}
|
||||||
|
|
@ -1151,9 +1156,9 @@ spec:
|
||||||
- name: http
|
- name: http
|
||||||
protocol: TCP
|
protocol: TCP
|
||||||
port: 80
|
port: 80
|
||||||
targetPort: 9376
|
targetPort: 49152
|
||||||
externalIPs:
|
externalIPs:
|
||||||
- 80.11.12.10
|
- 198.51.100.32
|
||||||
```
|
```
|
||||||
|
|
||||||
## Session stickiness
|
## Session stickiness
|
||||||
|
|
@ -1178,13 +1183,17 @@ mechanism Kubernetes provides to expose a Service with a virtual IP address.
|
||||||
|
|
||||||
## {{% heading "whatsnext" %}}
|
## {{% heading "whatsnext" %}}
|
||||||
|
|
||||||
Learn more about the following:
|
Learn more about Services and how they fit into Kubernetes:
|
||||||
* Follow the [Connecting Applications with Services](/docs/tutorials/services/connect-applications-service/) tutorial
|
* 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.
|
* Read about [Ingress](/docs/concepts/services-networking/ingress/), which
|
||||||
* [EndpointSlices](/docs/concepts/services-networking/endpoint-slices/)
|
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 the following:
|
||||||
* [Virtual IPs and Service Proxies](/docs/reference/networking/virtual-ips/)
|
* [Virtual IPs and Service Proxies](/docs/reference/networking/virtual-ips/)
|
||||||
* [API reference](/docs/reference/kubernetes-api/service-resources/service-v1/) for the Service API
|
* [EndpointSlices](/docs/concepts/services-networking/endpoint-slices/)
|
||||||
* [API reference](/docs/reference/kubernetes-api/service-resources/endpoints-v1/) for the Endpoints API
|
* [Service API reference](/docs/reference/kubernetes-api/service-resources/service-v1/)
|
||||||
* [API reference](/docs/reference/kubernetes-api/service-resources/endpoint-slice-v1/) for the EndpointSlice API
|
* [EndpointSlice API reference](/docs/reference/kubernetes-api/service-resources/endpoint-slice-v1/)
|
||||||
|
* [Endpoint API reference (legacy)](/docs/reference/kubernetes-api/service-resources/endpoints-v1/)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue