Revive inactive OpenShift pods that scaled to zero

This learning path demonstrates how to revive inactive pods in your sandbox that have scaled to zero.

Access the Developer Sandbox

Since the Developer Sandbox for Red Hat OpenShift is a learning platform, any pods you were running are stopped, or scaled to zero, after 12 hours of use. To bring the pod back to life, you need to set its replica count to one in your Deployment, DeploymentConfig, or StatefulSet files.

In order to get full benefit from taking this lesson, you need to:

In this lesson, you will:

  • Set replicas to one.

Scale pods to one in the OpenShift dashboard

When you change the number of pod replicas you're running, you are scaling the pod. To revive a single instance of your pod, do the following:

  1. Within the OpenShift dashboard, select the Developer perspective.
  2. Navigate to the Topology view. 
  3. Select the icon for the container you want to revive.
  4. Select the Details tab (Figure 1).
OpenShift Topology pod Details panel.
Figure 1: A container's Details panel.
  1. Click the up arrow to scale to one.

The ring around "Scaled to #" as shown in Figure 1 will change to blue when the pod has finished scaling up.

Scale pods to one from the command line

If you have not started your command-line terminal in the Developer Sandbox yet:

  1. Go to the set of icons on the top right (to the left of your project name) and click the terminal icon (>_). 
  2. A terminal will open at the bottom of your screen with the "Initialize terminal" interface displayed.
  3. For the purpose of this learning path, click Start to initialize a basic terminal for your project.

Note: If doing this in your own Red Hat OpenShift cluster, you will need to install the oc command.

The text "Connecting to your OpenShift command line terminal ..." will display until the terminal loads, which will look something like this:

Welcome to the OpenShift Web Terminal. Type "help" for a list of installed CLI tools.
bash-5.1 ~ $

You will need to get a list of Deployments, DeploymentConfigs, and StatefulSets. To get your Deployments, use the command oc get deploy like so:

oc get deploy
NAME                        READY   UP-TO-DATE   AVAILABLE   AGE
gateway-vertx               0/0     0            0           3h25m
inventory-quarkus           1/1     1            1           3h25m
primer-export-primer        1/1     1            1           4h9m
workspace71b1c95725544e5c   0/0     0            0           6d

To get your DeploymentConfigs and StatefulSets, run the following commands:

oc get dc
oc get deploy
oc get statefulsets

Here are two examples:

$ oc get statefulsets
NAME   READY   AGE
web    0/2     50s
$ oc get deploy
NAME                        READY   UP-TO-DATE   AVAILABLE   AGE
nodejs-basic                1/1     1            1           5m9s
workspace859454a8219440c3   1/1     1            1           4m58s

For each item listed under each command, run the oc scale command to set the replica count to one. Note that some of the commands might return zero objects, based on your specific situation. Examples include:

oc scale deploy/nodejs-basic –replicas 1
oc scale dc/foo –replicas 1
oc scale statefulset/web –replicas 1

Summary

When your OpenShift pods have scaled to 0 (stopped), you can quickly and easily scale up your pod counts from either the OpenShift dashboard or the oc command line.

Want to learn more? Try these:

Previous resource
Overview: Revive inactive OpenShift pods that scaled to zero