Jason Gambino, Author at Stark & Wayne https://www.starkandwayne.com/blog/author/jasongambino/ Cloud-Native Consultants Thu, 07 Apr 2022 16:22:57 +0000 en-US hourly 1 https://wordpress.org/?v=6.0.3 https://www.starkandwayne.com/wp-content/uploads/2021/04/cropped-SW_Logos__shield_blue_on_transparent_with_border-32x32.png Jason Gambino, Author at Stark & Wayne https://www.starkandwayne.com/blog/author/jasongambino/ 32 32 Setting up and testing Cloud Foundry App Autoscaler using Genesis https://www.starkandwayne.com/blog/setting-up-and-testing-cloud-foundry-app-autoscaler-using-genesis/ Tue, 05 Apr 2022 18:44:04 +0000 https://www.starkandwayne.com/?p=11466

Photo by Samuel Ramos on Unsplash

Autoscaling is a cloud computing feature that enables organizations to scale cloud services such as server capacities or virtual machines up or down automatically, based on defined situations. Autoscaler in cloud foundry provides the capability to adjust the computation resources by Dynamic scaling based on application performance metrics and Scheduled scaling based on time.

Adding the Autoscaler feature to the Cloud Foundry Genesis kit is pretty simple. Deploy the autoscaler kit, add autoscaler integration in CF deployment for credentials to register the service broker in CF.  Start by adding the feature flag, register the  autoscaler service broker, deploy autoscaler, create a service instance and bind it then add a policy to your app. Below we will run through the steps of adding and configuring the various components than how to test and change settings.  We will end with testing of an application.

Deploy Autoscaler

App Autoscaler is an add-on to Cloud Foundry to automatically scale the number of application instances based on CPU, memory, throughput, response time, and several other metrics. You can also add your own custom metrics. You decide which metrics you want to scale your app up and down by in a policy and then apply the policy to your application.

We start by deploying the autoscaler

Download the App Autoscaler kit from here

Once downloaded locally, change into that folder.

Do a 

Genesis New [autoscaler_env_file_name]

This will generate the manifest for the file.

Now Deploy the manifest

Genesis deploy [autoscaler_env_file_name]

Add Autoscaler feature to CF

To add support for Autoscaler in CF you need to set the feature flag for Autoscaler and deploy autoscaler itself.  In this tutorial We assume that you have vault as the credentials storage and safe is being used to target and auth the vault.

In the env file for you cf deployment add the feature flag

kit:
 name: cf
 version: 2.1.3
 features:
    - partitioned-network
    ...
    - app-autoscaler-integration # <<<< This is the addition

Deploy the env file from above **genesis deploy env.file**, once completed autoscaler will be added to your CF.

Configure the service broker

There are two ways to configure the service broker the genesis way and the manual way.

Genesis Way

The Genesis way will do a lot of work for you, go to the folder we deployed autoscaler in and run the following.

To see what genesis can do run

genesis do my_deployment_File list

you should get something like

