Step-by-Step Guide to Creating a VM in OpenStack:
2. Select or Upload an Image:
4. Select or Create a Flavor:
8. Access the VM:
1. Log in to OpenStack CLI:
The first step is to log into the OpenStack command-line interface (CLI) by sourcing your OpenStack RC file. This file contains the credentials and environment variables necessary to authenticate you with OpenStack services.
# source <your-openrc-file.sh>
VMs in OpenStack are booted from pre-defined images. You can either use an available image or upload your own.
List available images:
# openstack image list
Upload a new image:# openstack image create --disk-format qcow2 --container-format bare --file <IMAGE_PATH> <IMAGE_NAME>
This ensures you have the correct image available for booting the VM.3. Create or Choose a Network:
A VM needs to be attached to a network for connectivity. If you don't have one, you can create a new network.
Create a network:
# openstack network create <NETWORK_NAME>
Create a subnet for the network:# openstack subnet create --network <NETWORK_NAME> --subnet-range 192.168.0.0/24 <SUBNET_NAME>
Flavors in OpenStack determine the size of the VM, specifying the number of vCPUs, memory, and disk space.
List available flavors:
5. Set Up Security Groups:
# openstack flavor list
Create a new flavor (if required):# openstack flavor create --ram 2048 --vcpus 2 --disk 20 <FLAVOR_NAME>
Security groups act as virtual firewalls, controlling incoming and outgoing traffic for your VM.
List existing security groups:
6. Launch the VM:
# openstack security group list
Create a new security group:#openstack security group create <SECURITY_GROUP_NAME>
Add rules to allow traffic (e.g., SSH):# openstack security group rule create --proto tcp --dst-port 22 <SECURITY_GROUP_ID>
Now that you have selected an image, network, flavor, and security group, it’s time to launch the VM.
Launch a VM:
# openstack server create --flavor <FLAVOR_ID> --image <IMAGE_ID> --network <NETWORK_ID> --security-group <SEC_GROUP_ID> --key-name <KEY_NAME> <VM_NAME>
Check the VM status:# openstack server list
Once the status changes to ACTIVE, the VM is successfully running. 7. Assign a Floating IP (Optional):
To access the VM externally, you can associate a floating IP with it.
Create a floating IP:
# openstack floating ip create <EXTERNAL_NETWORK>
Assign the floating IP:# openstack server add floating ip <VM_ID> <FLOATING_IP>
Once the VM is up and running with a floating IP, you can SSH into the instance:
# ssh -i <KEY_FILE> <USERNAME>@<FLOATING_IP>
Comments
Post a Comment