教程:删除在 Azure 中运行的 Service Fabric 群集Tutorial: Remove a Service Fabric cluster running in Azure

本教程是一个系列的第五部分,介绍了如何删除在 Azure 中运行的 Service Fabric 群集。This tutorial is part five of a series, and shows you how to delete a Service Fabric cluster running in Azure. 若要彻底删除 Service Fabric 群集,还需要删除该群集使用的所有资源。To completely delete a Service Fabric cluster you also need to delete the resources used by the cluster. 可使用两种方法:删除该群集所在的资源组(此操作将删除群集资源以及该资源组中的所有其他资源),或特定删除群集资源及其关联资源(而不删除资源组中的其他资源)。You have two options: either delete the resource group that the cluster is in (which deletes the cluster resource and all other resources in the resource group) or specifically delete the cluster resource and it's associated resources (but not other resources in the resource group).

在本教程中,你将了解如何执行以下操作:In this tutorial, you learn how to:

  • 删除资源组及其所有资源Delete a resource group and all it's resources
  • 有选择地从资源组中删除资源Selectively delete resources from a resource group

在此系列教程中,你会学习如何:In this tutorial series you learn how to:

备注

本文进行了更新,以便使用新的 Azure PowerShell Az 模块。This article has been updated to use the new Azure PowerShell Az module. 你仍然可以使用 AzureRM 模块,至少在 2020 年 12 月之前,它将继续接收 bug 修补程序。You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. 若要详细了解新的 Az 模块和 AzureRM 兼容性,请参阅新 Azure Powershell Az 模块简介To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. 有关 Az 模块安装说明,请参阅安装 Azure PowerShellFor Az module installation instructions, see Install Azure PowerShell.

必备条件Prerequisites

在开始学习本教程之前:Before you begin this tutorial:

删除包含 Service Fabric 群集的资源组Delete the resource group containing the Service Fabric cluster

若要删除群集及其占用的所有资源,最简单的方式是删除资源组。The simplest way to delete the cluster and all the resources it consumes is to delete the resource group.

登录到 Azure,选择要删除群集的订阅 ID。Sign in to Azure and select the subscription ID with which you want to remove the cluster. 可通过登录到 Azure 门户查找订阅 ID。You can find your subscription ID by logging in to the Azure portal. 使用 Remove-AzResourceGroup cmdlet 或 az group delete 命令删除资源组和所有群集资源。Delete the resource group and all the cluster resources using the Remove-AzResourceGroup cmdlet or az group delete command.

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

有选择地删除群集资源和关联的资源Selectively delete the cluster resource and the associated resources

如果资源组仅包含与要删除的 Service Fabric 群集相关的资源,那么删除整个资源组更方便。If your resource group has only resources that are related to the Service Fabric cluster you want to delete, then it is easier to delete the entire resource group. 如果希望有选择地删除资源组中的资源,并保留未与群集关联的资源,请执行以下步骤。If you want to selectively delete the resources in your resource group, and keep resources not associated with the cluster, then follow these steps.

列出资源组中的资源:List the resources in the resource group:

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

对要删除的每项资源,运行以下脚本:For each of the resources you want to delete, run the following script:

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

若要删除群集资源,请运行以下脚本:To delete the cluster resource, run the following script:

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

后续步骤Next steps

在本教程中,你了解了如何执行以下操作:In this tutorial, you learned how to:

  • 删除资源组及其所有资源Delete a resource group and all it's resources
  • 有选择地从资源组中删除资源Selectively delete resources from a resource group

现在你已完成了本教程,请尝试执行以下任务:Now that you've completed this tutorial, try the following: