Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
January 4, 2022 02:42 pm GMT

Introduction to OpenStack with MicroStack

In this article, we will learn what OpenStack is, followed by a hands-on session where we install MicroStack in our local development environment and explore some basic features of MicroStack.

Prerequisites

Due to the nature of OpenStack, this hands-on session has non-trivial system requirements on top of knowledge and skill requirements.

Knowledge and skill requirements

It is assumed that you:

  • Are comfortable with the Linux command line and troubleshooting
  • Understand the core concepts behind hardware virtualization; practical experience with a production-grade hypervisor such as VMware Workstation or KVM would be beneficial
  • Understand the core concepts behind cloud computing, in particular IaaS; practical experience with a public cloud provider such as AWS, Azure or GCP would be beneficial

System requirements

It is assumed that your local development desktop or laptop:

  • Has at least 2 CPU cores; 4 or more recommended
  • Has at least 8 GiB of RAM; 16 GiB or more recommended
  • Has at least 100 GiB of available storage
  • Is running a sufficiently recent version of Ubuntu, or another Linux distribution where Snap packages are supported

In particular, if your desktop / laptop does not satisfy the last requirement (e.g. if you are running Windows or macOS), it should contain enough hardware resources to run a VM satisfying the requirements above, with hardware acceleration and nested virtualization enabled, so that you can run VMs inside that VM. Either way, YMMV.

Another possible solution if you do not meet the system requirements is to provision a bare metal instance on a public cloud such as AWS, Azure or GCP. For example, AWS offers a range of bare metal instances powered by AWS Nitro. However, do note that bare metal pricing is orders of magnitude greater than most other instance types, ranging from USD $4.00 per hour upwards. If you're ready to spend hundreds of dollars on a simple tutorial like this one, by all means, go ahead, so long as you are fully aware that you are solely responsible for any and all monetary costs incurred ;-)

With the prerequisites addressed, let's get started!

OpenStack

Reference: OpenStack

The official OpenStack website describes the project as "a cloud operating system that controls large pools of compute, storage, and networking resources throughout a datacenter, all managed and provisioned through APIs with common authentication mechanisms". Simply put, it is an open source platform designed to function as a private (or public) cloud. Typically, OpenStack would be deployed on a fleet of production-grade servers in a datacenter (or datacenters), though in this article we'll see how we can set up our own single-node micro cloud with MicroStack, a beta offering (at the time of writing) by Canonical, the company behind one of the most successful Linux distributions ever - Ubuntu.

Image description

Figure: Our own (micro) cloud in a bottle desktop / laptop. How cool is that? Credits to Steve Spangler Science for the image

OpenStack is a project under the Open Infrastructure Foundation, a non-profit organization founded for this purpose, though it has expanded to house related open source projects such as Airship and Kata Containers as well. OpenStack is licensed under the open source Apache 2.0 license and its source code can be found on GitHub or through the official website.

MicroStack

Reference: MicroStack

OpenStack is comprised of a collection of components known as services that can be selectively deployed to provide APIs to access various types of infrastructure resources, which you can learn about through the official website. For this reason, among others, deploying OpenStack is not a trivial task.

MicroStack is Canonical's distribution of OpenStack made simple and accessible, similar to how Ubuntu is a distribution of Linux made simple and accessible to the average user (also offered by Canonical). In a moment, we'll see how installing MicroStack is as simple as running a single snap install command, and initializing it for use is equally simple as well, also requiring a single command. No wonder the project describes itself as follows:

The most straightforward OpenStack ever.

Apart from being a great introduction to OpenStack, MicroStack can also be used for:

  • Micro-clouds consisting of a small number (not necessarily just 1) of nodes
  • Edge computing
  • Continuous Integration / Continuous Delivery (CI / CD) pipelines

For a larger number of nodes such as would be found in a typical datacenter, other distributions such as Charmed OpenStack (also offered by Canonical) or Red Hat OpenStack Platform (RHOP) may be more suitable, many of which are bundled with commercial support.

Anyway, enough talk - let's get our hands dirty ;-)

