Scale up and Scale down and Idle the application instances

In this recipe we will learn how to scale our application. OpenShift has the capability to scale your application and make sure that many instances are always running.

Create a project or use an existing project

If you want to, you can create a new project based on what you have learned in the previous recipe. Since we already have a project we will use it. Run the following command to make sure.

$ oc project ocp-test

View the deployment config

$ oc get deploymentconfig/dbtest -o json
{
    "apiVersion": "v1",
    "kind": "DeploymentConfig",
    "metadata": {
        "annotations": {
            "openshift.io/generated-by": "OpenShiftWebConsole"
        },
        "creationTimestamp": "2017-07-10T14:11:44Z",
        "generation": 5,
        "labels": {
            "app": "dbtest"
        },
        "name": "dbtest",
        "namespace": "ocp-test",
        "resourceVersion": "4708304",
        "selfLink": "/oapi/v1/namespaces/ocp-test/deploymentconfigs/dbtest",
        "uid": "b42bca1e-6579-11e7-bbc1-0682973451aa"
    },
    "spec": {
        "replicas": 1,
        "selector": {
            "deploymentconfig": "dbtest"
        },
        "strategy": {
            "activeDeadlineSeconds": 21600,
            "resources": {},
            "rollingParams": {
                "intervalSeconds": 1,
                "maxSurge": "25%",
                "maxUnavailable": "25%",
                "timeoutSeconds": 600,
                "updatePeriodSeconds": 1
            },
            "type": "Rolling"
        },
        "template": {
            "metadata": {
                "creationTimestamp": null,
                "labels": {
                    "app": "dbtest",
                    "deploymentconfig": "dbtest"
                }
            },
            "spec": {
                "containers": [
                    {
                        "env": [
                            {
                                "name": "MYSQL_USER",
                                "value": "test_user"
                            },
                            {
                                "name": "MYSQL_PASSWORD",
                                "value": "test_pass"
                            },
                            {
                                "name": "MYSQL_DATABASE",
                                "value": "sample"
                            }
                        ],
                        "image": "172.30.160.227:5000/ocp-test/dbtest@sha256:220bb329080f0358693a8661e4eb3c51c5f649edec888494f1d590829484c56d",
                        "imagePullPolicy": "Always",
                        "name": "dbtest",
                        "ports": [
                            {
                                "containerPort": 8080,
                                "protocol": "TCP"
                            }
                        ],
                        "resources": {},
                        "terminationMessagePath": "/dev/termination-log"
                    }
                ],
                "dnsPolicy": "ClusterFirst",
                "restartPolicy": "Always",
                "securityContext": {},
                "terminationGracePeriodSeconds": 30
            }
        },
        "test": false,
        "triggers": [
            {
                "imageChangeParams": {
                    "automatic": true,
                    "containerNames": [
                        "dbtest"
                    ],
                    "from": {
                        "kind": "ImageStreamTag",
                        "name": "dbtest:latest",
                        "namespace": "ocp-test"
                    },
                    "lastTriggeredImage": "172.30.160.227:5000/ocp-test/dbtest@sha256:220bb329080f0358693a8661e4eb3c51c5f649edec888494f1d590829484c56d"
                },
                "type": "ImageChange"
            },
            {
                "type": "ConfigChange"
            }
        ]
    },
    "status": {
        "availableReplicas": 1,
        "conditions": [
            {
                "lastTransitionTime": "2017-07-10T14:12:08Z",
                "lastUpdateTime": "2017-07-10T14:12:08Z",
                "message": "Deployment config has minimum availability.",
                "status": "True",
                "type": "Available"
            },
            {
                "lastTransitionTime": "2017-07-10T14:19:50Z",
                "lastUpdateTime": "2017-07-10T14:19:52Z",
                "message": "replication controller \"dbtest-3\" successfully rolled out",
                "reason": "NewReplicationControllerAvailable",
                "status": "True",
                "type": "Progressing"
            }
        ],
        "details": {
            "causes": [
                {
                    "imageTrigger": {
                        "from": {
                            "kind": "ImageStreamTag",
                            "name": "dbtest:latest",
                            "namespace": "ocp-test"
                        }
                    },
                    "type": "ImageChange"
                }
            ],
            "message": "image change"
        },
        "latestVersion": 3,
        "observedGeneration": 5,
        "readyReplicas": 1,
        "replicas": 1,
        "unavailableReplicas": 0,
        "updatedReplicas": 1
    }
}

