Creating your first stack

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.

Getting ready

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.

How to do it...

In this section, we will download a HOT file called cookbook.yaml, which will describe our instance and the network to attach it to:

  1. First, we download the HOT file from the Cookbook GitHub repository:
    wget -O cookbook.yaml 
    https://raw.githubusercontent.com/OpenStackCookbook/OpenStackCookbook/master/cookbook.yaml
    
  2. Heat takes input parameters from the command line, or from an environment file, which get passed to the template. These parameters are seen at the top of the HOT file, as shown here:
    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
  3. As can be seen, we expect to pass in various parameters when we launch this template. Ensure that we have these details by running the following commands:
    openstack keypair list
    openstack image list
    openstack flavor list
    openstack network list
    

    The openstack network list output may look like the following:

    How to do it...
  4. With the information at hand, we create an environment file that will be used to store our parameters that we will pass to the HOT file when we launch the stack. Create 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

How it works...

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.26.152