【问题标题】:How to mount a File Storage volume to an azure container instance using REST api如何使用 REST api 将文件存储卷挂载到 azure 容器实例
【发布时间】:2019-09-10 02:37:44
【问题描述】:

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

【问题讨论】:

  • mountPath 的文档是“容器内应安装卷的路径”,但您提供了文件共享的 URL。请参阅文档中的 example request body
  • @nlawalker 我将 mountPath 更改为 /mountFolder 但仍然是错误的请求

标签: c# azure containers azure-container-instances


【解决方案1】:

此更正存在 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"
}

【讨论】:

  • 我宣布你是救世主。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-27
  • 2017-04-25
  • 1970-01-01
  • 2021-09-17
  • 1970-01-01
相关资源
最近更新 更多