Scaling: Manual
The kubectl scale
command manually adjusts the number of pod replicas for a Deployment, ReplicaSet, StatefulSet, or Job.
This is useful when you want to:
Increase replicas to handle more traffic.
Reduce replicas to save resources.
Perform manual scaling when Horizontal Pod Autoscaler (HPA) is not required
Basic Syntax Usage
<resource-type>
: Type of resource (e.g.,deployment
,replicaset
,statefulset
,job
).<resource-name>
: The name of the resource you want to scale.--replicas=<number>
: Desired number of pod replicas.
Scaling Deployment
Lets create a deployment using nginx
image.
It will create a deployment with replicas defaulted to 1
.
Now lets scale the newly created deployment to 3
replicas using this command below.
Now if you check teh deployments again, we will have 3
replicas.
Others
To scale replicaset
, statefulset
, and job
is similar with scaling deployment, we only need to specify the resource type, resource name, and number of replicas in kubectl apply
command.
Note that this changes are not persisted. If you have yaml
file for your deployment definition you need to change the spec.replicas
value.
References
Last updated