Installing MicroStack and provisioning our first instance

Reference: Get started with MicroStack

First ensure snapd is installed on your system. If you're on a sufficiently recent version of Ubuntu, snapd is already installed by default and you do not have to do anything. Otherwise, you may have refer to the link above and follow the instructions specific to your distribution.

MicroStack is currently in beta. Install it from the beta channel in devmode:

$ sudo snap install microstack --devmode --beta

Once that completes, initialize it:

$ sudo microstack init --auto --control

This may take about 20 minutes or more to complete, depending on your hardware specs. On my MacBook Air from 2013 with 4 GiB of RAM and 2 CPU cores (4 CPU threads), it took about 45 minutes and running the above command twice before it successfully executed to completion.

Once complete, you should see the following line at the end:

2022-01-03 21:32:49,907 - microstack_init - INFO - Complete. Marked microstack as initialized!

Check the version:

$ microstack.openstack --version

Print a (very long!) help message:

$ microstack.openstack --help

Now let's launch our first instance. Here, we use the CirrOS image, a minimal Linux distribution specifically designed as a test image for use in OpenStack. We'll call the instance test:

$ microstack launch cirros --name testCreating local "microstack" ssh key at /home/donaldsebleung/snap/microstack/common/.ssh/id_microstackLaunching server ...Allocating floating ip ...Server test launched! (status is BUILD)Access it with `ssh -i /home/donaldsebleung/snap/microstack/common/.ssh/id_microstack [email protected]`You can also visit the OpenStack dashboard at https://10.20.20.1:443

Addendum: the name "CirrOS" is likely inspired by cirrus clouds which are thin and wispy in appearance.

From the command output depicted above, we see that an SSH key pair was automatically generated for accessing this instance, and the instance IP is 10.20.20.118 in my case (yours may differ). Now connect to this instance using the provided SSH private key, replacing the private key path and instance IP as appropriate:

$ ssh -i /home/donaldsebleung/snap/microstack/common/.ssh/id_microstack [email protected]

Now explore the instance with a few commands (feel free to try out your own):

$ uptime 14:08:55 up 5 min,  1 users,  load average: 0.00, 0.00, 0.00$ whoamicirros$ hostnametest$ iduid=1000(cirros) gid=1000(cirros) groups=1000(cirros)$ uname -aLinux test 4.4.0-28-generic #47-Ubuntu SMP Fri Jun 24 10:09:13 UTC 2016 x86_64 GNU/Linux$ cat /etc/os-releaseNAME=BuildrootVERSION=2015.05-g31af4e3-dirtyID=buildrootVERSION_ID=2015.05PRETTY_NAME="Buildroot 2015.05"

Nice. So we see from uname -a that the CirrOS image was likely derived from Ubuntu in some way.

Exit the instance:

$ exitConnection to 10.20.20.118 closed.

We learn from the official MicroStack tutorial that microstack launch is a wrapper for microstack.openstack server create.

View commands for managing MicroStack instances:

$ microstack.openstack server --help

List running instances:

$ microstack.openstack server list

This prints out a table, which could be difficult to read if your terminal width is small.

List running instances in JSON (much more readable IMO):

$ microstack.openstack server list -f json[  {    "ID": "0b433af1-7c28-4662-a917-4fce451bfa1c",    "Name": "test",    "Status": "ACTIVE",    "Networks": "test=192.168.222.214, 10.20.20.118",    "Image": "cirros",    "Flavor": "m1.tiny"  }]

Stop the instance, replacing the instance ID as appropriate:

$ microstack.openstack server stop 0b433af1-7c28-4662-a917-4fce451bfa1c

View the instance state again:

$ microstack.openstack server list -f json[  {    "ID": "0b433af1-7c28-4662-a917-4fce451bfa1c",    "Name": "test",    "Status": "SHUTOFF",    "Networks": "test=192.168.222.214, 10.20.20.118",    "Image": "cirros",    "Flavor": "m1.tiny"  }]

Restart the instance:

$ microstack.openstack server start 0b433af1-7c28-4662-a917-4fce451bfa1c

