Kubernetes - can a Deployment have multiple ReplicaSets?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Kubernetes is a powerful open-source platform designed to automate the deployment, scaling, and operation of application containers. It groups containers that make up an application into logical units for easy management and discovery. One of the key constructs for managing containerized applications in Kubernetes is the Deployment. In this article, we explore the relationship between Deployments and ReplicaSets, answering the question: can a Deployment have multiple ReplicaSets?
Understanding Deployments and ReplicaSets
What is a Deployment?
A Deployment in Kubernetes provides declarative updates to applications, meaning you can describe the desired state of your application, and the Deployment controller will change the actual state to the desired state at a controlled rate. Deployments are useful for:
- Rolling out updates to applications.
- Rolling back changes if an update fails.
- Scaling applications up or down.
- Pausing and resuming the rolling out of updates.
What is a ReplicaSet?
A ReplicaSet, while similar to a Deployment, is focused on ensuring a specified number of pod replicas are running at any one time. However, a ReplicaSet alone doesn't offer sophistication in managing updates or rolls back features that are provided by Deployments.
The primary role of ReplicaSets is to maintain a stable set of replica Pods running at any time.
The Relationship Between Deployments and ReplicaSets
In Kubernetes, Deployments are typically used to manage ReplicaSets, which in turn manage Pods. When you create or update a Deployment, it will create or update the ReplicaSets. This is where the question arises: Can a Deployment have multiple ReplicaSets at any given time?
Can a Deployment Have Multiple ReplicaSets?
Yes, a Deployment can manage multiple ReplicaSets. This occurs primarily during rolling updates when transitioning from one version of an application to another. Here's how:
- Initial Creation: When a Deployment is first created, it will create a new ReplicaSet to manage the required Pods.
- Scaling: If you scale the Deployment, it will adjust the number of replicas managed by the existing ReplicaSet.
- Rolling Updates:
- When a Deployment is updated, such as deploying a new version of an application, Kubernetes creates a new ReplicaSet.
- The new ReplicaSet gradually takes over the traffic from the old ReplicaSet. During this process, both the new and old ReplicaSets may co-exist to facilitate a smooth transition.
- The old ReplicaSet is scaled down while the new ReplicaSet is scaled up.
- Rollback Scenarios: If an update fails and a rollback is initiated, the old ReplicaSet might be scaled back up while the problematic new ReplicaSet is scaled down.
Example
Consider a scenario where you have a Deployment managing an application with the following configuration:
- Initial version: `v1` running with `ReplicaSet-1`
- Updated version: `v2` initiates `ReplicaSet-2`
During the rolling update process:
- name: my-app
- name: my-app
Related reading
- Kubernetes - Can't connect to a service IP from the service's pod
- Kubernetes - Container image already present on machine
- Kubernetes - delete all jobs in bulk
- Kubernetes - deployment initialization - how to ensure it happens only once?
- Kubernetes - force pod restart if container fails to re-trigger init containers
- kubernetes - kubectl run vs create and apply
- Kubernetes - How to access nginx load balancing from outside the cluster using a NodePort service
- Kubernetes - How to define ConfigMap built using a file in a yaml?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.