
You can update a deployment, deployment config, replicaset, replication controller, or statefulset to have a certain number of replicas:
- Manually (this article)
- Automatically, using the oc autoscale command
If you are not familiar with the oc command, refer to OpenShift - Getting Started with the oc command.
The oc scale command can be used to temporarily update a deployment, deployment config, replicaset, replication controller, or statefulset to have a certain number of replicas. Replicas is the number of pods that should be spawned. For example, to scale a deployment. Reducing the number of replicas in a deployment config will cause the pod(s) associated with the deployment to be terminated amd new pods will NOT be created.
oc scale deployment/my-deployment --replicas 0
Or a deployment config. Reducing the number of replicas in a deployment config will cause the pod(s) associated with the deployment config to be terminated amd new pods will NOT be created.
oc scale deploymentconfig/my-deploymentconfig --replicas 1
Or replicaset.
AVOID TROUBLE
Reducing the number of replicas in a replicaset will cause the pod(s) associated with the replicaset to be terminated. However, new pods will immediately be created at the DESIRED replicas value returned by the oc get deployments command.
oc scale replicaset/my-replicaset --replicas 2
Or replication controller.
AVOID TROUBLE
Reducing the number of replicas in a replication controller will cause the pod(s) associated with the replication controller to be terminated. However, new pods will immediately be created at the DESIRED replicas value returned by the oc get deployment configs command.
oc scale replicationcontroller/my-replicationcontroller --replicas 1
Or stateful set.
oc scale statefulset/my-statefulset --replicas 1
It is also noteworthy that the oc edit command can be used to permanently change number of replicas being used by a deployment or deployment config.
~]$ oc edit deployment <your deployment>
deployment.apps/app001-5b9879db6d edited
Or, the oc patch command can be used to permanently update a deployment or deployment config replicas.
~]$ oc patch deployment my-deployment --patch '{"spec":{"replicas":1}}'
deployment.apps/my-deployment patched
For deployments, once scaled, the oc get deployments command should return something like this. In this example, the deployment was scaled down to 0 replicas.
~]# oc get deployments
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
app001-5b9879db6d 0 0 0 0 205d
Similarly, the oc get replicaset command can be used to display the DESIRED, CURRENT, and READY replicas for the replicaset.
~]# oc get replicaset --namespace <some namespace>
NAME DESIRED CURRENT READY AGE
app001-5b9879db6d 1 1 1 205d
And the oc get pods command can be used to list the pods.
~]$ oc get pods --namespace my-project
NAME READY STATUS RESTARTS AGE
my-pod-7fj8d 6/6 Running 1 (14m ago) 14m
my-pod-dm8cj 6/6 Running 1 (14m ago) 14m
Did you find this article helpful?
If so, consider buying me a coffee over at