Creating a deployment:
Let's say, we have a deployment that spawns one replica for an "nginx" pod:
Creating the service:
After creating the deployment that spawns our pod, we create a service "nginx-service", to be able to reach our pod through it:
We can then create the service using the below command:
Below is a diagram for the service and its endpoint:
The selector helps us "select" the labels, that way the service knows which pod labels its selector will "attach" to.
Checking our service:
We can check the creation of the service and whether it is pointing to the right pods by comparing the address of the endpoints of the service to the address of the pod.
We display the service using the below command:
We can then "describe" the service to be able to see more details:
We then get the address of our pod and check if it is similar to the endpoint's address our service "nginx-service" points to:
We could see that the address of the endpoint "172.16.0.2" is the same as the pod's address.