scale

Scaling Kubenetes Resources

Set a new size for a Deployment, ReplicaSet, Replication Controller, or StatefulSet.

Scale also allows users to specify one or more preconditions for the scale action.

If –current-replicas or –resource-version is specified, it is validated before the scale is attempted, and it is guaranteed that the precondition holds true when the scale is sent to the server.

Command

  1. $ kubectl scale [--resource-version=version] [--current-replicas=count] --replicas=COUNT (-f FILENAME | TYPE NAME)

Example

Current State

  1. $ kubectl get deployments
  2. NAME READY UP-TO-DATE AVAILABLE AGE
  3. nginx 1/1 1 1 24s

Command

  1. $ kubectl scale --replicas=3 deployment/nginx
  2. deployment.apps/nginx scaled

New State

  1. $ kubectl get deployments
  2. NAME READY UP-TO-DATE AVAILABLE AGE
  3. nginx 3/3 3 3 87s

More Examples

  1. # Scale a replicaset named 'foo' to 3.
  2. kubectl scale --replicas=3 rs/foo
  1. # Scale a resource identified by type and name specified in "foo.yaml" to 3.
  2. kubectl scale --replicas=3 -f foo.yaml
  1. # If the deployment named mysql's current size is 2, scale mysql to 3.
  2. kubectl scale --current-replicas=2 --replicas=3 deployment/mysql
  1. # Scale multiple replication controllers.
  2. kubectl scale --replicas=5 rc/foo rc/bar rc/baz
  1. # Scale statefulset named 'web' to 3.
  2. kubectl scale --replicas=3 statefulset/web

Conditional Scale Update

It is possible to conditionally update the replicas if and only if the replicas haven’t changed from their last known value using the --current-replicas flag. e.g. kubectl scale --current-replicas=2 --replicas=3 deployment/mysql