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

问题描述 投票:0回答:1

我正在尝试创建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。

c# azure containers azure-container-instances
1个回答
0
投票

此更正有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"
}
© www.soinside.com 2019 - 2024. All rights reserved.