使用 PowerShell 创建和部署应用程序

注释

基本计划和标准计划于 2025 年 3 月 17 日进入退休期。 有关详细信息,请参阅 Azure Spring Apps 停用公告

本文介绍如何使用 Az.SpringCloud PowerShell 模块创建Azure Spring Apps实例。

要求

完成本文中的步骤的要求取决于Azure订阅:

  • 如果没有Azure订阅,请在开始前创建 Trial

重要

尽管 Az.SpringCloud PowerShell 模块为预览版,但你需要通过使用 cmdlet 来安装它。 请参阅以下命令。 此 PowerShell 模块正式发布后,它会包含在将来的 Az PowerShell 版本中。

Install-Module -Name Az.SpringCloud
  • 如果有多个 Azure 订阅,请选择适当的订阅以便对资源进行计费。 使用 Set-AzContext cmdlet 选择特定订阅:

    Set-AzContext -SubscriptionId <subscription-ID>
    

创建资源组

资源组是一个逻辑容器,在其中部署和管理 Azure 资源作为一个整体。 使用 New-AzResourceGroup cmdlet 创建 Azure 资源组。 以下示例将创建具有指定名称和位置的资源组。

New-AzResourceGroup -Name <resource group name> -Location chinanorth2

配置新实例

若要创建新Azure Spring Apps实例,请使用 New-AzSpringCloud cmdlet。 以下示例创建一个Azure Spring Apps服务,其中包含前面创建的资源组中指定的名称。

New-AzSpringCloud -ResourceGroupName <resource group name> -name <service instance name> -Location chinanorth2

创建新应用程序

若要创建新应用,请使用 New-AzSpringCloudApp cmdlet。 以下示例在名为 gateway 的Azure Spring Apps中创建应用。

New-AzSpringCloudApp -ResourceGroupName <resource group name> -ServiceName <service instance name> -AppName gateway

创建新的应用部署

若要创建新的应用部署,请使用 New-AzSpringCloudAppDeployment cmdlet。 以下示例在 Azure Spring Apps 中为名为 default 的应用创建一个名为 gateway 的应用部署,包含一个空的欢迎应用程序。

$welcomeApplication = New-AzSpringCloudAppDeploymentJarUploadedObject -RuntimeVersion "Java_11"
New-AzSpringCloudAppDeployment -ResourceGroupName <resource group name> -ServiceName <service instance name> -AppName gateway -Name default -Source $welcomeApplication

获取服务及其属性

若要获取Azure Spring Apps服务及其属性,请使用 Get-AzSpringCloud cmdlet。 以下示例检索有关指定Azure Spring Apps服务的信息。

Get-AzSpringCloud -ResourceGroupName <resource group name> -ServiceName <service instance name>

获取应用程序

若要在 Azure Spring Apps 中获取应用及其属性,请使用 Get-AzSpringCloudApp cmdlet。 以下示例检索有关应用 gateway 的信息。

Get-AzSpringCloudApp -ResourceGroupName <resource group name> -ServiceName <service instance name> -AppName gateway

获取应用部署

若要在 Azure Spring Apps中获取应用部署及其属性,请使用 Get-AzSpringCloudAppDeployment cmdlet。 以下示例检索有关 default Azure Spring Apps 部署的信息。

Get-AzSpringCloudAppDeployment -ResourceGroupName <resource group name> -ServiceName <service instance name> -AppName gateway -DeploymentName default

清理资源

如果不再需要使用本文中创建的资源,可以通过运行以下部分所示的示例将其删除。

删除应用部署

若要删除Azure Spring Apps中的应用部署,请使用 Remove-AzSpringCloudAppDeployment cmdlet。 以下示例删除为指定服务和应用部署在名为 default 的Azure Spring Apps中的应用。

Remove-AzSpringCloudAppDeployment -ResourceGroupName <resource group name> -ServiceName <service instance name> -AppName gateway -DeploymentName default

删除应用

若要删除Azure Spring Apps中的应用,请使用 Remove-AzSpringCloudApp cmdlet。 以下示例删除指定服务和资源组中的 gateway 应用。

Remove-AzSpringCloudApp -ResourceGroupName <resource group name> -ServiceName <service instance name> -AppName gateway

删除服务

若要删除Azure Spring Apps服务,请使用 Remove-AzSpringCloud cmdlet。 以下示例删除指定的Azure Spring Apps服务。

Remove-AzSpringCloud -ResourceGroupName <resource group name> -ServiceName <service instance name>

删除资源组

注意

以下示例删除指定的资源组及其包含的所有资源。 如果指定的资源组中存在本文范围外的资源,这些资源也会被删除。

Remove-AzResourceGroup -Name <resource group name>

后续步骤

Azure Spring Apps开发人员资源