Services are something that lets us contact our nodes or manage nodes , cluster etc.
For example, we have 3 type of services;
3) Load balancer
basically , assume your laptop and a node in cluster has same IP . But the pods have different IP. Thus you can not access the containers within the pods through your laptop.
Here comes nodeport which is a port on nodes, helping you connect to your pods networks and get the container .
Checkout these carefully:
The web server on the container is connected to port 80 which is Target Port. It is also connected to port of the service. again the service has its own clusterIP address 10.106.11.1.2
The service is also then connected to NodePort which is the point for your laptop to get connected with the containers.
So, why we gave these values , rights?
Check out this image
Now here is a thing. For a particular pod, we need to share the pod's labels . SO, that we can contact a particular pod.
So, we will use the labels from here under the selectors.
Now, lets do some hands on....
Now,and this is our service.yaml file to create a node port which has the same labels as the deployment file
- port: 80
Lets now run it in our terminal to create the service:
kubectl create -f service.yaml
Now check the services, using
kubectl get services
Now, as our cluster has 1 node and within the node, we have 6 pods or replicas. we just need to know the node IP . also we have the NodePort 30004. So, in our browser we need to go and follow this format "node IP : NodePort"
To connect frontend, back end and database, it is best to use clusterIP so that, each portion can contact with each other.
To create a clusterIP, follow this format
"Target port" is where the "back end" is exposed and "port" is where the service is exposed.
To select the back end pods, we will those their labels under the selector:
It is basically part of a voting system. So, you will let voters vote using one port 30035 and get the result of the votes on port 31061
Look carefully, as we have 4 nodes, now we will have 4 links for votes and thus 4 links for getting results:
But a voter does not want to see these 8 links. He/she just wants to have a link to vote and get result.
Load Balancer will do all of these for you. Taking traffic from nodes to website etc.
Basically some cloud service providers like GCP, AWS,Azure etc do provide this service .
So, that is it!