Cloud Docs Home > F5 Application Services Proxy Index

Launch an ASP instance for a Marathon Application

The ASP Controller for Marathon launches Application Services Proxy instances automatically for Apps that have the ASP_ENABLE_LABEL value set to “enabled” (for example, f5-asp:enable).

Launch an ASP instance with the default configurations

Add the label "f5-asp": "enable" to the App’s service definition.

  1. Via the Marathon web interface:

    • Click on the App name in the Applications list.
    • Click Configuration.
    • Click Edit.
    • Click Labels.
    • Click the + icon and add the label “f5-asp: enable”.
    • Click Change and deploy configuration.
  2. Via the REST API:

    • Edit the App definition
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    // REMOVE ALL COMMENTS FROM THIS FILE BEFORE USING
    {
      "container": {
        "docker": {
          "portMappings": [
            {
              "servicePort": 11099,
              "protocol": "tcp",
              "containerPort": 80,
              "hostPort": 0
            }
          ],
          "privileged": false,
          "image": "<my-app-image:version>",
          "network": "BRIDGE",
          "forcePullImage": true
        },
        "type": "DOCKER",
        "volumes": []
      },
      "mem": 128,
      // The label below activates the ASP with the default configurations
      "labels": {
        "f5-asp": "enable"
      },
      "cpus": 0.25,
      "instances": 1,
      "upgradeStrategy": {
        "maximumOverCapacity": 1,
        "minimumHealthCapacity": 1
      },
      "id": "demo-app"
    }
    
    • Send a PUT request to the Marathon API server to update the App.
    $ curl -X PUT -H "Content-Type: application/json" http://10.190.25.75:8080/v2/apps/basic-0 -d @app_asp-enabled-defaults.json
    

Launch an ASP instance with custom configurations

Add the label "f5-asp": "enable" to the App’s service definition.

  1. Via the Marathon web interface:

    • Click on the App name in the Applications list.
    • Click Configuration.
    • Click Edit.
    • Click Labels.
    • Click the plus sign icon and add your override labels.
    • Click Change and deploy configuration.
  2. Via the REST API:

    • Add your desired override labels to the App’s service definition.

       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      // REMOVE ALL COMMENTS FROM THIS FILE BEFORE USING
      {
        "container": {
          "docker": {
            "portMappings": [
              {
                // This service port will be the ASP's host port; make sure it is
                // an available port
                "servicePort": 11099,
                "protocol": "tcp",
                "containerPort": 80,
                "hostPort": 0
              }
            ],
            "privileged": false,
            "image": "someImage:version>",
            "network": "BRIDGE",
            "forcePullImage": true
          },
          "type": "DOCKER",
          "volumes": []
        },
        "mem": 128,
        // The labels below activate and configure the ASP
        "labels": {
          "f5-asp": "enable",
          "ASP_LOG_LEVEL": "debug",
          "ASP_VS_KEEP_ALIVE": 50,
          "ASP_VS_FLAGS" : "{ \"x-forwarded-for\": true, \"x-forwarded-by\": true}",
          "ASP_VS_EVENT_HANDLERS": "[{\"http-request\": \"module.exports = (req, res, next) => {\n if (req.method === 'POST') {\n res.statusCode = 503;\n res.end('POST Method not supported');\n } else { \n next(); \n } \n}\n\"}, {\"http-response\": \"module.exports = (res, next) => { res.headers['x-my-bar'] = 'foo'; next(); }\"}]",
          "ASP_COUNT_PER_APP": 2
        },
        "cpus": 0.25,
        "instances": 1,
        "upgradeStrategy": {
          "maximumOverCapacity": 1,
          "minimumHealthCapacity": 1
        },
        "id": "demo-app-custom"
      }
      
    • Send a PUT request to the Marathon API server to update the App definition.

      $ curl -X PUT -H "Content-Type: application/json" http://<marathon-url>:8080/v2/apps -d @app_asp-enabled-custom.json
      

Add Event Handlers

You can add ASP event handlers to the virtual server configuration.

See also

Take the steps below to add event handlers to an ASP.

  1. Define the ASP_VS_EVENT_HANDLERS label with a JSON string.

    Important

    Convert the JSON list to a string, like that shown in the example.

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
      "labels": {
        "f5-asp": "enable",
        "ASP_LOG_LEVEL": "debug",
        "ASP_VS_KEEP_ALIVE": 50,
        "ASP_VS_FLAGS" : "{ \"x-forwarded-for\": true, \"x-forwarded-by\": true}",
        "ASP_VS_EVENT_HANDLERS": "[{\"http-request\": \"module.exports = (req, res, next) => {\n if (req.method === 'POST') {\n res.statusCode = 503;\n res.end('POST Method not supported');\n } else { \n next(); \n } \n}\n\"}, {\"http-response\": \"module.exports = (res, next) => { res.headers['x-my-bar'] = 'foo'; next(); }\"}]",
        "ASP_COUNT_PER_APP": 2
      },
      "cpus": 0.25,
      "instances": 1,
      "upgradeStrategy": {
        "maximumOverCapacity": 1,
    
  2. Deploy the updated service definition to the Marathon API server.

    $ curl -X PUT -H "Content-Type: application/json" http://<marathon-url>:8080/v2/apps -d @app_asp-enabled-custom.json