Skip to content

How to create Instances on different Compute Nodes

Estimated time to read: 3 minutes

Before you start

This tutorial assumes you've got the CLI tools running. If you don't, please visit the OpenStack command-line interface (CLI) installation commands tutorial.

When building a cluster of instances on Fuga Cloud, you want to ensure that these instances are created on separate compute nodes in order to ensure the highest availability. When creating the instances via the Fuga Cloud dashboard, you have no way to control on which compute node your instance will be created, and cluster nodes can be created on the same compute node. When creating instances via the OpenStack command-line tools, you can supply hints to the Nova Scheduler to ensure the instances are created on separate compute hosts. The Nova Scheduler is the process in OpenStack that determines on which compute node an instance will be created. The Nova Scheduler uses filters to see which of the compute nodes can be used to create the instance. The Nova Scheduler assigns a weight to each of the available compute nodes and the node with the highest weight will receive the instance. The Nova Scheduler has filters for disk space, memory, available CPUs etc. Some of these filters accept hints that can be supplied by the users when creating an instance. The filters ServerGroupAffinityFilter and ServerGroupAntiAffinityFilter can be used to make sure instances run on the same or on different compute nodes.

To accomplish this, you will create a server group with the anti-affinity set. When creating a new instance in this server group the Nova Scheduler will give a higher priority to compute nodes with no other instances in this server group. When this rule can't be met, it will choose the compute node with the least amount of instances in this server group. First, you will create a new server group with the anti-affinity policy.

$ openstack server group create --policy anti-affinity server_group
+--------------------------------------+----------------+--------------------+---------+----------+
| Id                                   | Name           | Policies           | Members | Metadata |
+--------------------------------------+----------------+--------------------+---------+----------+
| 27a5df2e-6494-44af-8dbb-8a1d56536c09 | server-group   | [u'anti-affinity'] | []      | {}       |
+--------------------------------------+----------------+--------------------+---------+----------+
Now you can create instances in this server group. Hints can only be supplied when creating the instance via the API or CLI.
$ openstack server create --flavor <flavor> --nic net-id=<network_id> --image <image> --security-group <security_group> --hint group=<server_group_id> <instance_name>
+-----------------------------+---------------------------------------------------------+
| Field                       | Value                                                   |
+-----------------------------+---------------------------------------------------------+
| OS-DCF:diskConfig           | MANUAL                                                  |
| OS-EXT-AZ:availability_zone |                                                         |
| OS-EXT-STS:power_state      | NOSTATE                                                 |
| OS-EXT-STS:task_state       | scheduling                                              |
| OS-EXT-STS:vm_state         | building                                                |
| OS-SRV-USG:launched_at      | None                                                    |
| OS-SRV-USG:terminated_at    | None                                                    |
| accessIPv4                  |                                                         |
| accessIPv6                  |                                                         |
| addresses                   |                                                         |
| adminPass                   | CSLEC925Fwgg                                            |
| config_drive                |                                                         |
| created                     | 2021-12-02T14:27:18Z                                    |
| flavor                      | t2.tiny (3c457ea1-d89e-4a51-811d-5288aae2a16c)          |
| hostId                      |                                                         |
| id                          | a10a9339-a816-4bcd-8280-8972a72a0def                    |
| image                       | Ubuntu 20.04 LTS (0e10a3b8-10f9-4d4d-bf88-cff9de653ade) |
| key_name                    | None                                                    |
| name                        | instance1                                               |
| progress                    | 0                                                       |
| project_id                  | 315fd5298df541b084dd785cca9341d4                        |
| properties                  |                                                         |
| security_groups             | name='50626ccf-a6e8-4e8d-98fc-882ece2bc75b'             |
| status                      | BUILD                                                   |
| updated                     | 2021-12-02T14:27:18Z                                    |
| user_id                     | 0eeaf2104e464363b8d684530e807c4a                        |
| volumes_attached            |                                                         |
+-----------------------------+---------------------------------------------------------+
The members in a server group can be listed with the following command:
$ openstack server group list --long
+--------------------------------------+--------------+---------------+--------------------------------------+------------+---------+
| ID                                   | Name         | Policies      | Members                              | Project Id | User Id |
+--------------------------------------+--------------+---------------+--------------------------------------+------------+---------+
| 1a97006e-3fe4-4b5e-9a1e-5dc49b7ca31d | server_group | anti-affinity | a10a9339-a816-4bcd-8280-8972a72a0def |            |         |
+--------------------------------------+--------------+---------------+--------------------------------------+------------+---------+

Note

Assigning an instance to a server group can only be done when creating an instance. Existing instances cannot be assigned to a server group. References: http://docs.openstack.org/kilo/config-reference/content/section_compute-scheduler.html