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
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.
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.
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.
On the network configuration, add the network resource types.
...output omitted... external_network: type:OS::Neutron::Netproperties: name: external_network shared: false port_security_enabled: false external_subnet: type:OS::Neutron::Subnetproperties: 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
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
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.
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
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.
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
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.
Using the developer1 user with the project of production, launch the webapp-stack deployment using the webapp-stack.yaml template file.
On workstation, source the identity environment file for the developer1 user.
[student@workstation ~]$ source developer1-production-rcCreate 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 | +---------------------+---------------------------------------+
Determine if the web application stack was created correctly.
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
}
]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 | +-----------+------------+--------+----------------------------------------------+
Validate the functionality of the web application.
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" | | | ] | | | } | | | } | +---------------+--------------------------------------------------------+
Open a web browser and access the public IP address of the web application.
Add an item to the queue to verify that the application is working.
This concludes the lab.