And check the instance state again:

$ microstack.openstack server list -f json[  {    "ID": "0b433af1-7c28-4662-a917-4fce451bfa1c",    "Name": "test",    "Status": "ACTIVE",    "Networks": "test=192.168.222.214, 10.20.20.118",    "Image": "cirros",    "Flavor": "m1.tiny"  }]

Try SSHing into the instance again to confirm it is back up:

$ ssh -i /home/donaldsebleung/snap/microstack/common/.ssh/id_microstack [email protected]$ exit

After you're done exploring, terminate the instance:

$ microstack.openstack server delete 0b433af1-7c28-4662-a917-4fce451bfa1c

Confirm that the instance has been terminated:

$ microstack.openstack server list -f json[]

Great. Now that we've seen some basic commands for dealing with instances, let's go a bit deeper and explore some other common features.

Flavor management

Reference: OpenStack Docs: Flavors

If you've dealt with Amazon EC2 before (or a comparable public cloud IaaS provider), you've probably realized by now that OpenStack flavors are analogous to EC2 instance types (or equivalent). Basically, they define the amounts of various hardware resources (compute, network, storage) allocated to an instance, most notably the number of virtual CPU cores and memory. The main difference between EC2 instance types and OpenStack flavors is that the former is predetermined by the public cloud provider, but the latter can be managed by you (subject to the hardware resources available) since you own the cloud ;-)

Let's dive in with some simple commands. Print a help message:

$ microstack.openstack flavor --helpCommand "flavor" matches:  flavor create  flavor delete  flavor list  flavor set  flavor show  flavor unset

List the available flavors (in JSON):

$ microstack.openstack flavor list -f json[  {    "ID": "1",    "Name": "m1.tiny",    "RAM": 512,    "Disk": 1,    "Ephemeral": 0,    "VCPUs": 1,    "Is Public": true  },  {    "ID": "2",    "Name": "m1.small",    "RAM": 2048,    "Disk": 20,    "Ephemeral": 0,    "VCPUs": 1,    "Is Public": true  },  {    "ID": "3",    "Name": "m1.medium",    "RAM": 4096,    "Disk": 20,    "Ephemeral": 0,    "VCPUs": 2,    "Is Public": true  },  {    "ID": "4",    "Name": "m1.large",    "RAM": 8192,    "Disk": 20,    "Ephemeral": 0,    "VCPUs": 4,    "Is Public": true  },  {    "ID": "5",    "Name": "m1.xlarge",    "RAM": 16384,    "Disk": 20,    "Ephemeral": 0,    "VCPUs": 8,    "Is Public": true  }]

So here we see we have 5 flavors by default:

FlavorvCPUsMemory (MiB)
m1.tiny1512
m1.small12048
m1.medium24096
m1.large48192
m1.xlarge816384

Not bad for a micro-cloud. The thing is, my development laptop only has 4 GiB of RAM so m1.small would already be stretching the limits of my physical hardware and anything m1.medium and above would be out of the question. So let's remove some flavors that we won't be able to use anyway:

$ microstack.openstack flavor delete m1.xlarge m1.large m1.medium

Confirm that they have been deleted:

$ microstack.openstack flavor list -f json[  {    "ID": "1",    "Name": "m1.tiny",    "RAM": 512,    "Disk": 1,    "Ephemeral": 0,    "VCPUs": 1,    "Is Public": true  },  {    "ID": "2",    "Name": "m1.small",    "RAM": 2048,    "Disk": 20,    "Ephemeral": 0,    "VCPUs": 1,    "Is Public": true  }]

Display detailed information on remaining flavors:

$ microstack.openstack flavor show m1.tiny -f json{  "OS-FLV-DISABLED:disabled": false,  "OS-FLV-EXT-DATA:ephemeral": 0,  "access_project_ids": null,  "disk": 1,  "id": "1",  "name": "m1.tiny",  "os-flavor-access:is_public": true,  "properties": "",  "ram": 512,  "rxtx_factor": 1.0,  "swap": "",  "vcpus": 1}$ microstack.openstack flavor show m1.small -f json{  "OS-FLV-DISABLED:disabled": false,  "OS-FLV-EXT-DATA:ephemeral": 0,  "access_project_ids": null,  "disk": 20,  "id": "2",  "name": "m1.small",  "os-flavor-access:is_public": true,  "properties": "",  "ram": 2048,  "rxtx_factor": 1.0,  "swap": "",  "vcpus": 1}

