In Kubernetes, a Service is an abstraction which represents a logical set of Pods and a policy by which to access them.
Although each Pod has a unique IP address, those IPs are not exposed outside the cluster without a Service.
The point is that Pods in Kubernetes are “mortal” – every time a Pod dies for some reason, a new Pod is created in its place with a different IP address, so IP addresses of Pods cannot be called persistent and stable.
The idea of a Service is to group a set of Pod endpoints (back-end) into a single resource (front-end) with a persistent IP addresses that can be exposed in different ways depending on a ServiceType
.
In this note i will show how to list Services in Kubernetes using the kubectl
command and how to get detailed information about each Service in different formats.
Cool Tip: List & Change Namespaces in Kubernetes! Read more →
Get Kubernetes Services using Kubectl
List all Services:
$ kubectl get services
Show the particular Service:
$ kubectl get service <NAME>
Get the Service details:
$ kubectl describe services - or - $ kubectl describe service <NAME>
Get the Service details in YAML format:
$ kubectl get services -o yaml - or - $ kubectl get service <NAME> -o yaml
Cool Tip: List Nodes in Kubernetes cluster! Read more →
Types of Services
There are five types of Services in Kubernetes:
ServiceType | Description |
---|---|
ClusterIP | Exposes the Service on an internal IP, which can be accessed by other apps in the cluster, without allowing external access. This is the default ServiceType . |
NodePort | Exposes the Service on each Node’s IP at a static port (the NodePort ) in the range 30000-32768 , by default. A ClusterIP Service, to which the NodePort Service routes, is automatically created. You’ll be able to contact the NodePort Service, from outside the cluster, by requesting <NodeIP>:<NodePort> . |
LoadBalancer | Exposes the Service externally using a cloud provider’s load balancer. NodePort and ClusterIP Services, to which the external load balancer routes, are automatically created. |
ExternalName | Maps the Service to the contents of the externalName field (e.g. foo.bar.example.com ), by returning a CNAME record with its value. No proxying of any kind is set up. |
Headless | Sometimes you don’t need load-balancing and a single Service IP. In this case, you can create what are termed “headless” Services, by explicitly specifying "None" for the cluster IP (.spec.clusterIP ). |
Cool Tip: List Pods in Kubernetes cluster! Read more →