xxxxxxxxxx
A Kubernetes service is a logical abstraction for a deployed group of pods
in a cluster (which all perform the same function). Since pods are
ephemeral, a service enables a group of pods, which provide specific
functions (web services, image processing, etc.) to be assigned a name
and unique IP address (clusterIP).
xxxxxxxxxx
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: MyApp
ports:
- protocol: TCP
port: 80
targetPort: 9376
In Kubernetes, a Service is an abstraction that defines a logical set of Pods and a policy by which to access them, this kind of patterns is also sometimes called a micro-service.
If you are from a programming background and have been an API developer you must be familiar with the term REST object, services in k8s is quite similar to this REST object.
One can POST a Service definition to the API server to create a new instance.
The name of a Service object must be a valid DNS label name.
Each pod in the Kubernetes cluster has got the cluster IP and Network IP, but these pods cannot be directly accessed externally as those IPs are not exposed outside the cluster without a Service.
Kubernetes services allow our applications to be exposed to receive external world traffic, and also helps these pods lying in the node cluster to communicate with each other internally.