In my last article, I wrote about different levels in which OpenStack cloud can be segregated . These are hosts , host aggregates , availability zones and regions. In this article, I will be mentioning different options available to users for placing their virtual machine instances on these constructs based on suitability.
When a user creates an instance, the nova-scheduler service comes into picture and is responsible for selecting a target host for this requested instance. For doing this, all compute nodes publish their resources and other artifacts to scheduler which keeps the data handy and available . By default , scheduler is configured to choose hosts based on following criteria :-
1. Whether the host falls in requested Availability Zone
2. Whether the host has required RAM available
3. Whether the host has required CPU available
This selection criteria is configurable in many ways like filters. Lets check out various placement options :-
1. Placement on desired Availability Zone
Availability zone is preferably created as host aggregate which is exposed to end users in form of availability zone. Below steps illustrate how to create aggregate and specify it while provisioning :
- To create host aggregate , below command is used :
nova aggregate-create <name> [<availability-zone>]
Eg, nova aggregate-create Aggregate_1 AZ_1
- Add host to it using below command :
nova aggregate-add-host <aggregate> <host>
Eg. nova aggregate-add-host Aggregate_1 Host_A
- Now when an instance is created , created availability zone can be mentioned as a target for that instance.
nova boot --flavor 1 --image 6116f510-18c5-44e0-8a81-868e1c9fc79f --availability-zone AZ_1 testinstance
Note : we can also specify particular host within availability zone in above command
nova boot --flavor 1 --image 6116f510-18c5-44e0-8a81-868e1c9fc79f --availability-zone AZ_1: Host_A testinstance
2. Placement on desired Host aggregate
Host aggregates provide mechanism to group hosts that have a common capability like a group of hosts having SSD drives enabled. OpenStack scheduler is not by default enabled to support this and can be configured by making below changes in nova.conf file :-
Lookout for property scheduler_default_filters and append AggregateInstanceExtraSpecsFilter filter to its value.
Selecting host aggregate is done through metadata associated with it. Metadata contains key-value pairs that can be matched while provisioning instances.
Eg, we can create a ssd=true key-value pair and attach it to metadata of a host aggregate.
nova aggregate-set-metadata Aggregate_1 ssd=true
Next step is to create a flavor and add the same key-value pair to it's extra specs.
Create flavor using below command :
nova flavor-create ssd.large 6 512 10 1
Add key value pair to it
nova-manage instance_type set_key --name=ssd.large --key=ssd --value=true
Finally when an instance is launched with this flavor, the nova-scheduler will match the host aggregate based on the metadata of host aggregate and extra specs of flavor to determine the target host aggregate for new instance.
OpenStack provides filter scheduler which allows users to have their custom vm placement choices. There are many filters available in Openstack like ComputeFilter , DifferentHostFilter , RamFilter , JsonFilter etc.
When a request is made to launch instance, Filter scheduler first lines up all hosts and filters them based on the filter provided in request . After making a subset of hosts , then wights are applied to determine the destination host.
Filters are specified by --hint option in the nova boot command .
For example , this filter will select hosts that have free RAM more that 4 GB available.
nova boot --image 58ae75f1-3840-4149-bb0b-e52badbd1d4c --flavor 1 --hint query='[">=","$free_ram_mb",4096]' server_correct --nic net-id=16630baf-7b7a-45bf-88a5-cbbcd5d22cab