Get an OpenStack Instance Up and Running in 40 Minutes or Less

810

Once you have followed the previous tutorial and have OpenStack installed using the distribution of your choice, it’s time to get some instances running.

First, you’ll want to choose how you’d like to work with OpenStack:

  • Using the Horizon Browser User Interface (BUI), which provides easy authentication and accessibility to all components.

  • Using the OpenStack Command from the command line interface (CLI), in which case you’ll need to set up some items before you can get started in the user credential file.

I like to work from the CLI, because the openstack command gives access to all of the available options, whereas when working from the BUI you’ll notice that some of the advanced options are not available.

Create a Credentials File

Before you can start working with instances, you’ll need to to create a Project or Tenant. A project (which previously was referred to as a Tenant) is the environment that is created for a customer in OpenStack. This needs to be done as the OpenStack admin user, and to keep it easy on yourself, I’d recommend creating this user from the Horizon web interface. Make sure you’re logged in as admin, and next under Identity you’ll be able to add a project, a user in that project and assign the user as a member to the project.

Screen Shot 2017-05-23 at 10.32.32.png

For working with OpenStack, it’s important to realize which set of credentials you should use. In OpenStack, Admin credentials are typically used to create infrastructure while Tenant user credentials are typically used to create instances. So to spin off an instance, you’ll need to make sure that you have user credentials.

Before you can do anything with the CLI, you’ll need to create a credentials file that sets Linux shell variables and then source that file so that the environment variables will become available in your current shell environment. Such a credentials file can have the following contents, assuming you want to create a project with the name project1, in which a user with the name user1 and password “password” can do his work:

unset SERVICE_TOKEN SERVICE_ENDPOINT

export OS_USERNAME=user1

export OS_TENANT_NAME=project1

export OS_PASSWORD=password

export OS_AUTH_URL=http://server1.example.com:35357/v2.0/

export PS1='[u@h W(keystone_user1)]$ 

source ~/keystonerc_user1

Steps to Creating an OpenStack Instance

Now we’re ready to create an instance. An instance is based on an image that is joined with a flavor and a volume and connected to a private network. To implement it, some steps need to be applied:

  • Get an image (Glance)

  • Assign a Template

  • Find out which internal network you can use to connect the instance to

  • Assign a Security Group

  • Add an SSH Key

  • Add a Floating IP address

  • Boot the instance

Here are the OpenStack commands to carry out the steps, above:

  1. source /root/keystonerc_user: This command will give you the required credentials to work as user in OpenStack.

  2. openstack keypair create key1 > /root/key1: This command creates an SSH key-pair and includes it in OpenStack, so that users can later log in to the instance using the SSH key.

  3. openstack security group create mysecgroup: Use this command to create a security group, which basically is a firewall.

  4. nova secgroup-add-rule mysecgroup tcp 22 22 0.0.0.0/0: This command opens the security group firewall rules for SSH traffic.

  5. wget https://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img: This downloads a bootable Cirros image to your local machine.

  6. glance image-create --name cirros1 --disk-format qcow2 --container-format bare --file cirros[Tab] : Use this to import the image file you’ve just downloaded into Glance so that you can use it to spin of your instance.

  7. nova flavor-list : A flavor is a hardware profile. Use this command to display a list of flavors and select the flavor you want to use. For a small test environment, I’d recommend the m1.tiny flavor as it has the minimal settings that are required to boot an instance.

  8. neutron net-list : Notice the ID of the private network to which you are going to connect the instance.

  9. nova boot --flavor m1.tiny --image cirros1--key-name key1 --security-group mysecgroup --nic net-id=<NET-ID> myvm1 : This command will boot the instance, using the components that were discussed earlier in this procedure.

  10. nova list : This command verifies that the instance has indeed booted successfully. Notice that it may take a few seconds before the instance will show “Up” in its state.

Conclusion

Now that you’ve installed OpenStack and started some instances, let’s talk about how to enable Docker containers in OpenStack. Containers are ready-to-run applications, including the entire stack that’s required to run them. Learning how to run and manage containers is key to making the most of the OpenStack platform for scale-out applications — a topic that we’ll explore in part 3 of this series.

Now updated for OpenStack Newton! Our Essentials of OpenStack Administration course teaches you everything you need to know to create and manage private and public clouds with OpenStack. Download a sample chapter today!