Launch and terminate cloud instances

Key Value
Summary Launch and terminate cloud instances.
Categories openstack
Difficulty 1
Author Tytus Kurek tytus.kurek@canonical.com

Overview

Duration: 3:00

Before you get started!

Welcome to OpenStack!

In this series of tutorials, we will walk you through all the necessary steps to install, configure and get started with OpenStack. Using just your workstation, you will learn how to use OpenStack for cloud infrastructure implementation purposes, from a single-node installation to large-scale clusters.

This tutorial is the ninth in the “Phase I - Single-node OpenStack on your workstation” series.

Explore other tutorials >

What is OpenStack?

OpenStack is the most popular open source cloud platform that aggregates distributed compute, network and storage resources in the data centre and enables on-demand provisioning of virtual machines through a self-service portal. OpenStack powers thousands of public and private clouds all over the world, providing rapid access for greater innovation and better economics.

Learn more about OpenStack >

What is MicroStack?

MicroStack is a micro cloud platform based on OpenStack, designed for the edge and small-scale data centre deployments, that can be installed and maintained with minimal effort. MicroStack eliminates the complexity behind OpenStack, providing an opinionated approach to OpenStack architecture design and a straightforward installation method.

Learn more about MicroStack >

What is Charmed OpenStack?

Charmed OpenStack is an enterprise cloud platform based on OpenStack, designed for large-scale data centre deployments, that provides full automation around the initial installation and day-2 operations. Charmed OpenStack abstracts the complexity behind OpenStack, using a composable approach to OpenStack architecture design with model-driven operators (charms).

Learn more about Charmed OpenStack >

In this tutorial, you will learn how to:

  • Launch instances

  • Associate floating IPs

  • Attach security groups

  • Access instances

  • Delete instances

You will only need:

One physical machine with:

MicroStack

These instructions use MicroStack - OpenStack in a snap. MicroStack is also available on other Linux distros, Windows and macOS. Refer to the MicroStack website for more information on how to install MicroStack on other OS than Ubuntu.

Credentials

Duration: 1:00

Make sure you’re logged in as the myuser user we created in tutorial 6. Identities

To log in as the myuser user through the OpenStack client, open a new terminal window, execute the following command and type mypassword when asked for the password:


$ source ~/Downloads/myproject-openrc.sh

To log in as the myuser user through the OpenStack dashboard, visit https://10.20.20.1 and use the following credentials:

  • Domain - Type mydomain

  • User Name - Type myuser

  • Password - Type mypassword

Launch instances

Duration: 5:00

In the following steps, we’ll launch two instances called myinstance-1 and myinstance-2 on the ephemeral storage using the 20.04 image, the myflavor flavor and the mykeypair key pair, attached to the mysubnet subnet with the default security group attached.

Launch instances through the OpenStack client

To launch instances, execute the following command:


$ openstack --insecure server create --flavor myflavor --image 20.04 --network mynetwork --key-name mykeypair --min 2 --max 2 myinstance

Launching instances takes a while. You are going to see that instances go through the BUILD status first.

To list all instances, execute the following command:


$ openstack --insecure server list

Sample output:


+--------------------------------------+--------------+--------+-------------------------+-------+----------+

| ID | Name | Status | Networks | Image | Flavor |

+--------------------------------------+--------------+--------+-------------------------+-------+----------+

| 098b9750-dfcb-41e6-b42e-0aec7ce1452d | myinstance-1 | ACTIVE | mynetwork=192.168.0.168 | 20.04 | myflavor |

| c7293b64-08a8-4598-99b8-16b7fad16d39 | myinstance-2 | ACTIVE | mynetwork=192.168.0.140 | 20.04 | myflavor |

+--------------------------------------+--------------+--------+-------------------------+-------+----------+

Launch instances through the OpenStack dashboard

Navigate to Project -> Compute -> Instances and click the Launch Instance button on the right:

To launch instances, fill in the form as follows:

  • Instance Name - Type myinstance

  • Count - Type 2

Then choose Source from the menu on the left:

Fill in the form as follows:

  • Create New Volume - Choose No

  • Press UP beside 20.04

Then choose Flavor from the menu on the left:

Fill in the form as follows:

  • Press UP beside myflavor

Then click the Launch Instance button:

Launching instances takes a while. You are going to see that instances go through the Scheduling and Spawning stages until they reach the Active status. Once those complete, you will see both instances in Nova’s database:

Associate floating IP

Duration: 2:00

