Kubernetes Service Concepts: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 29: Line 29:


=Service=
=Service=
In its simplest form, a service provides a stable cluster IP address and exposes a set of ports that internal Kubernetes cluster clients (other pods) can use to connect to the pods served by the service. This type of service is know as a "" service, but explicitly designating it as such is optional. If


<font color=darkgray>Is is ClusterIP by default?</font>
<font color=darkgray>Is is ClusterIP by default?</font>

Revision as of 21:27, 19 September 2020

External

Internal

Playground

https://github.com/ovidiuf/playground/tree/master/kubernetes/httpd-pod-and-service

Overview

A service is a Kubernetes resource that provides stable network access to a set of ephemeral pods. The need for such a resource is explained in the Need for Services section.

Need for Services

Most pods exist to serve requests sent over the network, so the pods' clients need to know how to open a network connection into the pod - they need an IP address and a port. This is true for clients external to the Kubernetes cluster, and also for pods running inside the cluster, which act as clients for other pods.

However, the pods are ephemeral, they come and go. If a pod fails, it is not resurrected, but its failure is detected as result of lack of response from the liveness probe embedded within it and another pod is usually scheduled as replacement. The pod does not need to fail to be removed, the removal can be the result of a normal scale-down operation. In consequence, the IP address of an individual pod cannot be relied on.

First off, the IP address is dynamically allocated to the pod at the time of pod initialization, after the pod has been scheduled to a node and before the pod is started, and secondly, the IP address becomes obsolete the moment the pod disappears. As such, it is practically very difficult, if not impossible for application's clients running outside the Kubernetes cluster, or even for other pods acting as clients to keep track of ephemeral pod IP addresses.

Multiple pods may be providing the same service, and each of them has its own IP address, and it is not the client's job to choose a specific pod.

The solution to all these problems is maintain an instance of a specialized resource, the service, for each of such group of pods. The service instance exposes a stable IP address and set of ports for the life of the service instance.

Service

In its simplest form, a service provides a stable cluster IP address and exposes a set of ports that internal Kubernetes cluster clients (other pods) can use to connect to the pods served by the service. This type of service is know as a "" service, but explicitly designating it as such is optional. If

Is is ClusterIP by default?

Service Manifest

Service Manifest

Associating a Service with Pods

Manifest Syntax

Endpoints

Readiness Probe

Discovering Services inside the Cluster

Exposing Services to External Clients

Connecting to External Services from inside the Cluster

Kubernetes Service Concepts TODEPLETE