Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly Kubernetes Services are and how they are different from Deployments

Tags:

kubernetes

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.

like image 214
Qiulang 邱朗 Avatar asked Jul 05 '19 04:07

Qiulang 邱朗


People also ask

What is the difference between Kubernetes service and deployment?

What's the difference between a Service and a Deployment in Kubernetes? A deployment is responsible for keeping a set of pods running. A service is responsible for enabling network access to a set of pods. We could use a deployment without a service to keep a set of identical pods running in the Kubernetes cluster.

What are Kubernetes services?

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).

How service is deployed in Kubernetes?

A service can expose a Kubernetes deployment by offering a static IP in front of it, and instead of talking to the pods, you would talk to the service, which then routes the traffic to the pods. The internal DNS in a Kubernetes cluster even makes it possible to talk to a service using an FQDN instead of an IP.

What is POD deployment and service in Kubernetes?

A Kubernetes deployment provides a means of changing or modifying the state of a pod, which may be one or more containers that are running, or a group of duplicate pods, known as ReplicaSets. Using a deployment allows you to easily keep a group of identical pods running with a common configuration.


1 Answers

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.

like image 82
Malathi Avatar answered Sep 21 '22 18:09

Malathi