The following addons are defined:

  bind-autoscaler Binds the Autoscaler service broker to your deployed CF.`
  setup-cf-plugin Adds the ‘autoscaler’ plugin to the cf cli. Use -f option to bypass confirmation prompt.

I recommend running both commands but for this example we will “do” the bind-autoscaler command

genesis do my_deployment_File bind-autoscaler

Congratulations, you’ve setup the service broker in the next section we will make a policy and apply it to the application.

Manual Way

The Manual way does the same things as the genesis way but the genesis way does all the following steps for you automatically.

 First we setup a service broker for autoscaler, Service brokers publish a catalog of services and service plans, manage the provisioning and de-provisioning of service instances, and provide connection details and credentials for an application to consume the resource.

To configure a service broker we start by getting the credentials generated when we deployed the autoscaler feature.

safe tree

Find path to cf-app-autoscaler

safe get path/to/cf-app-autoscaler

This will retrieve the credentials for the service broker from safe: 

Write down the following:

  • Service_broker_domain
  • Service_broker_password
  • Service_broker_username

These are the credentials needed to register the broker with CF

cf create-service-broker autoscaler service_broker_username service_broker_password service_broker_username

With this we have made a Service broker for Autoscaler but we still need to enable the broker to be used in the cf environment.

This command will enable the broker for all orgs

cf enable-service-access autoscaler

Congratulations, you’ve setup the service broker in the next section we will make a policy and apply it to the application.

Creation and Application of Policies

In this step we assume you have already deployed an app and want to make a policy/apply a policy to the application.

Check what plans are available to use for Autoscaler

cf marketplace

it will say a plan name in the plan column for Autoscaler, write that down.

We create a **service instance**

cf create-service autoscaler plan service_instance_name

Now we can make a policy, policies are in json format. An example for CPU is given below

{
  "instance_min_count": 1,
  "instance_max_count": 4,
  "scaling_rules":
  [
   {
    "metric_type":"cpu",
    "breach_duration_secs":60,
    "threshold": 10,
    "operator":"<=",
    "cool_down_secs":60,
    “adjustment”: “-1”
   },
   {
    “metric_type”: “cpu”,
    “breach_duration_secs”: 60,
    “threshold”: 50,
    “operator”: “>”,
    “cool_down_secs”: 60,
    “adjustment”: “+1”
   }   
  ]
}

This policy shows limiting the amount of instances and scaling rules. The goal of a policy is to scale based on need within the instance rules. This example will max out at 4 and min out at 1. It will either be at one of the 2 extremes or at its sweet spot of between 10% and 50% threshold. When between the two it will maintain.

Bind the service and policy to the app you want to use autoscaler on.

cf bind-service cf-env service-instance -c policy

Restart the plugin, until it is restarted or reinitiated the metrics won’t be available

Setting up the CF app autoscaler CLI plugin

App-AutoScaler plug-in provides the command line interface to manage  app autoscaler policies, retrieve metrics and scaling event history.

The commands for CF App Autoscaler CLI are as follows

Command Description
autoscaling-api, asa Set or view AutoScaler service API endpoint
autoscaling-policy, asp Retrieve the scaling policy of an application
attach-autoscaling-policy, aasp Attach a scaling policy to an application
detach-autoscaling-policy, dasp Detach the scaling policy from an application
create-autoscaling-credential, casc Create custom metric credential for an application
delete-autoscaling-credential, dasc Delete the custom metric credential of an application
autoscaling-metrics, asm Retrieve the metrics of an application
autoscaling-history, ash Retrieve the scaling history of an application

You can install the CLI two ways

The Genesis way

genesis do my_deployment_File setup-cf-plugin

The CF plugin way

cf install-plugin -r CF-Community app-autoscaler-plugin

Viewing Metrics and History

To see the metrics Autoscaler is using for your application or what is happening according to policy there are two commands. Note that you will only see metrics AFTER your application is bound with a policy to a service instance of the Autoscaler service. You will also only see metrics referenced in `metric_type` of the policy for an application being enforced.

To see the metrics of a app (example below shows cpu)

cf autoscaling-metrics cf-env cpu

results of running auto-scaling-metrics for throughput

To see the history and what triggered events you look at the history of the app.

cf autoscaling-history cf-env

Testing Metrics

It is important to test a policy once it has been implemented. A simple way to do so is using scales. Using the policy from the last example…

Scale the app to 10 instances

cf scale -i 10 cf-env

Once this successfully scales up to 10 instances it will scale down to 4 because of the policy above having a max instance of 4. It will scale down to a single instance because it will be below 10 requests per second for 60 seconds.

Congratulations, you now know the basics of setting up and running Autoscaler.

The post Setting up and testing Cloud Foundry App Autoscaler using Genesis appeared first on Stark & Wayne.

]]>

Photo by Samuel Ramos on Unsplash

Autoscaling is a cloud computing feature that enables organizations to scale cloud services such as server capacities or virtual machines up or down automatically, based on defined situations. Autoscaler in cloud foundry provides the capability to adjust the computation resources by Dynamic scaling based on application performance metrics and Scheduled scaling based on time.

Adding the Autoscaler feature to the Cloud Foundry Genesis kit is pretty simple. Deploy the autoscaler kit, add autoscaler integration in CF deployment for credentials to register the service broker in CF.  Start by adding the feature flag, register the  autoscaler service broker, deploy autoscaler, create a service instance and bind it then add a policy to your app. Below we will run through the steps of adding and configuring the various components than how to test and change settings.  We will end with testing of an application.

Deploy Autoscaler

App Autoscaler is an add-on to Cloud Foundry to automatically scale the number of application instances based on CPU, memory, throughput, response time, and several other metrics. You can also add your own custom metrics. You decide which metrics you want to scale your app up and down by in a policy and then apply the policy to your application.

We start by deploying the autoscaler

Download the App Autoscaler kit from here

Once downloaded locally, change into that folder.

Do a 

Genesis New [autoscaler_env_file_name]

This will generate the manifest for the file.

Now Deploy the manifest

Genesis deploy [autoscaler_env_file_name]

Add Autoscaler feature to CF

To add support for Autoscaler in CF you need to set the feature flag for Autoscaler and deploy autoscaler itself.  In this tutorial We assume that you have vault as the credentials storage and safe is being used to target and auth the vault.

In the env file for you cf deployment add the feature flag

kit:
 name: cf
 version: 2.1.3
 features:
    - partitioned-network
    ...
    - app-autoscaler-integration # <<<< This is the addition

Deploy the env file from above **genesis deploy env.file**, once completed autoscaler will be added to your CF.

Configure the service broker

There are two ways to configure the service broker the genesis way and the manual way.

Genesis Way

The Genesis way will do a lot of work for you, go to the folder we deployed autoscaler in and run the following.

To see what genesis can do run

genesis do my_deployment_File list

you should get something like

The following addons are defined:

  bind-autoscaler Binds the Autoscaler service broker to your deployed CF.`
  setup-cf-plugin Adds the ‘autoscaler’ plugin to the cf cli. Use -f option to bypass confirmation prompt.

