Kubernetes 101 : Deployments, replicaSets, services, pods and endpoints



Creating a deployment:

Let's say, we have a deployment that spawns one replica for an "nginx" pod:


Below is the Yaml file of the deployment:


We can then use the below command to create our deployment:


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:


Below is the Yaml file of the service:


We can then create the service using the below command:


Below is a diagram for the service and its endpoint:


Remark:

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.

Comments

Leave as a comment:

Archive