In the following steps, we’ll associate floating IP with the myinstance-1 instance.

Associate floating IP through the OpenStack client

To associate floating IP, execute the following commands:


$ IP=$(openstack floating ip list | tail -n 2 | head -n 1 | awk '{print $4}')

$ openstack --insecure server add floating ip myinstance-1 $IP

Associate floating IP through the OpenStack dashboard

Navigate to Project -> Compute -> Instances. Then, under the Actions column beside myinstance-1, select Associate Floating IP from the drop-down menu:

To associate floating IP, fill in the form as follows:

  • IP Address - Select the available IP address from the drop-down menu (10.20.20.78 in this case)

Then click the Associate button:

You are now able to see the floating IP being associated with the instance:

Attach security group

Duration: 4:00

In the following steps, we’ll attempt to SSH to the myinstance-1 instance using the mykeypair.pem private key we’ve downloaded in tutorial 7. Multi-tenancy.

First, we need to narrow down the default permissions in the mykeypair.pem file. To set the right permissions, execute the following command:


$ chmod 0400 /home/guardian/Downloads/mykeypair.pem

To attempt to SSH to the instance, execute the following commands:


$ IP=$(openstack floating ip list | tail -n 2 | head -n 1 | awk '{print $4}')

$ ssh -i ~/Downloads/mykeypair.pem -o StrictHostKeyChecking=no ubuntu@$IP

Sample output:


ssh: connect to host 10.20.20.70 port 22: Connection timed out

The connection was unsuccessful. The reason behind this is that the default security group does not allow ingress SSH connections. In order to SSH to the instance, we can attach the mysecuritygroup security group we created in tutorial 8. Network.

In the following steps, we’ll attach the mysecuritygroup security group to the myinstance-1 instance.

Attach security group through the OpenStack client

To attach a security group, execute the following command:


$ openstack --insecure server add security group myinstance-1 mysecuritygroup

Attach security group through the OpenStack dashboard

Navigate to Project -> Compute -> Instances. Then, under the Actions column beside myinstance-1, select Edit Security Groups from the drop-down menu:

To attach the mysecuritygroup security group, fill in the form as follows:

  • All Security Groups - Press the + button beside mysecuritygroup

Then click the Save button:

Access instances

Duration: 1:00

At this point, you are able to SSH to the myinstance-1 instance:

To attempt to SSH to the instance, execute the following commands:


$ IP=$(openstack floating ip list | tail -n 2 | head -n 1 | awk '{print $4}')

$ ssh -i ~/Downloads/mykeypair.pem -o StrictHostKeyChecking=no ubuntu@$IP

Sample output:


Warning: Permanently added '10.20.20.70' (ECDSA) to the list of known hosts.

Welcome to Ubuntu 20.04.3 LTS (GNU/Linux 5.4.0-1047-kvm x86_64)

* Documentation: https://help.ubuntu.com

* Management: https://landscape.canonical.com

* Support: https://ubuntu.com/advantage

System information as of Tue Sep 28 11:40:43 UTC 2021

System load: 0.6 Processes: 68

Usage of /: 12.7% of 9.52GB Users logged in: 0

Memory usage: 14% IPv4 address for ens3: 192.168.0.168

Swap usage: 0%

1 update can be applied immediately.

To see these additional updates run: apt list --upgradable

The programs included with the Ubuntu system are free software;

the exact distribution terms for each program are described in the

individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by

applicable law.

To run a command as administrator (user "root"), use "sudo <command>".

See "man sudo_root" for details.

ubuntu@myinstance-1:~$

To disconnect from the instance, type exit (or press CTRL+D).

Delete instances

Duration: 2:00

In the following steps, we’ll delete the myinstance-2 instance.

Delete instances through the OpenStack client

To delete the instance, execute the following command:


$ openstack --insecure server delete myinstance-2

Delete instances through the OpenStack dashboard

Navigate to Project -> Compute -> Instances. Then, under the Actions column beside myinstance-1, select Delete Instance from the drop-down menu:

To delete the instance, click the Delete Instance button:

The myinstance-2 instance is no longer shown in Nova’s database:

Next steps

Duration: 2:00

Congratulations! You have reached the end of this tutorial.

You can now move to the next tutorial - “10. Storage” - or explore other tutorials.

In this tutorial, you have learnt how to:

  • Launch instances

  • Associate floating IPs

  • Attach security groups

  • Access instances

  • Delete instances

Where to go from here?