I recommend running both commands but for this example we will “do” the bind-autoscaler command

genesis do my_deployment_File bind-autoscaler

Congratulations, you’ve setup the service broker in the next section we will make a policy and apply it to the application.

Manual Way

The Manual way does the same things as the genesis way but the genesis way does all the following steps for you automatically.

 First we setup a service broker for autoscaler, Service brokers publish a catalog of services and service plans, manage the provisioning and de-provisioning of service instances, and provide connection details and credentials for an application to consume the resource.

To configure a service broker we start by getting the credentials generated when we deployed the autoscaler feature.

safe tree

Find path to cf-app-autoscaler

safe get path/to/cf-app-autoscaler

This will retrieve the credentials for the service broker from safe: 

Write down the following:

  • Service_broker_domain
  • Service_broker_password
  • Service_broker_username

These are the credentials needed to register the broker with CF

cf create-service-broker autoscaler service_broker_username service_broker_password service_broker_username

With this we have made a Service broker for Autoscaler but we still need to enable the broker to be used in the cf environment.

This command will enable the broker for all orgs

cf enable-service-access autoscaler

Congratulations, you’ve setup the service broker in the next section we will make a policy and apply it to the application.

Creation and Application of Policies

In this step we assume you have already deployed an app and want to make a policy/apply a policy to the application.

Check what plans are available to use for Autoscaler

cf marketplace

it will say a plan name in the plan column for Autoscaler, write that down.

We create a **service instance**

cf create-service autoscaler plan service_instance_name

Now we can make a policy, policies are in json format. An example for CPU is given below

{
  "instance_min_count": 1,
  "instance_max_count": 4,
  "scaling_rules":
  [
   {
    "metric_type":"cpu",
    "breach_duration_secs":60,
    "threshold": 10,
    "operator":"<=",
    "cool_down_secs":60,
    “adjustment”: “-1”
   },
   {
    “metric_type”: “cpu”,
    “breach_duration_secs”: 60,
    “threshold”: 50,
    “operator”: “>”,
    “cool_down_secs”: 60,
    “adjustment”: “+1”
   }   
  ]
}

This policy shows limiting the amount of instances and scaling rules. The goal of a policy is to scale based on need within the instance rules. This example will max out at 4 and min out at 1. It will either be at one of the 2 extremes or at its sweet spot of between 10% and 50% threshold. When between the two it will maintain.

Bind the service and policy to the app you want to use autoscaler on.

cf bind-service cf-env service-instance -c policy

Restart the plugin, until it is restarted or reinitiated the metrics won’t be available

Setting up the CF app autoscaler CLI plugin

App-AutoScaler plug-in provides the command line interface to manage  app autoscaler policies, retrieve metrics and scaling event history.

The commands for CF App Autoscaler CLI are as follows

CommandDescription
autoscaling-api, asaSet or view AutoScaler service API endpoint
autoscaling-policy, aspRetrieve the scaling policy of an application
attach-autoscaling-policy, aaspAttach a scaling policy to an application
detach-autoscaling-policy, daspDetach the scaling policy from an application
create-autoscaling-credential, cascCreate custom metric credential for an application
delete-autoscaling-credential, dascDelete the custom metric credential of an application
autoscaling-metrics, asmRetrieve the metrics of an application
autoscaling-history, ashRetrieve the scaling history of an application

You can install the CLI two ways

The Genesis way

genesis do my_deployment_File setup-cf-plugin

The CF plugin way

cf install-plugin -r CF-Community app-autoscaler-plugin

Viewing Metrics and History

To see the metrics Autoscaler is using for your application or what is happening according to policy there are two commands. Note that you will only see metrics AFTER your application is bound with a policy to a service instance of the Autoscaler service. You will also only see metrics referenced in `metric_type` of the policy for an application being enforced.

To see the metrics of a app (example below shows cpu)

cf autoscaling-metrics cf-env cpu

results of running auto-scaling-metrics for throughput

To see the history and what triggered events you look at the history of the app.

cf autoscaling-history cf-env

Testing Metrics

It is important to test a policy once it has been implemented. A simple way to do so is using scales. Using the policy from the last example…

Scale the app to 10 instances

cf scale -i 10 cf-env

Once this successfully scales up to 10 instances it will scale down to 4 because of the policy above having a max instance of 4. It will scale down to a single instance because it will be below 10 requests per second for 60 seconds.

Congratulations, you now know the basics of setting up and running Autoscaler.

The post Setting up and testing Cloud Foundry App Autoscaler using Genesis appeared first on Stark & Wayne.

]]>