Launching our first cloud instance

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! Let’s see how we can use the information from the nova image-list and nova flavor-list commands to reference this on the command line to launch the instance that we want.

Getting ready

The following steps are to be carried out on our network node under the user that has access to our OpenStack Compute credentials (as created in the Installation of command-line tools on network recipe).

Ensure you are logged in to the network node and that it has Internet access to allow us to install the required packages in our environment for running OVS and Neutron. If you created this node with Vagrant, you can execute the following command:

vagrant ssh network

Before we spin up 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 these) using the nova secgroup-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 the default group and its rules are always applied if no security group is mentioned on the command line.

The steps are as follows:

  1. With the Nova client installed, we use them by configuring our environment with the appropriate environment variables:
    export OS_TENANT_NAME=cookbook
    export OS_USERNAME=admin
    export OS_PASSWORD=openstack
    export OS_AUTH_URL=https://192.168.100.200:5000/v2.0/
    export OS_NO_CACHE=1
    export OS_KEY=/vagrant/cakey.pem
    export OS_CACERT=/vagrant/ca.pem

    Tip

    Add these to a file called novarc in your home area. We can then source these credentials in each time by simply executing the source novarc command.

  2. Using Nova client, we can simply add the appropriate rules using the following commands:
    nova secgroup-add-rule default tcp 22 22 0.0.0.0/0
    nova secgroup-add-rule default icmp -1 -1 0.0.0.0/0
    

    Note

    If there are no images available yet, follow the steps of the recipe Managing images with OpenStack Image Service in Chapter 2, Glance – OpenStack Image Service.

How to do it...

Now that our environment is set up correctly, we carry out the following steps to launch our first instance:

  1. List the images available by executing the following command:
    nova image-list
    

    This should produce an output like this:

    How to do it...
  2. Then, we get the available image flavors (think of them as sizes) by executing the following command:
    nova flavor-list
    

    Available flavors for our OpenStack installation will be listed like this:

    How to do it...

    We can specify flavor either by its ID or name.

  3. Since our lab environment is configured to with two networks, we will need to choose to which network to attach our instance. First, list the available networks using the following command:
    neutron net-list
    

    The available networks will be displayed like this:

    How to do it...
  4. To launch our instance, we need to specify image, flavor, network, and key name information we got earlier on the command line. To launch an instance using Nova client tools, we issue the following command using the UUID of our image that is named trusty-image and cookbook_network_1:
    nova boot myInstance 
        --image 5bfb4a6d-da77-4502-ba52-2e8e40597e96 
        --flavor 2 
        --nic net-id=0375e772-b021-425c-bc17-5a3263247fb8 
        --key_name demokey  
    

    You should see output like the following screenshot when you launch an instance:

    How to do it...
  5. This will take a few brief moments to spin up. To check the status of your instances, issue the following commands:
    nova list
    nova show 5971ab77-9d91-40d8-9961-d86da0945f26
    
  6. The preceding commands will give an output similar to the output of the previous command lines. However, this time it has created the instance, it is now running, and it has IP addresses assigned to it:
    How to do it...
  7. After a short while, you will be able to connect to this instance. If you are using the Vagrant environment, from the network node, you will be able to connect to the instance using network space and SSH private key. First, get a list of network spaces using the following command:
    ip netns
    

    This will show the following example output:

    qdhcp-0375e772-b021-425c-bc17-5a3263247fb8
    

    Now, connect to the instance using the following command:

    sudo ip netns exec 
       qdhcp-0375e772-b021-425c-bc17-5a3263247fb8 
       ssh -i demokey [email protected]
    

    Tip

    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 init boot process can call. In this case, it downloads a script to inject our private key into the Ubuntu user’s .ssh/authorized_keys file. We can modify which scripts are called during this boot process, and this will be covered later on.

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 instance we chose was specified as an ID of 2 when using the nova boot command. The instance types supported can be listed by running the following command:

nova flavor-list

These flavors (specification of instances) are summarized as follows:

Type of instance

Memory

VCPUS

Storage

Version

m1.tiny

512 MB

1

1 GB

32-bit and 64-bit

m1.small

2048 MB

1

20 GB

32-bit and 64-bit

m1.medium

4096 MB

2

40 GB

64-bit only

m1.large

8192 MB

4

80 GB

64-bit only

m1.xlarge

16384 MB

8

160 GB

64-bit only

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

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