代码之家  ›  专栏  ›  技术社区  ›  Kai Walter

如何为基于Windows Server SmallDisk的虚拟机或服务结构群集扩展操作系统磁盘?

  •  0
  • Kai Walter  · 技术社区  · 6 年前

    当我们部署带有-smalldisk映像的服务结构集群vms时

    ARM模板参数:

    "vmImageOffer": {
      "value": "WindowsServerSemiAnnual"
    },
    "vmImageSku": {
      "value": "Datacenter-Core-1803-with-Containers-smalldisk"
    },
    "vmImageVersion": {
      "value": "1803.0.20180613"
    }
    

    ARM模板:

    "storageProfile": {
      "imageReference": {
        "publisher": "[parameters('vmImagePublisher')]",
        "offer": "[parameters('vmImageOffer')]",
        "sku": "[parameters('vmImageSku')]",
        "version": "[parameters('vmImageVersion')]"
    },
    

    没有足够的空间(<30GB)在SF群集上承载容器映像。

    如何在部署时增加磁盘大小(使用ARM模板)?

    1 回复  |  直到 6 年前
        1
  •  0
  •   Kai Walter    6 年前

    向服务结构/vms arm模板添加了3个参数:

    ...
    "scriptLocation": {
      "type": "string",
      "metadata": {
        "description": "Location of custom extension scripts on storage account container"
      }
    },
    "scriptStorageAccount": {
      "type": "string",
      "metadata": {
        "description": "Name of custom extension scripts storage account"
      }
    },
    "scriptStorageAccountKey": {
      "type": "string",
      "metadata": {
        "description": "Key to custom extension scripts storage account"
      }
    },
    ...
    

    这些参数填充在powershell脚本中,上载自定义扩展脚本文件并调用 New-AzureRmResourceGroupDeployment 是的。

    ...
    $StorageAccountName = "mydeploymentstorage"
    $StorageContainerName = "ext"
    $ArtifactStagingDirectory = ".\ExtensionScripts"
    ...
    # transfer Extension script to Storage    $StorageAccount = (Get-AzureRmStorageAccount | Where-Object{$_.StorageAccountName -eq $StorageAccountName})
    $StorageAccountContext = $StorageAccount.Context
    New-AzureStorageContainer -Name $StorageContainerName -Context $StorageAccountContext -Permission Container -ErrorAction SilentlyContinue *>&1
    $ArtifactFilePaths = Get-ChildItem $ArtifactStagingDirectory -Recurse -File | ForEach-Object -Process {$_.FullName}
    foreach ($SourcePath in $ArtifactFilePaths) {
        Write-Host "transfering" $SourcePath
        $BlobName = $SourcePath.Substring($SourcePath.LastIndexOf("\")+1)
        Set-AzureStorageBlobContent -File $SourcePath -Blob $BlobName -Container $StorageContainerName -Context $StorageAccountContext -Force -ErrorAction Stop
    }
    
    # prepare and pass script parameters
    $DynamicParameters = New-Object -TypeName Hashtable
    $DynamicParameters["scriptLocation"] = $StorageAccountContext.BlobEndPoint + $StorageContainerName
    $DynamicParameters["scriptStorageAccount"] = $StorageAccountName
    $DynamicParameters["scriptStorageAccountKey"] = ($StorageAccount | Get-AzureRmStorageAccountKey).Value[0]
    ...
    # start deployment
    New-AzureRmResourceGroupDeployment -Name ((Get-ChildItem $TemplateFile).BaseName + '-' + ((Get-Date).ToUniversalTime()).ToString('MMdd-HHmm')) ` `
        -ResourceGroupName $ResourceGroupName `
        -TemplateFile $TemplateFile `
        -TemplateParameterFile $TemplateParametersFile `
        @DynamicParameters `
        -Verbose
    

    增加了磁盘大小 storageProfile 以下内容:

    ...
          "storageProfile": {
            "imageReference": {
              "publisher": "[parameters('vmImagePublisher')]",
              "offer": "[parameters('vmImageOffer')]",
              "sku": "[parameters('vmImageSku')]",
              "version": "[parameters('vmImageVersion')]"
            },
            "osDisk": {
              "caching": "ReadWrite",
              "createOption": "FromImage",
              "diskSizeGB": 128,
              "managedDisk": {
                "storageAccountType": "[parameters('storageAccountType')]"
              }
            }
          }
    ...
    

    将自定义脚本扩展添加到vms extensionProfile 以下内容:

    ...
        "virtualMachineProfile": {
          "extensionProfile": {
            "extensions": [
    ...
              {
                "name": "[concat(parameters('vmNodeType0Name'),'_SetupNode')]",
                "properties": {
                  "publisher": "Microsoft.Compute",
                  "type": "CustomScriptExtension",
                  "typeHandlerVersion": "1.9",
                  "autoUpgradeMinorVersion": true,
                  "settings": {
                    "fileUris": [
                      "[concat(parameters('scriptLocation'),'/setupNode.ps1')]"
                    ]
                  },
                  "protectedSettings": {
                    "commandToExecute": "powershell -ExecutionPolicy Unrestricted -File CreateDisk.ps1",
                    "storageAccountName": "[parameters('scriptStorageAccount')]",
                    "storageAccountKey": "[parameters('scriptStorageAccountKey')]"
                  }
                }
              }
            ]
    ...
    

    创建了脚本 setupNode.PS1 调整操作系统磁盘分区的大小

    # resize Partition
    $size = (Get-PartitionSupportedSize -DiskNumber 0 -PartitionNumber 1) 
    Resize-Partition -DiskNumber 0 -PartitionNumber 1 -Size $size.SizeMax