Senior
What is a Service in Kubernetes and how is it implemented?
sobes.tech AI
Answer from AI
In Kubernetes, a Service is an abstraction that defines a logical set of pods and a policy by which to access them. Service provides a stable IP address and DNS name for a group of pods, allowing clients to reach them regardless of changes in the pods (such as scaling or restarting).
Implementation:
- Service creates a virtual IP (ClusterIP) within the cluster.
- Uses selectors (labels) to determine which pods are part of the service.
- Inside the cluster, traffic to the Service is redirected to one of the pods using kube-proxy, which implements load balancing via iptables or IPVS.
Types of Service:
- ClusterIP (default) — accessible within the cluster.
- NodePort — opens a port on each node for external access.
- LoadBalancer — integrates with an external load balancer.
- ExternalName — redirects to an external DNS.
Thus, Service provides a stable and convenient way to access dynamically changing sets of pods.