Scaling ReplicaSets
You'll learn how to manually change the number of running Pod replicas in a ReplicaSet using kubectl and manifest files.
What Is Scaling?
Scaling a ReplicaSet means adjusting how many identical Pods should be running at once. Think of it like a restaurant adding or removing tables during rush hour—you're controlling capacity to match demand.
ReplicaSets maintain a desired number of replicas. When you scale up, the controller creates new Pods. When you scale down, it terminates excess Pods to reach your target.
Two Ways to Scale
Method 1: Using kubectl scale
The fastest way is a direct command:
kubectl scale replicaset my-replicaset --replicas=5
This immediately tells the ReplicaSet to maintain 5 Pods. You can scale up (increase replicas) or scale down (decrease replicas). The change happens right away, but isn't saved to your YAML file.
Method 2: Updating the Manifest
Edit your ReplicaSet YAML file and change the replicas field:
spec:
replicas: 5 # Changed from 3 to 5
selector:
matchLabels:
app: myapp
Then apply the updated manifest:
kubectl apply -f replicaset.yaml
This method documents the change in your source files, making it better for version control and reproducibility.
Choosing Your Approach
Use kubectl scale for quick testing or emergencies. Use manifest updates for permanent, documented changes that your team can review and track.
Key Takeaway: Scaling ReplicaSets adjusts Pod count either via kubectl scale commands for speed or manifest updates for permanence—both trigger the controller to add or remove Pods until the desired replica count is reached.