With Heat, we can create a wide variety of templates from spinning up basic instances, to creating complete environments for an application. In this section, we will show the basics of Heat by spinning up an instance and attaching it to an existing Neutron network, and assigning a floating IP to it. Heat templates describe the resources being used, the type and size of the instances, the network an instance will be attached to, among other pieces of information required to run that environment.
In this section, we will show you how to use a HOT file to spin up two web servers running Apache, connected behind a third instance running HAProxy acting as the load balancer.
Ensure that you are logged onto a correctly configured OpenStack client and can access the OpenStack environment. Refer to Chapter 2, The OpenStack Client, for details of setting up your environment to use Heat.
In this section, we will download a HOT file called cookbook.yaml
, which will describe our instance and the network to attach it to:
wget -O cookbook.yaml https://raw.githubusercontent.com/OpenStackCookbook/OpenStackCookbook/master/cookbook.yaml
parameters: key_name: type: string description: Name of keypair to assign to servers image: type: string description: Name of image to use for servers flavor: type: string description: Flavor to use for servers public_net_id: type: string description: > ID of public network for which floating IP addresses will be allocated private_net_id: type: string description: ID of private network into which servers get deployed private_subnet_id: type: string description: ID of private sub network into which servers get deployed
openstack keypair list openstack image list openstack flavor list openstack network list
The openstack network list
output may look like the following:
cookbook-env.yaml
in the same directory as cookbook.yaml
with the following contents based on the output of the previous commands (adjust to suit your environment):parameters: key_name: demokey image: xenial-image flavor: m1.tiny public_net_id: 2da8979e-dcf8-4eb8-b207-f33bfce4a15a private_net_id: 78a5a119-c27a-41c4-8310-5c04d3a6bc31 private_subnet_id: 3cee2bb9-5673-4a6e-bb1e-8cb66be066b2
Heat Orchestration Templates (HOT) are YAML files that describe our environment, or "Stacks" as they're known. The basic templates generally have the following structure:
description:
parameters:
resources:
outputs:
The description:
section has a number of words that helps a user understand what is expected to occur when the template is used.
The parameters:
section defines the input variables, for example, the type of image(s) to be used, the network(s) to attach the instances on, and the key pair name to associate with the instances. Parameters are arbitrary and can contain any information needed to execute the template properly. The parameters: section works directly with the information found in the accompanying environment file (as specified by the --environment
parameter). Each parameter must either have a default value or be specified in the environment file for the stack to launch successfully.
The resources:
section is usually the biggest section as it describes the environment. It can describe the instances that will be used, the naming of them, which networks to attach, and essentially how all of the elements relate to each other and how the environment is orchestrated. Explanations of how best to write these resources are beyond the scope of this book.
The outputs:
section refers to the "return" values from running the stack. For example, a user will need to know how to access a particular stack that has just been created. Random IPs and hostnames can all be assigned as normal operation of running stacks, so being able to interrogate the right information in order to access the environment is a must.
3.144.110.32