How to Create Availability Zones (AZ) in OpenStack from Command Line

In OpenStack terminology, Availability Zones (AZ) is defined as a logical partition of compute(nova), block storage (cinder) and network Service (neutron). Availability zones are required to segregate the work load of environments like production and non-production, let me elaborate this statement.

Availability-Zones-OpenStack-Command-Line

let’s suppose we have a tenant in OpenStack who wants to deploy their VMs in Production and Non-Production, so to create this type of setup in openstack , first we have to identify which computes will be considered as Production and Non-production then we have to create host-aggregate group where we will add the computes to the host-aggregate group and then we will map th host aggregate group to the Availability Zone.

In this tutorial we will demonstrate how to create and use computes availability zones in openstack via command line.

Creating compute availability zones

Whenever OpenStack is deployed, Nova is the default Availability Zone(AZ) created automatically and all the compute nodes belongs to Nova AZ. Run the below openstack command from the controller node to list Availability zones,

~# source openrc
~# openstack availability zone list
+-----------+-------------+
| Zone Name | Zone Status |
+-----------+-------------+
| internal  | available   |
| nova      | available   |
| nova      | available   |
| nova      | available   |
+-----------+-------------+
~#

To list only compute’s availability zones, run the beneath openstack command,

~# openstack availability zone list --compute
+-----------+-------------+
| Zone Name | Zone Status |
+-----------+-------------+
| internal  | available   |
| nova      | available   |
+-----------+-------------+
~#

To list all compute hosts which are mapped to nova availability zone execute the below command,

~# openstack host list | grep -E "Zone|nova"
| Host Name              | Service     | Zone     |
| compute-0-1            | compute     | nova     |
| compute-0-2            | compute     | nova     |
| compute-0-4            | compute     | nova     |
| compute-0-3            | compute     | nova     |
| compute-0-8            | compute     | nova     |
| compute-0-6            | compute     | nova     |
| compute-0-9            | compute     | nova     |
| compute-0-5            | compute     | nova     |
| compute-0-7            | compute     | nova     |
~#

Let’s create a two host-aggregate group with name production and non-production, add compute-4,5 & 6 to production host aggregate group and compute-7,8 & 9 to non-production host aggregate group.

Create Production and Non-Production Host aggregate using following OpenStack commands,

~# openstack aggregate create production
+-------------------+----------------------------+
| Field             | Value                      |
+-------------------+----------------------------+
| availability_zone | None                       |
| created_at        | 2019-08-17T03:02:41.561259 |
| deleted           | False                      |
| deleted_at        | None                       |
| id                | 7                          |
| name              | production                 |
| updated_at        | None                       |
+-------------------+----------------------------+

~# openstack aggregate create non-production
+-------------------+----------------------------+
| Field             | Value                      |
+-------------------+----------------------------+
| availability_zone | None                       |
| created_at        | 2019-08-17T03:02:53.806713 |
| deleted           | False                      |
| deleted_at        | None                       |
| id                | 10                         |
| name              | non-production             |
| updated_at        | None                       |
+-------------------+----------------------------+
~#

Now create the availability zones and associate it to its respective host aggregate groups

Syntax:

# openstack aggregate set –zone <az_name>  <host_aggregate_name>

~# openstack aggregate set --zone production-az production
~# openstack aggregate set --zone non-production-az non-production

Finally add the compute host to its host-aggregate group

Syntax:

# openstack aggregate add host <host_aggregate_name>  <compute_host>

~# openstack aggregate add host production compute-0-4
~# openstack aggregate add host production compute-0-5
~# openstack aggregate add host production compute-0-6

Similarly add compute host to non-production host aggregation group,

~# openstack aggregate add host non-production compute-0-7
~# openstack aggregate add host non-production compute-0-8
~# openstack aggregate add host non-production compute-0-9

Execute the beneath openstack commands to verify Host aggregate group and its availability zone

~# openstack aggregate list
+----+----------------+-------------------+
| ID | Name           | Availability Zone |
+----+----------------+-------------------+
|  7 | production     | production-az     |
| 10 | non-production | non-production-az |
+----+----------------+-------------------+
~#

Run below commands to list computes associated to AZ and host aggregate group

~# openstack aggregate show production
+-------------------+--------------------------------------------+
| Field             | Value                                      |
+-------------------+--------------------------------------------+
| availability_zone | production-az                              |
| created_at        | 2019-08-17T03:02:42.000000                 |
| deleted           | False                                      |
| deleted_at        | None                                       |
| hosts             | [u'compute-0-4', u'compute-0-5', u'compute-0-6'] |
| id                | 7                                          |
| name              | production                                 |
| properties        |                                            |
| updated_at        | None                                       |
+-------------------+--------------------------------------------+

