Why the different service types are needed in Kubernetes
Different service types in Kubernetes serve different responsiblity on the deployment of the application and each has its own way of accessing the pods or the application ,
Service in a kubernetes is a very important concept as it is the only way of exposing our application to the other machine or people in the world, so what service is , what are its type and all , discussing about it in later on this artical so dont skip to without reading it all
Lets start with a problem first what problem does this service actually solves under the hood,
if we are running an application on the kubernetes as pod , pods are just like containers in nature but with some additional features , they are sort-lived and can be restarted or refreshed , so all the time as the pods keep replacing when something changes in deployment , everynew pod comes up with new ip address, so we can access our running applications inside the pods using its ip address as it gets changes along with ephemeral pods,
for the example:: we created two pods
pod A and pod B with respective ip address 123.34.32.1 and 12.23.45.56 , a user wants to access the app using 123.34.32.1 ip address , after sometime becouse of any reason that pod with ip address got crashed and replaced with new pod with new ip address, so when the user made request , he was getting error like service is not reacheble , at this movement service came into the picture to solve this problem , service provides us a stable networking endpoint through which we can easily access our pods, sevice forwards request to the pods and get the response back , these pods are the endpoint for the service we create so now we dont need to know the ip address of the pods , insteed just know the service provided endpoint or ip and access through that , but the same problem is here as well how service will be finding the pods becouse they may still be getting replaced this is what service discovery comes up to solve.
Service using the selector method finds the pods according to the labels assigned to it and this concept is called service discovery,
so now here its type comes in to disccuss
- Cluster ip type: it is a defualt service type , it only allows the user to access the pods inside its cluster private network not outside of it , it is kind of restriction is here, from outside network , you can not get the pods access
- NodePort type: in NodePort service type , our pods can be accessed using the node( the machine that is excuting all the operations under the hood like local machine of your laptop or remote servers ) ip address but only accesable inside our local network . how it works let me explain a little bit, when we create a NodePort service type and map a port with the port our containers inside the pods are listening at , this service a expose a port that we use with our node ip to make request and this port forward that request to the mapped port
- LoadBalancer type: in this type of service , it exposes our application to ouside world so it is genreally used at tha large scale for the users to access it, and we also then go to use some sorts of cloud providers to use load balancing for services ,
but here one more things comes into the picture is that if we use seperate and multiple laodbalancing for each service that would be costly so that is why ingress came into the picture to resolve this problem of multiple loadbalancing
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article