Note that the replicas: is set to 1. This tells OpenShift that when this application deploys, make sure that there is 1 instance.

The replicationController mirrors this configuration initially; the replicationController (or rc) will ensure that there is always the set number of instances always running.

To view the rc for your application first get the current pod running.

 oc get pods
NAME                               READY     STATUS      RESTARTS   AGE
dbtest-3-wwcd3                     1/1       Running     0          12m

This shows that the build dbtest-3 is running in pod wwcd3. Let us view the rc on this build.

$ oc get rc/dbtest-3
NAME       DESIRED   CURRENT   READY     AGE
dbtest-3   1         1         1         14m
Note
You can change the number of replicas in DeploymentConfig or the ReplicationController.

However note that if you change the deploymentConfig it applies to your application. This means, even if you delete the current replication controller, the new one that gets created will be assigned the REPLICAS value based on what is set for DC. If you change it on the Replication Controller, the application will scale up. But if you happen to delete the current replication controller for some reason, you will loose that setting.

Scale Application

To scale your application we will edit the deploymentConfig to 3.

Scale your application using the oc scale command (remembering to specify the dc)

$ oc scale --replicas=3 dc/dbtest
deploymentconfig "dbtest" scaled

On the command line, see how many pods you are running now:

$ oc get pods --show-all=false
NAME                               READY     STATUS    RESTARTS   AGE
dbtest-3-366r6                     1/1       Running   0          1m
dbtest-3-rwl59                     1/1       Running   0          1m
dbtest-3-wwcd3                     1/1       Running   0          19m

If you look at the web console and you will see that there are 3 instances running now.

You now have 3 instances of dbtest-3 running (each with a different pod-id). If you check the rc of the dbtest-3 build you will see that it has been updated by the dc.

$ oc get rc/dbtest-3
NAME       DESIRED   CURRENT   READY     AGE
dbtest-3   3         3         3         21m

Idling the application

Run the following command to find the available endpoints

$ oc get endpoints
NAME                       ENDPOINTS                                       AGE
dbtest                     10.1.0.10:8080,10.1.11.55:8080,10.1.6.84:8080   30m

Note that the name of the endpoints is dbtest and there are three ips addresses for the three pods.

Run the oc idle endpoints/dbtest command to idle the application

$ oc idle endpoints/dbtest
The service "ocp-test/dbtest" has been marked as idled
The service will unidle DeploymentConfig "ocp-test/dbtest" to 3 replicas once it receives traffic
DeploymentConfig "ocp-test/dbtest" has been idled

Go back to the webconsole. You will notice that the pods show up as idled.

idled_pods

At this point the application is idled, the pods are not running and no resources are being used by the application. This doesn’t mean that the application is deleted. The current state is just saved.. that’s all.

Reactivate your application

Now click on the application route URL or access the application via curl.

Note that it takes a little while for the application to respond. This is because pods are spinning up again. You can notice that in the web console.

In a little while the output comes up and your application would be up with 3 pods.

So, as soon as the user accesses the application, it comes up!!!

Scaling Down

Scaling down is the same procedure as scaling up. Use the oc scale command on the dbtest application dc setting.

$ oc scale --replicas=1 dc/dbtest
deploymentconfig "dbtest" scaled

Congratulations!! In this recipe you have learned about scaling and how to scale up/down your application on OpenShift!

results matching ""

    No results matching ""