天天看点

ironic baremetal 裸金属环境 使用 Placement Trait 在特定物理机上启用实例

openstack裸金属启用实例时会从可用资源池中,根据过滤策略随机分配一台主机来启用实例。

nova-scheduler 启动实例时的调度机制

#https://www.cnblogs.com/CloudMan6/p/5441782.html

#https://blog.csdn.net/u011692924/article/details/80578686

在一些特定的应用场景下,我们希望某个实例使用指定的一个或一批物理硬件。例如,希望Hadoop集群使用A批机器,k8s集群使用B批次的机器。通过摸索利用Placement_API打上资源特征的方法找到一条可行的路径。

环境

centos7.6

openstack queens + baremetal

过程:

1、安装placement client

yum install -y epel-release

yum install -y python-pip

pip install -U pip

pip install osc-placement

2、placement client 使用

#Queens版最高支持 1.17    

#https://docs.openstack.org/placement/latest/placement-api-microversion-history.html#queens

#添加环境变量

export OS_PLACEMENT_API_VERSION=1.17

3、命令行使用

#参考https://docs.openstack.org/osc-placement/queens/cli/index.html

3.1 openstack resource class list

#资源类列表,

#Resource Class:资源种类,即资源的类型,Placement 为 Compute Node 缺省了下列几种类型,同时支持 Custom Resource Classes。

[[email protected] ~]# openstack resource class list

+-------------------+

| name              |

+-------------------+

| VCPU              |

| MEMORY_MB         |

| DISK_GB           |

| PCI_DEVICE        |

| SRIOV_NET_VF      |

| NUMA_SOCKET       |

| NUMA_CORE         |

| NUMA_THREAD       |

| NUMA_MEMORY_MB    |

| IPV4_ADDRESS      |

| VGPU              |

| VGPU_DISPLAY_HEAD |

+-------------------+

3.2 openstack resource provider list

#资源提供者列表

#裸金属可用节点将出现在资源提供者列表中

3.3 openstack resource provider inventory list

#资源提供者资源清单列表

#资源提供者,实际提供资源的实体,例如:Compute Node、Storage Pool、IP Pool 等

openstack resource provider inventory list 34a84cf3-4898-4d66-83cc-8f978d1349e6

[[email protected] ~]# openstack resource provider inventory list 34a84cf3-4898-4d66-83cc-8f978d1349e6

+----------------+------------------+----------+----------+-----------+----------+-------+

| resource_class | allocation_ratio | max_unit | reserved | step_size | min_unit | total |

+----------------+------------------+----------+----------+-----------+----------+-------+

| VCPU           |              1.0 |        8 |        0 |         1 |        1 |     8 |

| MEMORY_MB      |              1.0 |    24576 |        0 |         1 |        1 | 24576 |

| DISK_GB        |              1.0 |      222 |        0 |         1 |        1 |   222 |

+----------------+------------------+----------+----------+-----------+----------+-------+

#裸金属资源的分配比率( allocation_ratio)为1:1,而普通虚拟机允许多分配

[[email protected] ~]# openstack resource provider inventory list  e64c934c-cd5a-4991-8b64-2b83aad2405d

+----------------+------------------+----------+----------+-----------+----------+-------+

| resource_class | allocation_ratio | max_unit | reserved | step_size | min_unit | total |

+----------------+------------------+----------+----------+-----------+----------+-------+

| VCPU           |             16.0 |       24 |        0 |         1 |        1 |    24 |

| MEMORY_MB      |              1.5 |    18431 |      512 |         1 |        1 | 18431 |

| DISK_GB        |              1.0 |       49 |        0 |         1 |        1 |    49 |

+----------------+------------------+----------+----------+-----------+----------+-------+

3.4 openstack resource provider usage show

#资源提供者的资源使用情况

openstack resource provider usage show 34a84cf3-4898-4d66-83cc-8f978d1349e6

[[email protected] ~]# openstack resource provider usage show 34a84cf3-4898-4d66-83cc-8f978d1349e6

+----------------+-------+

| resource_class | usage |

+----------------+-------+

| VCPU           |     8 |

| MEMORY_MB      | 24576 |

| DISK_GB        |   222 |

+----------------+-------+

3.5  openstack trait create | list | show

#资源特征管理

#资源特征,不同资源提供者可能会具有不同的资源特征。Traits 作为资源提供者特征的描述,它不能够被消费,例如:标识可用#的 Disk 具有 SSD 特征,有助于 Scheduler 灵活匹配 Launch Instance 的请求。

#我们就是利用给资源打上特征,然后在分配时供我们使用。自定义特征以CUSTOM_开头,本例给几台机器打上CUSTOM_HADOOPNODE特征标记,以供启用hadoop集群时使用。

openstack trait create CUSTOM_HADOOPNODE

3.6 openstack resource provider trait set

#为资源提供者设置特征

openstack resource provider trait set --trait CUSTOM_HADOOPNODE  0623436c-816b-44c6-b741-01cc7c0b2fff

3.7  openstack allocation candidate list

#分配候选人列表

#列出满足当前条件的资源列表

openstack allocation candidate list --resource VCPU=8  --required CUSTOM_HADOOPNODE

[[email protected] ~]# openstack allocation candidate list --resource VCPU=16  --required CUSTOM_HADOOPNODE

+---+------------+--------------------------------------+-------------------------+-------------------+

| # | allocation | resource provider                    | inventory used/capacity | traits            |

+---+------------+--------------------------------------+-------------------------+-------------------+

| 1 | VCPU=16    | e64c934c-cd5a-4991-8b64-2b83aad2405d | VCPU=12/384             | CUSTOM_HADOOPNODE |

| 2 | VCPU=16    | 0623436c-816b-44c6-b741-01cc7c0b2fff | VCPU=0/24               | CUSTOM_HADOOPNODE |

+---+------------+--------------------------------------+-------------------------+-------------------+

#指定节点上启动实例,根据allocation candidate --required trait 过滤出的provider id 即可以对应到相应的ironic node

#然后使用 --availability-zone nova:[ironic-node-name]启动实例

openstack server create \

    --availability-zone nova:compute03 \

    --image hadoop-master \

    --flavor dell.bm  \

    --key-name mykey \

    --nic net-id=b78a9fca-1e69-4668-91f5-0410998fbc5a \

    allocation-candidate01

openstack server create \

    --hypervisor-hostname compute01 \

    --image hadoop-slaver \

    --flavor r220.bm \

    --key-name mykey \

    --nic net-id=b78a9fca-1e69-4668-91f5-0410998fbc5a \

    allocation-candidate02

即实现了根据特征trait启用相应的物理硬件。

参考文档:

https://blog.csdn.net/Jmilk/article/details/82980378

https://blog.csdn.net/weixin_34132768/article/details/93577066

https://blog.csdn.net/u011692924/article/details/80578686

https://blog.51cto.com/99cloud/2166339

https://docs.openstack.org/placement/latest/placement-api-microversion-history.html#queens

继续阅读