Here we see a few more properties being printed such as the amount of swap space for that flavor and whether the flavor is publicly accessible.

I've also just realized that 512 MiB of RAM seems a bit small for proper Ubuntu images that I would like to import and boot later, but 2 GiB of RAM would be a tad too large. What if I could create instances with 1 GiB of RAM? Simple - since I own this cloud, I can just define my own flavor!

$ microstack.openstack flavor create m1.mini \  --vcpus 1 \  --ram 1024 \  --disk 20

This creates a new flavor m1.mini with 1 vCPU core, 1 GiB of RAM and 20 GiB of storage.

Confirm the new flavor is created:

$ microstack.openstack flavor list -f json[  {    "ID": "1",    "Name": "m1.tiny",    "RAM": 512,    "Disk": 1,    "Ephemeral": 0,    "VCPUs": 1,    "Is Public": true  },  {    "ID": "2",    "Name": "m1.small",    "RAM": 2048,    "Disk": 20,    "Ephemeral": 0,    "VCPUs": 1,    "Is Public": true  },  {    "ID": "7d0de4b8-5c51-408c-9fb1-3d7bf3641e73",    "Name": "m1.mini",    "RAM": 1024,    "Disk": 20,    "Ephemeral": 0,    "VCPUs": 1,    "Is Public": true  }]

View details on this new flavor:

$ microstack.openstack flavor show m1.mini -f json{  "OS-FLV-DISABLED:disabled": false,  "OS-FLV-EXT-DATA:ephemeral": 0,  "access_project_ids": null,  "disk": 20,  "id": "7d0de4b8-5c51-408c-9fb1-3d7bf3641e73",  "name": "m1.mini",  "os-flavor-access:is_public": true,  "properties": "",  "ram": 1024,  "rxtx_factor": 1.0,  "swap": "",  "vcpus": 1}

In fact, we've already covered 4 out of 6 (at the time of writing) commands for managing flavors - the remaining two are set and unset which deals with modifying details of existing flavors.

Now let's look at another service - the image service.

Image and snapshot management

Reference: Get images

An image is a template from which an instance is launched. Let's see what operations on images are available:

$ microstack.openstack image --helpCommand "image" matches:  image add project  image create  image delete  image list  image member list  image remove project  image save  image set  image show  image unset

View default images:

$ microstack.openstack image list -f json[  {    "ID": "98a4eb3d-5965-4954-98eb-1ae7f589ce68",    "Name": "cirros",    "Status": "active"  }]

There is only one by default, cirros. View details:

$ microstack.openstack image show cirros -f json{  "checksum": "443b7623e27ecf03dc9e01ee93f67afe",  "container_format": "bare",  "created_at": "2022-01-03T13:28:32Z",  "disk_format": "qcow2",  "file": "/v2/images/98a4eb3d-5965-4954-98eb-1ae7f589ce68/file",  "id": "98a4eb3d-5965-4954-98eb-1ae7f589ce68",  "min_disk": 0,  "min_ram": 0,  "name": "cirros",  "owner": "9bfca2a6753d4f869f2e9a74d1604c92",  "properties": {    "os_hidden": false,    "os_hash_algo": "sha512",    "os_hash_value": "6513f21e44aa3da349f248188a44bc304a3653a04122d8fb4535423c8e1d14cd6a153f735bb0982e2161b5b5186106570c17a9e58b64dd39390617cd5a350f78",    "owner_specified.openstack.object": "images/cirros",    "owner_specified.openstack.sha256": "a8dd75ecffd4cdd96072d60c2237b448e0c8b2bc94d57f10fdbc8c481d9005b8",    "owner_specified.openstack.md5": "443b7623e27ecf03dc9e01ee93f67afe"  },  "protected": false,  "schema": "/v2/schemas/image",  "size": 12716032,  "status": "active",  "tags": [],  "updated_at": "2022-01-03T13:28:33Z",  "visibility": "public"}

