当我们部署带有-smalldisk映像的Service Fabric群集VMSS时
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模板)增加磁盘大小?
答案 0 :(得分:0)
在Service Fabric / VMSS 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')]"
}
}
}
...
将自定义脚本扩展名添加到VMSS 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
来调整OS磁盘分区的大小
# resize Partition
$size = (Get-PartitionSupportedSize -DiskNumber 0 -PartitionNumber 1)
Resize-Partition -DiskNumber 0 -PartitionNumber 1 -Size $size.SizeMax