Kubernetes - Service
Last Updated: 2023-08-26
A Service
provides an unchanging IP, used between frontend deployment and backend deployment.
A Service
is responsible for enabling network access to a set of pods.
Each Service
gets a ClusterIP
allocated, one IP to get traffic to all the endpoints.
Service types:
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<NodeIP>:<NodePort>
LoadBalancer
: for services to be exposed to external world, using a cloud provider's load balancer.
ClusterIP
vs LoadBalancer
: LoadBalancer
has an external IP.
When you create a Service
, it creates a corresponding DNS entry.
Service
selects Pod
s by selector
:
selector:
app: http-echo
Headless Services: "None" for the cluster IP address .spec.clusterIP
.
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
EndpointSlice
s 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