- What is a K8s service ?
- A service is a K8s object that is used to loadbalance or make the pod available from the service endpoint (ClusterIP service), Node endpoint (NodePort service) or Outside the cluster (LoadBalancer service).
- Why do we need it ?
- We need services as there can be different requirements for availabilities of pods. Some may want to access the pod, so ClusterIP is created to loadbalance the pods, hence application is available through the ClusterIP. Through NodePort service, we can access the application by just hitting the nodeIP. Through LoadBalancer, we don't have to worry about what node to choose for connection to application, we can just use the ip/dns name for LoadBalancer and it will internally select the node.
- How it works/commands ?
- Service has a field called Selector, in that whatever labels we specify that should be the same labels present in the pod. If the labels are same, the endpoint in the service will be assigned with the IP of the pods.
To view the Selectors and Endpoint -> kubectl describe svc my-svc -n my-ns
To edit the service file and changes the Selector -> kubectl edit svc my-svc -n my-ns
Top comments (0)