Kubernetes : Services



When pods get deployed, they get assigned an IP address. If they crash and get re-deployed, they get assigned a different IP address.


We could also have multiple pods handling a single application.
To have a fixed IP address representing all these pods, we use services.
A service represents a fixed IP address through which we could have access to a group of pods.
Services also function as load-balancers directing requests to the appropriate pod or pods.

Deployments:

A deployment is a kubernetes object that provides an easy way to declare pods and to update them using a Yaml file as below:


The above Yaml file will deploy two nginx pods. We could list them using their labels with the below command:


For client applications to access the nginx pods, they go through the below service:


The targetPort is the port the service uses to connect to the pods it represents.
We could check the services using the below command:


We could also check the endpoints of the service, which are the IP addresses the service uses to communicate with its pods:

Comments

Leave as a comment:

Archive