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.
  • 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 Pods by 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