Get replica set of the deployment
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
In Kubernetes, a Deployment is a critical resource object that provides declarative updates for Pods and ReplicaSets. Understanding how to retrieve and manage the replica set of a Deployment is essential for maintaining application availability and reliability within a cluster. This article explores the technical underpinnings of how Deployments and their associated ReplicaSets function and demonstrates how to get and manage these ReplicaSets.
Understanding Deployments and ReplicaSets
Deployments in Kubernetes allow users to define applications in a declarative manner, specifying configurations, desired state, and policies for rolling updates. They are pivotal for managing stateless applications. The Deployment controller handles updates concerning these deployments automatically.
ReplicaSets are a mechanism to maintain a stable set of replica Pods running at any given time. They ensure the specified number of replicas for a Pod is maintained, replacing any that fail or are deleted.
Relationship Between Deployments and ReplicaSets
When a Deployment is created, it generates and manages a ReplicaSet. The ReplicaSet, in turn, manages the Pods. Each update to the Deployment (like adding new labels, updating container images, etc.) creates a new ReplicaSet pointing to the new specification, while the old ReplicaSet may or may not be scaled down depending on the update strategy.
Accessing the ReplicaSet of a Deployment
Finding the ReplicaSet related to a Deployment involves understanding and querying the Kubernetes API or using kubectl command-line tool. The process involves retrieving the Deployment, checking its metadata, and retrieving associated ReplicaSets.
Prerequisites
- Kubernetes cluster access.
- `kubectl` command-line tool installed and configured.
Step-by-Step Guide to Retrieve ReplicaSet
- Retrieve the Deployment: To list the Deployments in the default namespace, use:
- Scaling a Deployment: Modifying the number of replicas in the Deployment causes the associated ReplicaSet to scale accordingly.
- Rolling Updates: Deployments manage rolling updates to pods automatically, creating new ReplicaSets for revisions.
- Rollback: Kubernetes allows you to roll back to previous versions by reverting to earlier ReplicaSets.
Related reading
- Get Service selectors with K8s Python client
- Get the image and SHA image ID of images in pod on Kubernetes deployment
- get vs. list in Kubernetes RBAC
- Get YAML for deployed Kubernetes services?
- Getting Broker may not be available error when spring boot container tries to connect kafka container
- Getting ErrImageNeverPull in pods
- Get total and free disk space using Prometheus
- Getting Spring Boot color console logging working within Intellij?

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.