Launching our first Cloud instance
Instances are virtual machines that within the cloud. Now that we have a running OpenStack Compute environment and a machine image to use, it’s now time to spin up our first cloud instance! This section explains how to use the information from the nova image-list commands to refer this on the command line to launch the instance that we want.
The instance can be launched from the following sources:
- Images uploaded to the image service
- Instance snapshot that you took
- An image that has been copied to a persistent volume.
These steps are to be carried out on our Ubuntu machine under the user that has access to our OpenStack Compute credentials (as created in the Installation of command-line tools on Ubuntu recipe).
Before we spin up for our first instance, we must create the default security settings that define the access rights. We do this only once (or when we need to adjust) using the nova sec group-add -rule command under Nova client. The following set of commands gives us SSH access (Port 22) from any IP address and also allows us to ping the instance to help with troubleshooting. Note that the default group and its rules are always applied if no security group is mentioned on the command line.
- With the Nova client installed, we use it by configuring our environment with the appropriate environment variables. We do this as follows:
Add these to a file called novarc in your home area. We can then source these credentials at each time by simply executing . novarc.
- Using Nova Client, we can simply add the appropriate rules using the following commands:
nova sec group-add-rule default
tcp 22 22 0.0.0.0 /0
nova sec group-add-rule default
icmp -1 -1 0.0.0.0 /0
If there are no images available yet, follow the steps of the recipe Managing images with OpenStack Image Service in Chapter 2, Starting OpenStack Image Service.
How to achieve it…
To launch our first instance, our environment must set up correctly, then carry out the following set of commands:
- We first list the images available by executing the following command:
This should produce output like the following screenshot:
- To launch our instance, we need this information and we specify this on the command line. For launching an instance using Nova client tools, we issue the following by using the UUID of our image that is named Ubuntu 12.04 x86_64
nova boot myInstance \
–image 1d8f15b2-ddd8-4816-8610-486bf8fd0eb8 \ –flavor 2 \
- You should see output like the following screenshot when you launch an instance:
- This will take a few brief moments to spin up. To check the status of your instances, issue the following commands:
nova show 67438c9f-4733-4fa5-92fc-7f6712da4fc5
- This brings back output, which is similar to the output of the previous command lines, yet this time it has created the instance and is now running with a certain IP addresses assigned to it:
- After a short while, you will be able to connect to this instance from our host or client where we launched our instance, using SSH, and specifying your private key to gain access:
ssh -i demo.pem email@example.com
The default user that ships with the Ubuntu cloud images is Ubuntu.
Congratulations! We have successfully launched and connected to our first OpenStack Cloud instance.
How it works…
After creating the default security settings, we made a note of our machine image identifier, UUID value, and then called a tool from Nova Client to launch our instance. Part of that command line refers to the key pair to use. We then connect to the instance using the private key as part of that key pair generated.
How does the cloud instance know what key to use? As part of the boot scripts for this image, it makes a call back to the meta- server, which is a function of the nova-api and nova-api-metadata services. The meta-server provides a go-between that bridges, our instance and the real world that the Cloud in it boot process can call . In this case, it downloads a script to inject our private key into the Ubuntu user’s
We can modify scripts that are called during the boot process.
When a cloud instance is launched, it generates a number of useful metrics and details about that instance. This is presented by the nova list and nova show commands. The nova list command shows a convenient short version listing the ID, name, status and IP addresses of our instance.
The type of the instance we chose is specified as an ID of 2 when using the nova boot command. The instance types supported can be listed by running the following command:
These flavors (specification of instances) are summarized as follows:
Enroll for Instructor Led Live OpenStack Training