如何使用REST API将文件存储卷安装到azure容器实例

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何使用REST API将文件存储卷安装到azure容器实例相关的知识,希望对你有一定的参考价值。

我正在尝试创建Azure容器实例并通过REST API挂载文件存储卷,但我得到400响应。

我能够创建容器并使其保持运行但是当我添加卷部分时它返回400响应(错误请求)而无需进一步说明

这是我发送到REST端点的JSON有效负载:

{
  "id": "/subscriptions/111111111/resourceGroups/OraResourceGroup/providers/Microsoft.ContainerInstance/containerGroups/solver",
  "location": "West Europe",
  "name": "solver",
  "properties": {
    "volumes": [
      {
        "azureFile": {
          "shareName": "orafileshare",
          "storageAccountKey": "somekey",
          "storageAccountName": "myaccountname"
        },
        "name": "Volume1"
      }
    ],
    "containers": [
      {
        "name": "solver",
        "properties": {
          "command": [],
          "environmentVariables": [],
          "image": "acraccount/solver:v1",
          "ports": [
            {
              "port": 12345
            }
          ],
          "resources": {
            "requests": {
              "cpu": 1.0,
              "memoryInGB": 1.5
            }
          },
          "volumeMounts": [
            {
              "name": "Volume1",
              "mountPath": "/mountFolder"
            }
          ]
        }
      }
    ],
    "imageRegistryCredentials": [
      {
        "password": "123123123213123",
        "server": "acr.server.io",
        "username": "acrOra"
      }
    ],
    "ipAddress": {
      "ports": [
        {
          "protocol": "TCP",
          "port": 12345
        }
      ],
      "type": "Public"
    },
    "osType": "Linux",
    "restartPolicy": "Always"
  },
  "type": "Microsoft.ContainerInstance/containerGroups"
}

预期结果是200或201响应,容器应出现在我的Azure门户仪表板上,但实际响应为400。

答案

此更正有2个问题。我还收到400个不良请求,但后来更正了它,我能够成功运行它。

  1. 卷的名称,大写字母是不允许的。

Change "Volume1" to "volume1"

参考错误:

{"error":{"code":"InvalidVolumeName","message":"The volume name 'Volume1' is invalid. The volume name must match the regex '[a-z0-9]([-a-z0-9]*[a-z0-9])?' (e.g. 'my-name')."}}

  1. Sku不是有效的属性,删除它 {"error":{"code":"InvalidRequestContent","message":"The request content was invalid and could not be deserialized: 'Could not find member 'sku' on object of type 'ComputeResources'. Path 'properties.containers[0].properties.resources.requests.sku', line 32, position 22.'."}} 参考https://docs.microsoft.com/en-us/rest/api/container-instances/containergroups/createorupdate#resourcerequests

示例配置

{
  "id": "/subscriptions/xxxx/resourceGroups/teststoragerest/providers/Microsoft.ContainerInstance/containerGroups/solver",
  "location": "West Europe",
  "name": "demo1forrahul",
  "properties": {
    "volumes": [
      {
        "azureFile": {
          "shareName": "testfilestorage",
          "storageAccountKey": "xxxx",
          "storageAccountName": "xxxxxx"
        },
        "name": "volume1"
      }
    ],
    "containers": [
      {
        "name": "demo1forrahul",
        "properties": {
          "command": [],
          "environmentVariables": [],
          "image": "nginx",
          "ports": [
            {
              "port": 80
            }
          ],
          "resources": {
            "requests": {
              "cpu": 1.0,
              "memoryInGB": 1.5
            }
          },
          "volumeMounts": [
            {
              "name": "volume1",
              "mountPath": "/testfolder"
            }
          ]
        }
      }
    ],
    "imageRegistryCredentials": [],
    "ipAddress": {
      "ports": [
        {
          "protocol": "TCP",
          "port": 80
        }
      ],
      "type": "Public"
    },
    "osType": "Linux",
    "restartPolicy": "Always"
  },
  "type": "Microsoft.ContainerInstance/containerGroups"
}

以上是关于如何使用REST API将文件存储卷安装到azure容器实例的主要内容,如果未能解决你的问题,请参考以下文章

Django rest 框架 - 将图像上传到 Azure 存储

在不使用 Azure SDK 的情况下使用 REST API 将流上传到 Azure Blob 存储

使用 REST API 上传到 Azure Blob 存储时,Zip 档案损坏

如何将 azure 广告集成到在 azure 中也使用 REST API 的 React Web 应用程序

请求令牌时如何在 Azure 存储 Blob 中为 REST 请求指定范围? [AZURE-BLOB][REST API]

REST Api 使用访问密钥到 Azure Blob 存储