Create an Instance in OpenStack

Creating an instance in OpenStack using the CLI involves several steps, including setting up your environment, selecting appropriate resources, and issuing the command to create the instance.

Step 1: Source Your OpenStack RC File

First, you need to source your OpenStack RC file to set the necessary environment variables for authentication.

sudo -i -u stack
cd ~/devstack
source openrc <USERNAME> <PROJECT_NAME>

Step 2: Choose an Image

List the available images and note the ID of the image you want to use.

openstack image list

Step 3: Choose a Flavor

List the available flavors and note the ID of the flavor you want to use. Flavors define the compute, memory, and storage capacity of the instances.

openstack flavor list

Step 4: Choose a Network

List the available networks and note the ID of the network you want to connect the instance to.

openstack network list

Step 5: Choose a Key Pair

List the available key pairs and note the name of the key pair you want to use for SSH access to the instance.

openstack keypair list

If you don't have a key pair, you can create one.

ssh-keygen -t ed25519 -C "[email protected]"
openstack keypair create --public-key <KEY_PATH> <KEY_NAME>

Step 6: Create the Instance

Finally, create the instance using the image, flavor, network, and the key pair. You can also specify additional options such as security groups, availability zones, etc.

openstack server create \
--image <IMAGE_NAME> \
--flavor <FLAVOR_ID> \
--network <NETWORK_NAME> \
--key-name <KEY_NAME> \
--block-device source_type=image,uuid=<IMAGE_ID>,destination_type=volume,volume_size=10,delete_on_termination=true \
<INSTANCE_NAME>

For example,

openstack server create \
--image ubuntu-24.04-x86_64 \
--flavor ds1G \
--network my-network \
--key-name my-keypair \
--block-device source_type=image,uuid=6a2ea112-4d31-4a25-bedd-54e235146473,destination_type=volume,volume_size=10,delete_on_termination=true \
my-server

Step 7: Verify Instance Creation

Verify that the instance is running showing the server list. Optionally, inspect the details of the created server and check logs.

openstack server list
openstack server show <INSTANCE_NAME>
openstack console log show <INSTANCE_NAME>

Step 8: Delete Instance

Finally, delete the server when it is not needed anymore.

openstack server delete <INSTANCE_NAME>