Load balancer

To use the application load balancer cloudlet, create a conditional origin, load balancer configuration, and define its match rules.

Note: You should have a separate conditional origin for each data center included in your load balancer configuration.

1. Create conditional origin

Conditional origins represent data centers to which the load balancer forwards incoming traffic. Their behavior and criteria are defined in your property's rule tree.

  1. Get your property's rule tree files as a set of JSON files.

    Get-PropertyRules -PropertyName "my-property" -PropertyVersion latest -OutputDirectory "./property-rules
    
  2. Create a Cloudlets_Origin_Group.json file and place it in the returned property-snippets directory.

  3. Define a Cloudlets Origin Group rule. Add at least one instance of the Cloudlets Origin Definition rule as a child along with the behavior and criteria that fit your business need.

    Use the references to fill out the options for each.


    {
      "name": "Cloudlets Origin Group",
      "children": [
          {
              "name": "Cloudlets Origin Definition",
              "children": [],
              "behaviors": [
                  {
                      "name": "origin",
                      "options": {}
                  },
                  {
                      "name": "cpCode",
                      "options": {}
                  }
              ],
              "criteria": [
                  {
                      "name": "cloudletsOrigin",
                      "options": {}
                  }
              ],
              "criteriaMustSatisfy": "all"
          }
      ],
      "behaviors": [
          {
              "name": "allowCloudletsOrigins",
              "options": {}
          }
      ],
      "criteria": [],
      "criteriaMustSatisfy": "all"
    }
    
  4. In your rules' main.json, add a variable to your new rule in the default rule's children array.

    ...
    
    "children": [
      "#include:Cloudlets_Origin_Group.json"
    ]
    ...
    
    
  5. Update your property's rules, pointing to the property snippet directory.

    Send your entire rule tree back. Rules not returned are removed from your property.
    Set-PropertyRules -PropertyName "my-property" -PropertyVersion latest -InputDirectory "./property-rules/property-snippets" -VersionNotes "Adding conditional origin"
    

    The output returns your rule tree along with any errors or warnings on upload. Set the cmdlet output to a variable to use downstream.

  6. The origin must be in an active property to create a load balancer configuration.

    Provide a value for the network, staging or production, and activate your property.

    New-PropertyActivation -PropertyName "my-property" -PropertyVersion latest -Network staging
    
    activationLink: /papi/v0/properties/prp_98765/activations/atv_76543?contractId=ctr_C-0N7RAC7&groupId=grp_12345  
    

When your property is activated, create and add a load balancer configuration.

2. Create a load balancer

Pass your conditional origin's ID and an optional description to create a load balancer.

Note: This creates a load balancer without a configuration.

New-CloudletLoadBalancer -OriginID "my_OriginID" -Description "Created new load balancer"
originId    : "my_OriginID"
akamaized   : False
checksum    : ab1cde2fgh3i4567890j1k23456lmn78
description : Created new load balancer
type        : APPLICATION_LOAD_BALANCER

Configure your load balancer using an existing configuration as is, get and make updates to an existing configuration, or create a new one.

3. Configure your load balancer

Define the settings for your load balancer's balance type, data centers, and liveliness.

Create new

The load balancer you created without a configuration counts as its first version. The new configuration you define uses a new version cmdlet to associate your configuration with your load balancer, creating a subsequent version.

  1. Pass the required and optional properties that fit your business needs, setting the output to a variable.

    $MyALBConfig = @{
    description = "Initial configuration for testing"
    balancingType = "WEIGHTED"
    dataCenters = {
      city = "Boston"
      cloudServerHostHeaderOverride = false
      cloudService = true
      continent = "NA"
      country = "US"
      hostname = my_alb_config.com
      latitude = 42.3601
      liveness_hosts = ("my_liveness_host.com")
      longitude = 71.0589
      originId = "my_OriginID"
      percent = 100
      state_or_province = "MA"
      }
    livenessSettings = {
      port = 80
      protocol = HTTP
      path = "/status"
      host_header = header
      interval = 10
      requestString = "my_request_string"
      responseString = "my_response_string"
      }
    }
    
    $MyALBConfig = New-CloudletLoadBalancerVersion -OriginID "my_OriginID" -Body $MyALBConfig 
    
    $MyALBConfig = New-CloudletLoadBalancerVersion -OriginID "my_OriginID" -Body '{@{"description": "Initial configuration for testing","balancingType": "WEIGHTED","dataCenters": {"city": "Boston","cloudServerHostHeaderOverride": false,"cloudService": true,"continent": "NA","country": "US","hostname": "my_alb_config.com","latitude": 42.3601,"liveness_hosts": ["example"],"longitude": 71.0589,"originId": "myConditionalOrigin","percent": 100,"state_or_province": "MA"},"livenessSettings": {"port": 80,"protocol": "HTTP","path": "/status","host_header": "header","interval": 10,"requestString": "my_request_string","responseString": "my_response_string"}}}'
    

    Until you activate the configuration, you can continue to make changes and send your updates through the Set-CloudletLoadBalancerVersion</code> cmdlet until you're ready to activate it.

  2. Activate your new version to use your configured load balancer on a network.

Use existing

To use an existing configuration on a new load balancer or update an existing configuration, the configuration cannot be or have ever been active.

If you're not sure what state your configuration is in, step one gets a configuration and asks you set it to a variable. Review the returned immutable property.

  • A value of true requires you create a new version of the configuration before you can associate any changes.
  • A value of false allows you to make and send changes to the configuration until you're ready to activate it.

There is potential to overwrite changes or get an error on update due to an activation when multiple people work on the same configuration at the same time.
  1. Use the version parameter along with an origin ID to get an existing configuration, setting the output to a variable.

    $MyALBConfig = Get-CloudletLoadBalancingVersion -OriginID "my_originID" -Version latest
    
  2. To make changes, use the set version cmdlet to update your configuration until you're ready to activate it.

    Use dot notation to update a single property within your configuration's variable.

    Set-CloudletLoadBalancerVersion -OriginID "my_originID" -Version latest $MyALBConfig
    
  3. To use the configuration as is, associate the configuration to your load balancer using the new version cmdlet.

    New-CloudletLoadBalancerVersion -OriginID "my_OriginID" -Body $MyALBConfig
    
  4. Activate your new version to use your configured load balancer on a network.

4. Activate version

To start serving traffic using your load balancer on a network, pass your origin ID, a version value of latest, and which network, PRODUCTION or STAGING, on which to activate your configuration.

You can also use the DryRun switch to validate the configuration without activating it.
New-CloudletLoadBalancerActivation -OriginID "my_OriginID" -Network STAGING -Version latest