Skip to content

Demo preview. Courses, instructors, reviews and prices are sample content. Payments are simulated.

XOps, home

Pods, Deployments and Services: How They Fit Together

Three Kubernetes objects cause most early confusion. Here is what each one is responsible for and how they work together to run an application.

Priya Nair · 7 min readSample article
Abstract illustration of connected cluster nodes

When you first deploy an application to Kubernetes, you meet Pods, Deployments and Services almost at once. They are easy to mix up because each one seems to “run the app”. In fact, each has a narrow job.

A Pod runs containers

A Pod is the smallest unit Kubernetes schedules. It wraps one or more containers that share a network address and storage. Pods are disposable: if a node fails, its Pods are gone, and nothing brings them back on its own.

A Deployment keeps Pods running

A Deployment describes the Pods you want, for example three copies of version 2 of your image. Kubernetes continuously compares that desired state with what is running and creates or removes Pods to match. Updates happen as rolling changes, so a new version replaces the old one gradually.

yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
spec:
  replicas: 3
  selector:
    matchLabels: { app: web }
  template:
    metadata:
      labels: { app: web }
    spec:
      containers:
        - name: web
          image: example/web:2.0.0
          ports:
            - containerPort: 8080

A Service gives Pods a stable address

Pods come and go, and their IP addresses change. A Service selects Pods by label and gives them one stable name and address inside the cluster. Traffic sent to the Service is spread across whichever matching Pods are healthy at that moment.

  • Pod: runs your containers, and is replaceable.
  • Deployment: keeps the right number of Pods at the right version.
  • Service: lets other workloads reach those Pods by a stable name.
  • Kubernetes
  • Containers