使用图库镜像创建VMSS时提示'osProfile参数不允许',该如何解决?
问题原因
专用(Specialized)类型的Azure Compute Gallery镜像已包含完整的操作系统配置(如预创建的root用户、已配置的SSH密钥等)。基于这类镜像创建VMSS时,Azure Compute API不允许再传入osProfile参数,否则会抛出Parameter 'osProfile' is not allowed异常。
你的代码中调用了.WithRootUsername(userName)和.WithSsh(publicKey)方法,这会触发Fluent API自动生成osProfile字段并发送给Azure API,违反了专用镜像的使用规则。
修正后的代码
移除设置OS用户和SSH密钥的两行代码即可:
using Microsoft.Azure.Management.Fluent; using Microsoft.Azure.Management.Compute.Fluent; ... IGalleryImageVersion image = ... IVirtualMachineScaleSet vmss = await Azure.VirtualMachineScaleSets .Define(vmssName) .WithRegion(region) .WithExistingResourceGroup(rgName) .WithSku(sku) .WithExistingPrimaryNetworkSubnet(network, subnetName) .WithoutPrimaryInternetFacingLoadBalancer() .WithoutPrimaryInternalLoadBalancer() .WithLinuxGalleryImageVersion(image.Id) .WithNewDataDisk(dataDiskSize) .WithCapacity(intendedSize) .WithExistingUserAssignedManagedServiceIdentity(identity) .WithVirtualMachinePublicIp() .CreateAsync(token);
补充说明
- 专用镜像的VMSS实例会直接复用镜像中已有的OS配置,无需重复指定用户或SSH密钥;
- 仅当使用通用(Generalized)镜像时,才需要通过
.WithRootUsername和.WithSsh这类方法配置OS用户信息; - Fluent API无需显式“省略”参数,只要不调用相关配置方法,就不会生成
osProfile字段,符合Azure API对专用镜像的要求。
内容的提问来源于stack exchange,提问作者Alexandre Khodakovski
相关产品推荐
相关产品推荐

