为了账号安全,请及时绑定邮箱和手机立即绑定

如何使用 REST api 将文件存储卷挂载到 Azure 容器实例

如何使用 REST api 将文件存储卷挂载到 Azure 容器实例

C#
杨魅力 2022-12-24 10:16:45
我正在尝试创建 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。
查看完整描述

1 回答

?
翻翻过去那场雪

TA贡献2065条经验 获得超14个赞

此更正有 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://learn.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"

}


查看完整回答
反对 回复 2022-12-24
  • 1 回答
  • 0 关注
  • 55 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号