Kubernetes Difference between Service & Deployment

In K8s, both Service & Deployment seem to shelter a group of Pods with similar characteristics by providing an interface on top. So what’s the difference?

👉 A Deployment keeps a set of Pods running as specified by the user

If you want to run 5 Pods for your application, you can create & manage them by hand. But this is obviously inefficient. What if you need to scale out to 100 Pods tomorrow?
In a Deployment, you simply declare what you want and it takes care of creating, scaling & replacing Pods to meet the desired state.

👉 A Service allows network access to a set of Pods

Each Pod has its own IP address and can be reached by other apps over network. But if your application has 100 Pods, will you pass 100 IPs to the dependent microservices? When Pods get destroyed or replaced, will you refresh all IPs everywhere?
A service exposes a single, stable endpoint and load-balances incoming network requests amongst all your Pods, even when they keep fluctuating.

Examples:

1️⃣ If running a report generation app, you probably only need to use Deployment because no other microservices will make requests to your Pods.
2️⃣ If running a microservice (REST API), you probably need both - Deployment to manage the large cluster and Service for distributing network requests.

1 thought on “Kubernetes Difference between Service & Deployment”

Leave a Comment