~# openstack aggregate show non-production
+-------------------+---------------------------------------------+
| Field             | Value                                       |
+-------------------+---------------------------------------------+
| availability_zone | non-production-az                           |
| created_at        | 2019-08-17T03:02:54.000000                  |
| deleted           | False                                       |
| deleted_at        | None                                        |
| hosts             | [u'compute-0-7', u'compute-0-8', u'compute-0-9'] |
| id                | 10                                          |
| name              | non-production                              |
| properties        |                                             |
| updated_at        | None                                        |
+-------------------+---------------------------------------------+
~#

Above command’s output confirm that we have successfully create host aggregate group and availability zones.

Launch Virtual Machines in Availability Zones

Now let’s create couple virtual machines in these two availability zones, to create a vm in particular availability zone use below command,

Syntax:

# openstack server create –flavor <flavor-name> –image <Image-Name-Or-Image-ID>  –nic net-id=<Network-ID> –security-group <Security-Group-ID> –key-name <Keypair-Name> –availability-zone <AZ-Name>   <VM-Name>

Example is shown below:

~# openstack server create --flavor m1.small --image Cirros --nic net-id=37b9ab9a-f198-4db1-a5d6-5789b05bfb4c --security-group f8dda7c3-f7c3-423b-923a-2b21fe0bbf3c --key-name mykey --availability-zone production-az test-vm-prod-az

Run below command to verify virtual machine details:

~# openstack server show test-vm-prod-az

Openstack-Server-AZ-command

To create a virtual machine in a specific compute node under availability zone, use the below command,

Syntax:

# openstack server create –flavor <flavor-name> –image <Image-Name-Or-Image-ID>  –nic net-id=<Network-ID> –security-group <Security-Group-ID> –key-name {Keypair-Name} –availability-zone <AZ-Name>:<Compute-Host> <VM-Name>

Let suppose we want to spin a vm under production AZ on specific compute (compute-0-6), so to accomplish this, run the beneath command,

~# openstack server create --flavor m1.small --image Cirros --nic net-id=37b9ab9a-f198-4db1-a5d6-5789b05bfb4c --security-group f8dda7c3-f7c3-423b-923a-2b21fe0bbf3c --key-name mykey --availability-zone production-az:compute-0-6 test-vm-prod-az-host

Execute following command to verify the VM details:

~# openstack server show test-vm-prod-az-host

Output above command would be something like below:

OpenStack-VM-AZ-Specific-Host

Similarly, we can create virtual machines in non-production AZ, example is shown below

~# openstack server create --flavor m1.small --image Cirros --nic net-id=37b9ab9a-f198-4db1-a5d6-5789b05bfb4c --security-group f8dda7c3-f7c3-423b-923a-2b21fe0bbf3c --key-name mykey --availability-zone non-production-az vm-nonprod-az

Use below command verify the VM details,

~# openstack server show vm-nonprod-az

Output of above command would be something like below,

OpenStack-Non-Production-AZ-VM

Also Read : How to Create Affinity and Anti-Affinity Policy in OpenStack

Removing Host aggregate group and Availability Zones

Let’s suppose we want to remove /delete above created host aggregate group and availability zones, for that first we must remove host from the host aggregate group, use the below command,

~# openstack aggregate show production

Above command will give u the list of compute host which are added to production host aggregate group.

Use below command to remove host from the host aggregate group

Syntax:

# openstack aggregate remove host <host-aggregate-name> <compute-name>

~# openstack aggregate remove host production compute-0-4
~# openstack aggregate remove host production compute-0-5
~# openstack aggregate remove host production compute-0-6

Once you remove all host from the group, then re-run the below command,

~# openstack aggregate show production
+-------------------+----------------------------+
| Field             | Value                      |
+-------------------+----------------------------+
| availability_zone | production-az              |
| created_at        | 2019-08-17T03:02:42.000000 |
| deleted           | False                      |
| deleted_at        | None                       |
| hosts             | []                         |
| id                | 7                          |
| name              | production                 |
| properties        |                            |
| updated_at        | None                       |
+-------------------+----------------------------+
~#

As we can see in above output there is no compute host associated to production host aggregate group, now we are good to remove the group

Use below command to delete host aggregate group and its associated availability zone

~# openstack aggregate delete production

Run the following command to check whether availability zone has been removed or not,

~# openstack availability zone list | grep -i production-az
~#

Similarly, you can refer the above steps to remove or delete non-production host aggregate and its availability zone.

That’s all from this tutorial, in case above content helps you to understand OpenStack host aggregate and availability zones then please do share your feedback and comments.

Read Also: Top 30 OpenStack Interview Questions and Answers

4 thoughts on “How to Create Availability Zones (AZ) in OpenStack from Command Line”

  1. You dont mention cinder AZ. Your opening summary mentions cinder but it’s like you forgot about it. How do you launch a vm in a nova AZ and force a particular backend cinder AZ? For example, production hosts and production storage, compared with non-prod hosts and non-prod storage.

  2. Could someone please explain, why we are using availability zones? If we create prod and non-prod HA and keep AZ as Nova by default the result will be the same. In which use cases do we need to map HA with many AZ? Thanks in advance.

Leave a Comment

Your email address will not be published. Required fields are marked *