Services:

A pod is the smallest unit of kubernetes, it serves as a wrapper around one or more containers.

In the diagram below, a pod is "wrapped around" one container.


A pod has and IP_address and a port on which the application running in the container is listening.

Because pods crash and get recreated with new IP address, we need a way to keep track of all these changes of IPs.

Kubernetes has way to provides a single point of entry to a group of similar pods, so we don't have to keep track of all the IP changes, it is called a service.

The clients send the requests to this service (with fixed IP and port) which then forwards the request to one of the pod replicas.

Services offer an IP address and a port through which we can access to a group of pods.


Remark:

A service can have more than one port, each port on the service forwards requests to a specific application port inside the pod.

More than one application running in a Pod:


We have two applications inside the pod (web server and a Dabatase) that offer services on two different ports, port: 80 for the Webserver and port: 3000 for the database.

The service we create for these pods need to have two ports, one port that forwards the requests to the Webserver on port 80 and the other port to forward the requests to the database on port 3000

YAML file for a Cluster IP service with two ports:


When we have more than one port open on a service, we have to name the ports, for example (Web_port and DB_Port).

Requests arriving on port 2050 get forwarded to the application on port: 80 (Webserver) and requests arriving on port 3050 get forwarded to the application on port: 3000 (Database).

 

Brando Sabatini and Ikbal C ©. Powered by Blogger.