Key Concepts
ReplicaSet
A controller that maintains a stable set of replica pods running at any time.
Selector
Label selector that identifies which pods belong to the ReplicaSet.
Replicas
The desired number of pod instances to maintain.
Owner Reference
Link to the parent controller (usually a Deployment) that manages the ReplicaSet.
Required Permissions
| Action | Permission |
|---|---|
| View replicasets | iam:project:infrastructure:kubernetes:read |
| Scale replicaset | iam:project:infrastructure:kubernetes:write |
| Create replicaset | iam:project:infrastructure:kubernetes:write |
| Edit replicaset | iam:project:infrastructure:kubernetes:write |
| Delete replicaset | iam:project:infrastructure:kubernetes:delete |
ReplicaSet Status Values
| Status | Description |
|---|---|
| Running | All desired replicas are ready |
| NotReady | Some replicas are not ready yet |
| Scaled to 0 | ReplicaSet has zero replicas |
| Unknown | Status cannot be determined |
ReplicaSet Metrics
| Metric | Description |
|---|---|
| Replicas | Desired number of pods |
| Ready | Pods that are ready (ready/desired) |
| Available | Pods available for service |
| Fully Labeled | Pods with all expected labels |
How to View ReplicaSets
The “Controlled By” column shows the parent resource (usually a Deployment) that manages each ReplicaSet.
How to View ReplicaSet Details
How to Scale a ReplicaSet
How to Create a ReplicaSet
How to Edit a ReplicaSet
Modify Spec
Edit the ReplicaSet specification. Common changes:
- Replica count
- Pod template (triggers pod replacement)
- Labels and annotations
How to Delete a ReplicaSet
ReplicaSets vs Deployments
| Feature | ReplicaSet | Deployment |
|---|---|---|
| Pod replication | Yes | Yes (via ReplicaSet) |
| Rolling updates | No | Yes |
| Rollback | No | Yes |
| Update history | No | Yes |
| Declarative updates | Manual | Automatic |
Deployments are the recommended way to manage stateless applications. They create and manage ReplicaSets automatically, providing additional features like rolling updates and rollbacks.
Understanding Owner References
Most ReplicaSets are created and managed by Deployments:- Controlled By Deployment: The ReplicaSet is managed by a Deployment. Changes to replica count should be made on the Deployment.
- No Owner: The ReplicaSet is standalone and can be managed directly.
Troubleshooting
ReplicaSet not creating pods
ReplicaSet not creating pods
- Check if replica count is greater than zero
- Verify selector matches pod template labels
- Check for resource quota limits in namespace
- Review ReplicaSet events for errors
Pods not becoming ready
Pods not becoming ready
- Check pod logs for application errors
- Verify readiness probe configuration
- Check if required ConfigMaps/Secrets exist
- Verify image pull is successful
Scale changes being reverted
Scale changes being reverted
- Check if ReplicaSet is managed by a Deployment
- Scale the parent Deployment instead
- Check for HorizontalPodAutoscaler targeting the Deployment
Old ReplicaSets consuming resources
Old ReplicaSets consuming resources
- Deployments keep old ReplicaSets for rollback
- Set
spec.revisionHistoryLimiton Deployment to limit retained ReplicaSets - Default is 10 revisions
Cannot delete ReplicaSet
Cannot delete ReplicaSet
- If managed by Deployment, it will be recreated
- Delete the parent Deployment instead
- Check for finalizers blocking deletion
Selector mismatch errors
Selector mismatch errors
- Selectors are immutable after creation
- Ensure pod template labels match the selector
- Delete and recreate to change the selector
FAQ
Should I create ReplicaSets directly?
Should I create ReplicaSets directly?
Generally no. Use Deployments instead, which manage ReplicaSets and provide additional features like rolling updates and rollbacks. Direct ReplicaSet creation is only needed for specific use cases.
Why are there multiple ReplicaSets for one Deployment?
Why are there multiple ReplicaSets for one Deployment?
Each time you update a Deployment’s pod template, a new ReplicaSet is created. Old ReplicaSets are kept (scaled to 0) for rollback capability. The number retained is controlled by
revisionHistoryLimit.Can I restart pods in a ReplicaSet?
Can I restart pods in a ReplicaSet?
ReplicaSets don’t have a built-in restart mechanism. Delete pods to have them recreated, or if managed by a Deployment, use the Deployment’s restart feature.
What happens if I scale a Deployment-managed ReplicaSet?
What happens if I scale a Deployment-managed ReplicaSet?
The Deployment controller will detect the change and revert it to match the Deployment’s replica count. Always scale the Deployment instead.
How do I identify which Deployment owns a ReplicaSet?
How do I identify which Deployment owns a ReplicaSet?
Check the “Controlled By” column or the owner references in the ReplicaSet details. The ReplicaSet name usually includes the Deployment name as a prefix.
Why is my ReplicaSet showing 0/0 replicas?
Why is my ReplicaSet showing 0/0 replicas?
This is normal for old ReplicaSets after a Deployment update. The Deployment scales down old ReplicaSets to 0 but keeps them for rollback history.
Can I update the pod template in a ReplicaSet?
Can I update the pod template in a ReplicaSet?
Yes, but existing pods won’t be updated. Only new pods (created due to scaling or pod deletion) will use the new template. Use Deployments for proper rolling updates.