19

After reading thru Kubernetes documents like this, deployment , service and this I still do not have a clear idea what the purpose of service is.

It seems that the service is used for 2 purposes:

  1. expose the deployment to the outside world (e.g using LoadBalancer),
  2. expose one deployment to another deployment (e.g. using ClusterIP services).

Is this the case? And what about the Ingress?

------ update ------

Connect a Front End to a Back End Using a Service is a good example of the service working with the deployment.

Qiulang
  • 10,295
  • 11
  • 80
  • 129
  • 1
    Deployment is one of the Controllers - to manage pods / containers - scale up, down, start, stop, replicas etc. Service is Load Balancer - to manage connectivity between the pods (ClusterIP) and outside world (Load Balancer, NodePort) – Prakash Krishna Jul 05 '19 at 04:26
  • So we are on the same page. – Qiulang Jul 05 '19 at 04:29

1 Answers1

13

Service

A deployment consists of one or more pods and replicas of pods. Let's say, we have 3 replicas of pods running in a deployment. Now let's assume there is no service. How does other pods in the cluster access these pods? Through IP addresses of these pods. What happens if we say one of the pods goes down. Kunernetes bring up another pod. Now the IP address list of these pods changes and all the other pods need to keep track of the same. The same is the case when there is auto scaling enabled. The number of the pods increases or decreases based on demand. To avoid this problem services come into play. Thus services are basically programs that manages the list of the pods ip for a deployment.

And yes, also regarding the uses that you posted in the question.

Ingress

Ingress is something that is used for providing a single point of entry for the various services in your cluster. Let's take a simple scenario. In your cluster there are two services. One for the web app and another for documentation service. If you are using services alone and not ingress, you need to maintain two load balancers. This might cost more as well. To avoid this, ingress when defined, sits on top of services and routes to services based on the rules and path defined in the ingress.

Malathi
  • 2,119
  • 15
  • 40
  • the nested scheme is like this: e.g. 3 pods are exposed into a service. 2 pods in another service and on top of these services there is ingress that load balances traffic. correct? – ERJAN Jan 27 '22 at 05:41