Skip to content
tezvyn:

Kubernetes Deployment: Declarative App Updates

Source: kubernetes.ioMediumHow cards are made

Kubernetes Deployment: Declarative App Updates

A Kubernetes Deployment is your app's blueprint. You declare the desired state—like '3 replicas of image v2'—and Kubernetes makes it happen. It's the standard for stateless apps like APIs. The footgun: don't manage Pods directly; manage the Deployment.

Why it exists

Manually managing application lifecycles across many servers is complex and error-prone. You need a reliable, automated way to roll out updates, scale up or down, and recover from failures without downtime. Deployments solve this by abstracting away the low-level details of managing individual application instances (Pods).

The mental model

Think of a Deployment as the manager of a team of identical workers (Pods). You give the manager a goal: 'I need 5 workers running version 1.2 of our software.' The manager ensures that's always the case. If a worker gets sick and crashes, the manager replaces them automatically. If you change the goal to 'I need 10 workers running version 1.3,' the manager handles hiring the new workers and retiring the old ones gracefully, ensuring the work continues uninterrupted.

How it works

A Deployment is a Kubernetes object that declaratively defines a desired state for your application. This includes the container image, the number of replicas, and the update strategy. When you create a Deployment, it creates a child object called a ReplicaSet. The ReplicaSet's job is to ensure the specified number of Pods are always running. When you update the Deployment (e.g., by changing the container image tag), it creates a new ReplicaSet and performs a rolling update. It gradually terminates Pods from the old ReplicaSet while creating Pods in the new one, allowing for zero-downtime rollouts.

When to use it

Use Deployments for stateless applications where any Pod is interchangeable and can handle any request. This is the most common workload type in Kubernetes. Good examples include REST APIs, web frontends, and background processing workers that pull from a queue.

When not to use it

Do not use Deployments for stateful applications that require stable, unique network identifiers and persistent storage tied to each instance. For those, use a StatefulSet (e.g., for databases like Zookeeper or etcd). For tasks that run to completion, use a Job or CronJob. To run a Pod on every node in the cluster, use a DaemonSet.

One canonical example

A team wants to run their stateless web application with three instances for high availability. They create a Deployment manifest specifying replicas: 3 and the container image webapp:v1. Kubernetes ensures three Pods are running. To release a new version, they update the Deployment's image to webapp:v2. The Deployment controller then, one by one, terminates an old Pod and creates a new one until all three are running v2, with no service interruption.

Interview question

For which application scenario is a Kubernetes Deployment the most suitable choice?

  • a.A background task designed to run to completion once or on a schedule.
  • b.A database that requires unique network identifiers and persistent storage per instance.
  • c.A system-level agent that needs to be present and running on every node in the cluster.
  • d.A web frontend where any Pod can serve any user request and data is not stored locally.Correct
Why?

The card specifies that Deployments are ideal for "stateless applications where any Pod is interchangeable and can handle any request," such as web frontends. The other options describe use cases for StatefulSets, Jobs/CronJobs, and DaemonSets, respectively, which are explicitly mentioned as scenarios where Deployments are not suitable.

Just read this? Test yourself on what you have been reading.

Read the original → kubernetes.io

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on kubernetes — each one lists the topics its interview covers.

See open roles