Update the Template

Using your preferred text editor open the Apache Web Server template you created and modified in the previous tutorials.

Update the Outputs

Update the outputs section to display the IP address of the Load Balancer instead of the Apache Web Server in the two highlighted places below.

##################################################################################################################################################
# This defines the two outputs to appear on the DCM console Stack overview page (IP address and URL of the Load Balancer)
##################################################################################################################################################
outputs:                                                        # Define outputs
  application_group:                                            # Create a Group
    type: dcm.outputs.DisplayGroup                              # It's a displayGroup
    properties:
      displayName: "Apache Web Server Information"              # Set the display name for the group containing the outputs which appears on the Stack Overview page

  vm_ip:                                                        # Define an output
    type: string                                                # It's a string output
    description: IP of the server                               # Set the description for the string output
    value: {get_attribute: [lb, address]}                       # Set the value to the public IP address of the Load Balancer running in the stack
    properties:
      displayName: IP address                                   # Set the display name (label) for the string output
      displayGroup: application_group                           # Place this output in the displayGroup named application_group

  link:                                                         # Define another output
    type: dcm.outputs.Uri                                       # It's a URI output
    value: http://xxxxxxxxxxxxx/index.html                      # Set the initial value
    properties:
      host: {get_attribute: [lb, address]}                      # Set the hostname/ipaddress of the URI to the public IP address of the Load Balancer running in the stack
      displayName: Apache Server URL                            # Set the display name (label) for the URI output
      displayGroup: application_group                           # Place this output in the displayGroup named application_group

Add a Load Balancer

In this tutorial a Load Balancer will be added to the template. Refer to the Load Balancer section in this document for reference.

The Load Balancer will be created and configured to:

  • Use the HTTP network protocol
  • Use the ROUND_ROBIN routing algorithm
  • Listen on port 80
  • Forward the HTTP request to the listeners listening on port 80

Add the following statements to the Apache Web Server template in the node_templates: section. Make sure you align this section with the other nodes in the template (same indentation).

lb:
  type: dcm.nodes.LoadBalancer
  properties:
    name: "acme-lb"                                                          # Name of the Load Balancer
    cloud: { get_input: [account_region_zone_selector, cloud] }              # Retrieve the cloud from the AccountRegionSelector
    cloudAccountId: { get_input: [account_region_zone_selector, accountId] } # Retrieve the cloud account ID from the AccountRegionSelector
    region: { get_input: [account_region_zone_selector, region] }            # Retrieve the region from the AccountRegionSelector
    zone: { get_input: [account_region_zone_selector, zone] }                # Retrieve the zone from the AccountRegionSelector
    configurations:
      - protocol: HTTP                                                       # Use the HTTP protocol
        algorithm: ROUND_ROBIN                                               # Use the Round Robin algorithm to service the listeners
        loadBalancerPort: 80                                                 # The Load Balance will listen on port 80
        instancePort: 80                                                     # Redirect the traffic to the listeners on port 80
    healthCheck:                                                             # Define a health check
          name: port_80_check                                                # Name is port_80_check
          description: "Load Balancer Health Check for Port 80"              # Description for the health check
          protocol: HTTP                                                     # Protocol is HTTP
          port: 80                                                           # Port to contact on the server(s) is 80
          path: /index.html                                                  # Destination for the HTTP or HTTPS request is /index.html
          interval: 120                                                      # Perform a health check every 2 minutes
          timeout: 60                                                        # Amount of time to wait for the response to the health check
          unhealthyCount: 2                                                  # If 2 consecutive health checks fail then mark the server as unhealthy
          healthyCount: 3                                                    # If 3 consecutive health checks succeed then mark the server as healthy
  requirements:
    - member: web_vm                                                         # The virtual machines launched from the node-template named "web_vm"
                                                                             # will be serviced by the Load Balancer

Modify the instances

In this tutorial the Load Balancer will be initially servicing two Apache Web Servers. Modify the instances: and maxInstances: properties and increase their values from 1 to 2 which will create two Apache Web Servers when the stack is launched.

###################################################################################################################################################
# This group defines the auto scaling and auto healing policies for the Apache Web server (web_vm)
###################################################################################################################################################
groups:
  scaling_and_healing_group:
    members: [web_vm]                            # The node_template with the statement named "web_vm" is in this group
    properties:
      instances: 2                               # Launch 2 servers when the stack is started
      minInstances: 2                            # The minimum number of servers
      maxInstances: 5                            # The maximum number of servers
      coolDown: 300                              # The number of seconds to wait before performing a auto scale or auto repair operation.