自动化创建OSS、NAS数据卷

    xiaoxiao2025-09-12  58

    数据卷的基本介绍参考:https://yq.aliyun.com/articles/138?spm=5176.100240.searchblog.11.dcX58H

    阿里云OSS数据卷介绍:https://yq.aliyun.com/articles/7581?spm=5176.100240.searchblog.7.SgLL9J

    阿里云NAS数据卷介绍:https://yq.aliyun.com/articles/52523?spm=5176.100240.searchblog.40.IhHWyf

    控制台创建数据卷参考:https://help.aliyun.com/document_detail/26033.html?spm=5176.doc26054.6.166.0Qcl7D

    1. 获取集群ID

    (OpenApi)通过API创建集群后,获得集群ID;参考:https://help.aliyun.com/document_detail/26054.html?spm=5176.doc26060.6.203.H4azPQ

    2. 获取集群介入地址

    (OpenApi)通过集群ID获取集群信息,从中获取集群的接入点URL(master_url);参考:https://help.aliyun.com/document_detail/26056.html?spm=5176.doc26057.6.205.ltOB01

    3. 获取集群证书

    (OpenApi)通过集群ID获取证书,参考:https://help.aliyun.com/document_detail/26057.html?spm=5176.doc26056.6.206.O0Lf63

    4. 创建NAS数据卷

    实现下面HTTP请求以创建NAS数据卷:请求:

    curl -k -H "Content-Type: application/json" -X POST -d @nas.json https://master1g4.cs-cn-hangzhou.aliyun.com:14930/volumes/create -v --key key.pem --cacert ca.pem --cert cert.pem

    响应:

    {"Name":"docker2","Driver":"nas","Mountpoint":"/mnt/acs_mnt/nas/0a1c9498c","Labels":null,"Scope":""}

    其中:/mnt/acs_mnt/nas/0a1c9498c 是生成的NAS挂载目录;其中:master1g4.cs-cn-hangzhou.aliyun.com:14930 是通过步骤2获取的集群接入点URL;其中:key.pem, ca.pem, cert.pem 是通过步骤3获取的集群证书;其中:nas.json是需要创建的NAS数据卷信息文件,其内容如下:

    { "name": "docker2", "driver": "nas", "driverOpts": { "diskid": "0a1c9498c", "host": "0a1c9498c-fjs24.cn-hangzhou.nas.aliyuncs.com", "opts": "" } }

    需要提供NAS信息:数据卷名字(name),NAS的磁盘ID(diskid),NAS的挂载点地址(host);

    5. 创建OSS数据卷

    (HTTP)实现下面HTTP请求以创建OSS数据卷:请求:

    curl -k -H "Content-Type: application/json" -X POST -d @oss.json https://master1g4.cs-cn-hangzhou.aliyun.com:14930/volumes/create -v --key key.pem --cacert ca.pem --cert cert.pem

    响应:

    {"Name":"docker1","Driver":"ossfs","Mountpoint":"/mnt/acs_mnt/ossfs/aliyun-docker","Labels":null,"Scope":""}

    其中:/mnt/acs_mnt/ossfs/aliyun-docker是生成的OSS挂载目录;其中:master1g4.cs-cn-hangzhou.aliyun.com:14930是通过步骤2获取的集群接入点URL;其中:key.pem, ca.pem, cert.pem是通过步骤3获取的集群证书;其中:oss.json是需要创建的OSS数据卷信息文件,其内容如下:

    { "name": "docker1", "driver": "ossfs", "driverOpts": { "bucket": "aliyun-docker", "ak_id": "****", "ak_secret": "*****", "url": "oss-cn-hangzhou.aliyuncs.com", "no_stat_cache": "true", "other_opts": "-o allow_other -o default_permission=666" } }

    需要提供的OSS信息:数据卷名字(name),OSS的Bucket名字(diskid),用户的AK信息(ak_id, ak_secret),OSS访问域名(url);


    以上步骤中,1.2.3容器服务都有相应的SDK提供,参考:https://help.aliyun.com/document_detail/26060.html?spm=5176.doc26057.6.231.oDUQLYhttps://github.com/denverdino/aliyungo

    步骤4、5未提供OpenApi、SDK,需要自己实现Client端;

    最新回复(0)