Kubernetes Service


Kubernetes Service is a service defines a logical set of Kubernetes Pods and a way to access them using an IP Address and port number pair.

Kubernetes Service enable a loose coupling between dependent Kubernetes Pods. A Kubernetes Service is defined using YAML (preferred) or JSON, like all Kubernetes objects. The set of Kubernetes Pods targeted by a Kubernetes Service is usually determined by a LabelSelector (see below for why you might want a Kubernetes Service without including selector in the spec).

Although each Kubernetes Pod has a unique IP Address, those IPs are not exposed outside the cluster without a Kubernetes Service. Kubernetes Service allow your applications to receive traffic. Kubernetes Service can be exposed in different ways by specifying a type in the ServiceSpec:

  • ClusterIP (default) - Exposes the Kubernetes Service on an internal IP Address in the cluster. This type makes the Kubernetes Service only reachable from within the cluster.
  • NodePort - Exposes the Service on the same port of each selected Node in the cluster using NAT. Makes a Service accessible from outside the cluster using <NodeIP>:<NodePort>. Superset of ClusterIP.
  • LoadBalancer - Creates an external load balancer in the current cloud (if supported) and assigns a fixed, external IP to the Kubernetes Service. Superset of NodePort.
  • ExternalName - Exposes the Kubernetes Service using an arbitrary NAME (specified by externalName in the spec) by returning a CNAME record with the name. No proxy is used. This type requires v1.7 or higher of kube-dns.

Kubernetes Service routes traffic across a set of Kubernetes Pods. Kubernetes Service are the abstraction that allow Kubernetes Pods to die and replicate in Kubernetes without impacting your application. Discovery and routing among dependent Pods (such as the frontend and backend components in an application) is handled by Kubernetes Services.

Kubernetes Services match a set of Kubernetes Pods using labels and selectors, a grouping primitive that allows logical operation on objects in Kubernetes. Labels are Key-value pairs attached to objects and can be used in any number of ways:

More Information#

There might be more information for this subject on one of the following: