Kubernetes - Service
Service provides an unchanging IP, used between frontend deployment and backend deployment.
Service is responsible for enabling network access to a set of pods.
Service gets a
ClusterIP allocated, one IP to get traffic to all the endpoints.
ClusterIP: for testing; cluster scoped IP, used internally, the service is not exposed to resources outside the cluster. Workload can be accessed by a node ip + port, e.g. http://192.168.126.8:32768.
NodePort: for services within the cluster; maps a node port to a service; can be accessed from outside the cluster by requesting
LoadBalancer: for services to be exposed to external world, using a cloud provider's load balancer.
LoadBalancer has an external IP.
When you create a
Service, it creates a corresponding DNS entry.
selector: app: http-echo
Headless Services: "None" for the cluster IP address
For headless Services, a cluster IP is not allocated, kube-proxy does not handle these Services, and there is no load balancing or proxying done by the platform for them.
DNS is configured depends on either
- selectors, the endpoints controller creates
EndpointSlices and modifies the DNS configuration to return A or AAAA records (IPv4 or IPv6 addresses) that point directly to the Pods backing the Service.
- without selectors: https://kubernetes.io/docs/concepts/services-networking/service/#without-selectors