教程:删除在 Azure 中运行的 Service Fabric 群集

本教程是一个系列的第五部分,介绍了如何删除在 Azure 中运行的 Service Fabric 群集。 若要彻底删除 Service Fabric 群集,还需要删除该群集使用的所有资源。 可使用两种方法:删除该群集所在的资源组(此操作将删除群集资源以及该资源组中的所有其他资源),或特定删除群集资源及其关联资源(而不删除资源组中的其他资源)。

在本教程中,你将了解如何执行以下操作:

  • 删除资源组及其所有资源
  • 有选择地从资源组中删除资源

在此系列教程中,你会学习如何:

注意

建议使用 Azure Az PowerShell 模块与 Azure 交互。 请参阅安装 Azure PowerShell 以开始使用。 若要了解如何迁移到 Az PowerShell 模块,请参阅 将 Azure PowerShell 从 AzureRM 迁移到 Az

先决条件

在开始学习本教程之前:

删除包含 Service Fabric 群集的资源组

若要删除群集及其占用的所有资源,最简单的方式是删除资源组。

登录到 Azure,选择要删除群集的订阅 ID。 可通过登录到 Azure 门户查找订阅 ID。 使用 Remove-AzResourceGroup cmdlet 或 az group delete 命令删除资源组和所有群集资源。

Connect-AzAccount -Environment AzureChinaCloud
Set-AzContext -SubscriptionId <guid>
$groupname = "sfclustertutorialgroup"
Remove-AzResourceGroup -Name $groupname -Force
az login
az account set --subscription <guid>
ResourceGroupName="sfclustertutorialgroup"
az group delete --name $ResourceGroupName

有选择地删除群集资源和关联的资源

如果资源组仅包含与要删除的 Service Fabric 群集相关的资源,那么删除整个资源组更方便。 如果希望有选择地删除资源组中的资源,并保留未与群集关联的资源,请执行以下步骤。

列出资源组中的资源:

Connect-AzAccount -Environment AzureChinaCloud
Set-AzContext -SubscriptionId <guid>
$groupname = "sfclustertutorialgroup"
Get-AzResource -ResourceGroupName $groupname | ft
az login
az account set --subscription <guid>
ResourceGroupName="sfclustertutorialgroup"
az resource list --resource-group $ResourceGroupName

对要删除的每项资源,运行以下脚本:

Remove-AzResource -ResourceName "<name of the Resource>" -ResourceType "<Resource Type>" -ResourceGroupName $groupname -Force
az resource delete --name "<name of the Resource>" --resource-type "<Resource Type>" --resource-group $ResourceGroupName

若要删除群集资源,请运行以下脚本:

Remove-AzResource -ResourceName "<name of the Resource>" -ResourceType "Microsoft.ServiceFabric/clusters" -ResourceGroupName $groupname -Force
az resource delete --name "<name of the Resource>" --resource-type "Microsoft.ServiceFabric/clusters" --resource-group $ResourceGroupName

后续步骤

在本教程中,你了解了如何执行以下操作:

  • 删除资源组及其所有资源
  • 有选择地从资源组中删除资源

现在你已完成了本教程,请尝试执行以下任务: