Sale down a service to zero pods, and have it scale backup up automatically when network traffic is
detected with the oc idle <service>
command.
You can run the oc idle <service>
on a service to have OpenShift scale it to zero pods. When network traffic is
detected OpenShift will scale up the deployment.
This is what a typical service in OpenShift will look like before being idled:
➜ oc get pods
NAME READY STATUS RESTARTS AGE
minio-1-25vtj 1/1 Running 0 2m12s
minio-1-5v6vh 1/1 Running 0 2m12s
minio-1-bqjq2 1/1 Running 0 2m12s
Use the oc get service
command to list the services in your namespace:
➜ oc get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
api ClusterIP 10.98.96.63 <none> 8080/TCP 496d
minio ClusterIP 10.98.136.34 <none> 9000/TCP 496d
patroni ClusterIP 10.98.133.221 <none> 5432/TCP 501d
web ClusterIP 10.98.229.240 <none> 2015/TCP 496d
Once you've identifed the service, use the command oc idle <service-name>
to idle all the pods:
➜ oc idle minio
Warning: extensions/v1beta1 Scale is deprecated in v1.2+, unavailable in v1.16+
The service "22efde-dev/minio" has been marked as idled
The service will unidle DeploymentConfig "22efde-dev/minio" to 3 replicas once it receives traffic
DeploymentConfig "22efde-dev/minio" has been idled
OpenShift will scale down all the pods associated with that service until network traffic is detected on that service:
➜ oc get pods
NAME READY STATUS RESTARTS AGE
minio-1-5v6vh 1/1 Terminating 0 3m17s
minio-1-25vtj 1/1 Terminating 0 3m17s
minio-1-bqjq2 1/1 Terminating 0 3m17s
Pro Tip 🤓
If you know you won't be using the environment for an extended period of time consider scaling down all the depoyments so
they don't unintentionally restart. For this use the command oc scale --replicas=0 <deployment-config-name>