Our cloud isn't much use if we can only launch CirrOS instances, which are minimal and only suitable for demo and testing purposes. What if we could import an image for a more popular, practical distribution such as Ubuntu? Fortunately, we can do so with the openstack image create command:

$ microstack.openstack image create --help

Take a moment to skim through the help info. In particular, we see that we can pass a --file <FILE> option to create a new image from a local disk file.

Fetch the latest Ubuntu 20.04 LTS cloud image for KVM:

$ wget https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64-disk-kvm.img

Now create our image:

$ microstack.openstack image create ubuntu-focal \  --disk-format qcow2 \  --file focal-server-cloudimg-amd64-disk-kvm.img \  --public

Confirm it is created:

$ microstack.openstack image list -f json[  {    "ID": "98a4eb3d-5965-4954-98eb-1ae7f589ce68",    "Name": "cirros",    "Status": "active"  },  {    "ID": "6ff67cd2-02b5-4fa2-baf9-65865e8a9b6b",    "Name": "ubuntu-focal",    "Status": "active"  }]

Let's try to boot an instance from our new image with our newly created m1.mini flavor:

$ microstack launch ubuntu-focal \  -n my-mini-ubuntu \  -f m1.mini

Note: microstack launch is specific to MicroStack, while openstack server create is applicable across OpenStack distributions. You may wish to try launching an instance with openstack server create as an additional exercise.

SSH into it as usual. Now poke around the instance (feel free to try out your own commands):

$ whoamiubuntu$ hostnamemy-mini-ubuntu$ free -m              total        used        free      shared  buff/cache   availableMem:            990         107         508           0         375         862Swap:             0           0           0$ df -ThFilesystem     Type      Size  Used Avail Use% Mounted on/dev/root      ext4       20G  1.3G   18G   7% /devtmpfs       devtmpfs  494M     0  494M   0% /devtmpfs          tmpfs     496M     0  496M   0% /dev/shmtmpfs          tmpfs     100M  476K   99M   1% /runtmpfs          tmpfs     5.0M     0  5.0M   0% /run/locktmpfs          tmpfs     496M     0  496M   0% /sys/fs/cgroup/dev/loop0     squashfs   68M   68M     0 100% /snap/lxd/21835/dev/loop1     squashfs   44M   44M     0 100% /snap/snapd/14295/dev/loop2     squashfs   62M   62M     0 100% /snap/core20/1270/dev/vda15     vfat      105M  5.2M  100M   5% /boot/efitmpfs          tmpfs     100M     0  100M   0% /run/user/1000$ uname -aLinux my-mini-ubuntu 5.4.0-1050-kvm #52-Ubuntu SMP Fri Nov 12 11:00:20 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux$ cat /etc/os-releaseNAME="Ubuntu"VERSION="20.04.3 LTS (Focal Fossa)"ID=ubuntuID_LIKE=debianPRETTY_NAME="Ubuntu 20.04.3 LTS"VERSION_ID="20.04"HOME_URL="https://www.ubuntu.com/"SUPPORT_URL="https://help.ubuntu.com/"BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"VERSION_CODENAME=focalUBUNTU_CODENAME=focal

Exit the session when done.

Now that we have a known working Ubuntu image, we probably won't use CirrOS anymore. Delete the image and confirm the deletion:

$ microstack.openstack image delete cirros$ microstack.openstack image list -f json[  {    "ID": "6ff67cd2-02b5-4fa2-baf9-65865e8a9b6b",    "Name": "ubuntu-focal",    "Status": "active"  }]

You should now only have the ubuntu-focal image left.

Before we conclude our tour of OpenStack, let's look at one more feature: snapshots. Snapshots record the state of an instance at a particular time, so that we can revert to that state later on (if something goes wrong, for example). In fact, as far as OpenStack is concerned, a snapshot is just an image.

