Kubernetes 101 : Internal and eternal services, pods and labels
Pods crash and get redeployed or they get moved to other hosts, during this process their IP address changes.
How do pods for example keep track of these changes to be able to continue communicating with each other.
Services give a solution to that problem.
Role of services:
Services are kubernetes objects that serve as a link or access point to a group of pods.
The service has an fixed IP address and a port. The client of the pods doesn't have to know the location or the number of the pods that offer a certain functionality. It connects to the service and its request get routed to the right pod.
Internal or external services:
We can have service that caters to the external clients. Clients can connect to the pods, using the IP address and the port of the service.
Pods can also use an internal service with a fixed IP address to communicate among themselves (Cluster IP service).
Pods, labels and services:
Each pod has a label which is used to determine which pods "belong" to a certain service.
When it receives a request a service forward the request to a pod in the group a pods (member of a pod group have the same label, DB in the diagram below).Service YAML file:The service "Service name" routes incoming requests on port:80 to port:8080 on the pods.
app: Pod_label (DB in the above diagram)
To create the service we use the below which has as an argument the YAML file:
On creation the service is assigned an IP address that is valid as long as the service is not destroyed.