Debug School


Posted on

Services Resources in K8s

Basically Services means the Network load balancer.

There will be a problem like if some one has to call the rest call where inside the POD its running in that case he needs the ipaddress and POrt.

But these ip address keeps on changing when the pod fone k8s will create one more pod with different ip.

In this case we have the use the Services Basically this will works based on the labels

" POd label should match with the services selector label " then those Services provides one of the ip with that ip we can access that "

like --type=clusterIp : kubectl expose rs nagendrareplica --port=1234 --target-port=80

There are three types:

  1. Clusterip : We can use this cluster ip to access tha application inside the cluster with the port not outside of it

  2. --type=nodeport : This one will do the cluster ip step and also opens the node port which can be accessible by outside
    root@ip-172-31-46-170:/home/ubuntu/nagendra# kubectl expose rs nagendrareplica --port=1234 --target-port=80 --type=NodePort -n=nagendra
    service/nagendrareplica exposed

From Clusterip with port we can access inside the cluster
From nodeip where services is running with the port given by node port we can access outside whcih will redirect that traffic into the correspoding application

  1. type=--loadbalancer : This will create the loadbalancer ip and the node port. Here k8s not able to create the loadbalancer thats why its coming as pending --type=LoadBalancer : ubectl expose rs nagendrareplica --port=1234 --target-port=80 --type=LoadBalancer -n=nagendra servicel1 LoadBalancer 1234:30649/TCP 5s

Workflow like : f user do the curl of ( which was added in DNS mapping there we have to mention the loadbalancerip and node port)

Then the request goes to the loadbalancer ip to the one of the node and that corresponding nodeport and then it redirected that info to the 80 port and gives the result

Note : There is a problem like if there are too many services resources like if its 100 then it has to create 100 loadbalancer which is costlier.

Exapmples :

root@ip-172-31-46-170:/home/ubuntu/nagendra# kubectl get services -n=nagendra
nag-cs ClusterIP 5678/TCP 66m
nagendrareplica NodePort 1234:30710/TCP 25s
nagendrareplicav2 ClusterIP 80/TCP 56m

Top comments (0)