Bookmark this page

Lab: Automating a Customized Cloud Application Launch

In this lab, you will launch a 3-tier application stack, with instances customized using cloud-init, and verify that each application component tier functions correctly.

Outcomes

You should be able to:

  • Verify that the HOT file contains what is necessary for the deployment of the stack.

  • Customize stack instances using cloud-init.

  • Verify the functionality of the application components of each tier of the stack.

  • Validate the operation of the web application.

As the student user on the workstation machine, use the lab command to prepare your system for this lab.

This command ensures that all resources required for the exercise are present.

[student@workstation ~]$ lab cloudapps-review start

Procedure 8.3. Instructions

  1. As the student user, edit the webapp-stack.yaml template file and fill the fields with the missing data. The template file is written in YAML and requires specific spacing and indentation.

    Note

    A completed version of the template is provided as /home/student/webapp-stack-complete.yaml and may be used instead of creating the requested files in this exercise.

    1. Edit the template file by adding the missing parameter.

      [student@workstation ~]$ vi webapp-stack.yaml
      ...output omitted...
      parameters:
        public_net_id:
        type: string
        description: Private network into which servers get deployed
        default: provider-datacentre

      Do not save the changes yet and continue editing the template.

    2. On the network configuration, add the network resource types.

      ...output omitted...
      external_network:
        type: OS::Neutron::Net
        properties:
        name: external_network
        shared: false
        port_security_enabled: false
      
      external_subnet:
        type: OS::Neutron::Subnet
        properties:
        name: sub-external
        network_id:
          get_resource: external_network
        cidr: 192.168.7.0/24
        gateway_ip: 192.168.7.1
        enable_dhcp: 'True'
        dns_nameservers:
        - 172.25.250.254
    3. Edit the webapp-stack.yaml file, on the database tier instance configuration, add the resource type and the database port.

      [student@workstation ~]$ vi webapp-stack.yaml
      ...output omitted...
      database_server:
        type: OS::Nova::Server
    4. On the application tier instance configuration, add the resource type.

      ...output omitted...
      app_server::
        type: OS::Nova::Server
      ...output omitted...
                      port: "3306"
                      dialect: 'mysql'
                    }

      Save the changes and close the template file.

  2. Customize the database tier instance with the following script.

    #!/bin/bash
    cat << EOF | mysql -u root
    GRANT ALL PRIVILEGES ON todo.* TO 'db_user'@'%' \
    IDENTIFIED BY 'db_pass';
    FLUSH PRIVILEGES;
    TRUNCATE todo.Item;
    EOF
    1. Edit the template file by adding the user data required in the database tier instance configuration.

      [student@workstation ~]$ vi webapp-stack.yaml
      ...output omitted...
            user_data_format: RAW
            user_data:
              str_replace:
                template: |
                  #!/bin/bash
                  cat << EOF | mysql -u root
                  GRANT ALL PRIVILEGES ON todo.* TO 'db_user'@'%' \
                  IDENTIFIED BY 'db_pass';
                  FLUSH PRIVILEGES;
                  TRUNCATE todo.Item;
                  EOF

      Save the changes and close the template file.

  3. Customize the web tier instance with the following script.

    #!/bin/bash
    sysctl /proc/sys/net/ipv4/ip_forward=1
    sysctl net.ipv4.conf.all.forwarding=1
    echo "net.ipv4.conf.all.forwarding=1" >> /etc/sysctl.d/99-sysctl.conf
    sysctl -p
    sysctl --system
    firewall-offline-cmd --zone=public \
    --add-forward-port=port=30080:proto=tcp:toport=30080:toaddr=192.168.8.10
    firewall-offline-cmd --zone=public --add-masquerade
    firewall-offline-cmd --zone=public --add-port=80/tcp
    systemctl enable firewalld
    systemctl start firewalld
    /usr/bin/sed -i s-192.168.173.187-172.25.250.174-g \
    /var/www/html/script/item.js
    1. Edit the template file, adding the user data required in the web tier instance configuration.

      [student@workstation ~]$ vi webapp-stack.yaml
      ...output omitted...
        web_config:
          type: OS::Heat::SoftwareConfig
          properties:
            group: ungrouped
            config: |
              #!/bin/bash
              sysctl /proc/sys/net/ipv4/ip_forward=1
              sysctl net.ipv4.conf.all.forwarding=1
              echo "net.ipv4.conf.all.forwarding=1" >> /etc/sysctl.d/99-sysctl.conf
              sysctl -p
              sysctl --system
              firewall-offline-cmd --zone=public \
              --add-forward-port=port=30080:proto=tcp:toport=30080:toaddr=192.168.8.10
              firewall-offline-cmd --zone=public --add-masquerade
              firewall-offline-cmd --zone=public --add-port=80/tcp
              systemctl enable firewalld
              systemctl start firewalld
              /usr/bin/sed -i s-192.168.173.187-172.25.250.174-g \
              /var/www/html/script/item.js

      Save the changes and close the template file.

  4. Using the developer1 user with the project of production, launch the webapp-stack deployment using the webapp-stack.yaml template file.

    1. On workstation, source the identity environment file for the developer1 user.

      [student@workstation ~]$ source developer1-production-rc
    2. Create the webapp-stack stack.

      [student@workstation ~(developer1-production)]$ openstack stack create \
      > --template webapp-stack.yaml webapp-stack
      +---------------------+---------------------------------------+
      | Field               | Value                                 |
      +---------------------+---------------------------------------+
      | id                  | 42d64a20-a2cf-4f1c-920d-04244b93680e  |
      | stack_name          | webapp-stack                          |
      | description         | This HOT template defines the 3-tier  |
      |                     | web application stack for the         |
      |                     | Application Issue Tracker.            |
      |                     |                                       |
      | creation_time       | 2020-09-03T17:33:10Z                  |
      | updated_time        | None                                  |
      | stack_status        | CREATE_IN_PROGRESS                    |
      | stack_status_reason | Stack CREATE started                  |
      +---------------------+---------------------------------------+
  5. Determine if the web application stack was created correctly.

    1. Verify that the web application stack has finished correctly, using the openstack stack list command.

      [student@workstation ~(developer1-production)]$ openstack stack list -f json
      [
        {
          "ID": "42d64a20-a2cf-4f1c-920d-04244b93680e",
          "Stack Name": "webapp-stack",
          "Project": "6dc0ec15468d47228d20d81d7bdd3302",
          "Stack Status": "CREATE_COMPLETE",
          "Creation Time": "2020-09-03T17:33:10Z",
          "Updated Time": null
        }
      ]
    2. Confirm the creation of each tier instance.

      [student@workstation ~(developer1-production)]$ openstack server list \
      > -c ID -c Name -c Status -c Networks
      +-----------+------------+--------+----------------------------------------------+
      | ID        | Name       | Status | Networks                                     |
      +-----------+------------+--------+----------------------------------------------+
      | fc2...9fc | database   | ACTIVE | app_db=192.168.9.10                          |
      | 76x...c52 | web        | ACTIVE | external_network=192.168.7.10, 172.25.250.174|
      | 4f8...f17 | app_server | ACTIVE | app_app=192.168.8.10                         |
      +-----------+------------+--------+----------------------------------------------+
  6. Validate the functionality of the web application.

    1. Determine the public IP address of the web application, using the stack creation output.

      [student@workstation ~(developer1-production)]$ openstack stack output show \
      > --all webapp-stack
      +---------------+--------------------------------------------------------+
      | Field         | Value                                                  |
      +---------------+--------------------------------------------------------+
      | app_public_ip | {                                                      |
      |               |   "output_key": "app_public_ip",                       |
      |               |   "description": "Floating IP address of webapp in     |
      |               |                  public network",                      |
      |               |   "output_value": {                                    |
      |               |     "external_network": [                              |
      |               |       "192.168.7.10",                                  |
      |               |       "172.25.250.174"                                 |
      |               |     ],                                                 |
      |               |     "367a37dc-16c1-4f8f-a41f-85f39501d638": [          |
      |               |       "192.168.7.10",                                  |
      |               |       "172.25.250.174"                                 |
      |               |     ]                                                  |
      |               |   }                                                    |
      |               | }                                                      |
      +---------------+--------------------------------------------------------+
    2. Open a web browser and access the public IP address of the web application.

    3. Add an item to the queue to verify that the application is working.

Evaluation

Grade your work by running the lab command from your workstation machine. Correct any reported failures and rerun the script until successful.

[student@workstation ~]$ lab cloudapps-review grade

Finish

On the workstation machine, use the lab command to complete this exercise. This is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab cloudapps-review finish

This concludes the lab.

Revision: cl110-16.1-4c76154