Managing ReplicaSets
1. Listing ReplicaSets
kubectl get rs
kubectl get rs -l app=web
kubectl get rs -o wide
| Column | Meaning |
| DESIRED | Spec replica count |
| CURRENT | Existing pods |
| READY | Pods passing readiness |
2. Describing ReplicaSet Details
| Section | Info |
| Selector | matchLabels |
| Replicas | Desired/current/ready |
| Pods Status | Running/Waiting/Succeeded/Failed counts |
| Pod Template | Containers, labels |
| Events | Created/Deleted pod actions |
3. Scaling ReplicaSets
kubectl scale rs web-7f8 --replicas=5
Warning: Scaling a Deployment-owned RS directly will be reverted by the Deployment controller. Scale the Deployment instead.
4. Deleting ReplicaSets
| Command | Behavior |
kubectl delete rs NAME | Delete RS + pods (cascading) |
kubectl delete rs NAME --cascade=orphan | Keep pods orphaned |
5. Understanding ReplicaSet Selectors
spec:
selector:
matchLabels: { app: web, pod-template-hash: 7f8abc }
| Property | Detail |
| pod-template-hash | Added by Deployment to disambiguate RS |
| Immutable | Selector cannot change after creation |
6. Viewing ReplicaSet Ownership
kubectl get rs web-7f8 -o jsonpath='{.metadata.ownerReferences}'
kubectl tree deploy web # plugin: show ownership tree
| Field | Detail |
| ownerReferences[].kind | Usually Deployment |
| controller: true | Marks owner that reconciles |
7. Viewing ReplicaSet Pods
kubectl get pods -l app=web,pod-template-hash=7f8abc
| Approach | Use |
| label selector | Match RS selector |
| field selector | --field-selector=spec.nodeName=node1 |
8. Orphaning Pods During Deletion
| --cascade | Effect |
| background (default) | Owner deleted; GC removes children |
| foreground | Owner stays Terminating until children deleted |
| orphan | Owner deleted; children remain |
9. Understanding ReplicaSet vs Deployment
Deployment
- Declarative updates & rollback
- Manages multiple RS revisions
- Use for stateless apps
ReplicaSet
- Just maintains replica count
- No rollout/rollback
- Rarely used directly
10. Troubleshooting ReplicaSet Issues
| Symptom | Likely Cause |
| Pods stuck Pending | Unschedulable (resources, selector, taints) |
| RS stuck at 0 ready | Readiness probe failing |
| Image pull error | Wrong image/tag, missing imagePullSecret |
| Selector mismatch | RS selector doesn't match template labels |
| Stale RS persists | revisionHistoryLimit too high or paused |