SSH into our my-mini-ubuntu instance and run the following commands within our instance:

$ sudo add-apt-repository ppa:donaldsebleung/misc$ sudo apt update$ sudo apt install -y donaldsebleung-com$ yes "" | openssl req \  -x509 \  -newkey rsa:4096 \  -keyout key.pem \  -out cert.pem \  -sha256 \  -days 365 \  -nodes$ sudo mv key.pem /etc/donaldsebleung-com$ sudo mv cert.pem /etc/donaldsebleung-com$ sudo systemctl enable --now donaldsebleung-com.service

This installs my personal website (shameless promotion here :-P). Check that it is up and running:

$ wget -qO - https://localhost --no-check-certificate<!DOCTYPE HTML><!--    Hyperspace by HTML5 UP    html5up.net | @ajlkn    Free for personal and commercial use under the CCA 3.0 license (html5up.net/license)-->...

Exit the session. Now stop our instance:

$ microstack.openstack server stop my-mini-ubuntu

Create a snapshot donaldsebleung-com from my-mini-ubuntu:

$ microstack.openstack server image create my-mini-ubuntu \  --name donaldsebleung-com

Now see that it has been added to our list of images, along with ubuntu-focal:

$ microstack.openstack image list -f json[  {    "ID": "e58f4ab7-2bb6-4f11-9cfd-0887d1ac9b2c",    "Name": "donaldsebleung-com",    "Status": "saving"  },  {    "ID": "6ff67cd2-02b5-4fa2-baf9-65865e8a9b6b",    "Name": "ubuntu-focal",    "Status": "active"  }]

If the status of your snapshot is saving as shown above, wait a few seconds and query the image list again until the status changes to active.

At this point, if your laptop is resource-constrained like mine (with only 4 GiB of RAM!), you may wish to first terminate your existing my-mini-ubuntu instance, as we will be launching another instance shortly:

$ microstack.openstack server delete my-mini-ubuntu

Now launch a new instance my-personal-website from the donaldsebleung-com snapshot:

$ microstack launch donaldsebleung-com \  -n my-personal-website \  -f m1.mini

SSH into the instance. If everything is working as expected, the web server should already be up and running:

$ wget -qO - https://localhost --no-check-certificate<!DOCTYPE HTML><!--    Hyperspace by HTML5 UP    html5up.net | @ajlkn    Free for personal and commercial use under the CCA 3.0 license (html5up.net/license)-->...

Exit the session.

Cleaning up

Reference: OpenStack in a snap!

Terminate my-personal-website:

$ microstack.openstack server delete my-personal-website

If you won't be using MicroStack again in a short while but would like to keep it around for future exploration, disabling the snap could be an option:

$ sudo snap disable microstack

Then, whenever you need MicroStack again, you can re-enable it with:

$ sudo snap enable microstack

Alternatively, if you might not use MicroStack again for quite a while and would like to free up disk space (like I do), removing it with the usual snap remove is an option:

$ sudo snap remove --purge microstack

Conclusion

We learned:

  • What OpenStack is
  • MicroStack as an OpenStack distribution that "just works"
  • How to install MicroStack, provision our first instance and connect to it
  • How to manage instances, flavors, images and snapshots

Of course, this is just the tip of the iceberg. Some things we haven't had the time to look at in this tutorial:

  • Identity access management with Keystone
  • Advanced networking configuration with Neutron
  • Managing OpenStack from the web console with Horizon

By the way, the compute and image services that we explored are known as Nova and Glance respectively. At the time of writing, MicroStack only comes with these 5 core services, with many additional services left out. This means if you get the chance to try out a proper production-grade OpenStack distribution, you might have the chance to work with other services not available through MicroStack:

  • Zun for containers
  • Ironic for bare-metal provisioning
  • Magnum for container orchestration

... and so on.

Finally, here are some extra resources for your interest:

I hope you enjoyed this article ;-)

References


Original Link: https://dev.to/donaldsebleung/introduction-to-openstack-with-microstack-1f5j

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To