您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

在 Azure 中重新生成本地应用程序Rebuild an on-premises application in Azure

本文演示如何在迁移到 Azure 的过程中,将在 VMware 虚拟机上运行的两层 Windows .NET 应用程序 (Vm) 重建。This article demonstrates how the fictional company Contoso rebuilds a two-tier Windows .NET application that's running on VMware virtual machines (VMs) as part of a migration to Azure. Contoso 将前端 VM 迁移到 Azure App Service 的 web 应用。Contoso migrates the front-end VM to an Azure App Service web app. Contoso 使用部署到 Azure Kubernetes Service (AKS) 管理的容器的微服务生成应用程序后端。Contoso builds the application back end by using microservices that are deployed to containers managed by Azure Kubernetes Service (AKS). 站点与 Azure Functions 进行交互,提供宠物照片功能。The site interacts with Azure Functions to provide pet photo functionality.

本示例中使用的 SmartHotel360 应用程序在开源许可证下提供。The SmartHotel360 application used in this example is provided under an open-source license. 如果要将其用于自己的测试目的,可以从 GitHub下载。If you want to use it for your own testing purposes, you can download it from GitHub.

业务驱动因素Business drivers

Contoso IT 领导团队与其业务合作伙伴密切协作,以了解合作伙伴希望在本次迁移中实现的目标:The Contoso IT leadership team has worked closely with business partners to understand what they want to achieve with this migration:

  • 解决业务增长。Address business growth. Contoso 正在不断增长,希望为 Contoso 网站上的客户提供不同的体验。Contoso is growing and wants to provide differentiated experiences for customers on Contoso websites.
  • 提高灵活性。Be agile. Contoso 必须能够比 marketplace 中的更改更快地做出发展,使其在全球经济中取得成功。Contoso must be able to react faster than the changes in the marketplace to enable their success in a global economy.
  • 纵向.Scale. 当业务成功发展时,Contoso IT 团队必须提供可同时增长的系统。As the business grows successfully, the Contoso IT team must provide systems that can grow at the same pace.
  • 降低成本。Reduce costs. Contoso 希望将许可成本降至最低。Contoso wants to minimize licensing costs.

迁移目标Migration goals

Contoso 云团队已为此迁移固定应用程序要求。The Contoso cloud team has pinned down application requirements for this migration. 这些要求用于确定最佳迁移方式:These requirements were used to determine the best migration method:

  • Azure 中的应用程序必须保持关键,因为它当前位于本地。The application in Azure must remain as critical as it is today on-premises. 它应具有良好的性能并能轻松缩放。It should perform well and scale easily.
  • 应用程序不应使用基础结构即服务 (IaaS) 组件。The application shouldn't use infrastructure as a service (IaaS) components. 所有内容都应该构建为使用平台即服务 (PaaS) 或无服务器服务。Everything should be built to use platform as a service (PaaS) or serverless services.
  • 应用程序生成应在云服务中运行,容器应位于云中的专用企业范围内的注册表中。Application builds should run in cloud services, and containers should reside in a private, enterprise-wide registry in the cloud.
  • 在现实世界中,用于宠物照片的 API 服务应该是准确且可靠的,因为应用程序做出的决策必须在其酒店上生效。The API service that's used for pet photos should be accurate and reliable in the real world, because decisions made by the application must be honored in their hotels. 应当允许经授权进入的任何宠物停留在酒店中。Any pet granted access is allowed to stay at the hotels.
  • 为了满足 DevOps 管道的要求,Contoso 将在 Azure Repos 中使用 Git 存储库进行源代码管理。To meet requirements for a DevOps pipeline, Contoso will use a Git repository in Azure Repos for source code management. 自动化的生成和发布将用于生成代码,并将其部署到 Azure 应用服务、Azure Functions 和 AKS。Automated builds and releases will be used to build code and deploy to Azure App Service, Azure Functions, and AKS.
  • (CI/CD) 管道需要单独进行持续集成/持续开发,微服务在后端和网站上的前端。Separate continuous integration/continuous development (CI/CD) pipelines are needed for microservices on the back end and for the website on the front end.
  • 后端服务和前端 web 应用具有不同的发布周期。The back-end services and the front-end web app have different release cycles. 为了满足此要求,Contoso 将部署两个不同的管道。To meet this requirement, Contoso will deploy two different pipelines.
  • Contoso 在部署所有前端网站时需获得管理批准,并且 CI/CD 管道必须提供此批准。Contoso needs management approval for all front-end website deployment, and the CI/CD pipeline must provide this.

解决方案设计Solution design

在确定其目标和要求后,Contoso 设计并审查部署解决方案,确定迁移流程,包括将用于迁移的 Azure 服务。After pinning down their goals and requirements, Contoso designs and reviews a deployment solution, and identifies the migration process, including the Azure services that will be used for the migration.

当前应用程序Current application

  • SmartHotel360 本地应用程序跨两个 Vm 进行分层 (WEBVMSQLVM) 。The SmartHotel360 on-premises application is tiered across two VMs (WEBVM and SQLVM).
  • 这两个 VM 位于 VMware ESXi 主机 contosohost1.contoso.com(版本 6.5)上。The VMs are located on VMware ESXi host contosohost1.contoso.com (version 6.5).
  • VMware 环境由 VM 上运行的 vCenter Server 6.5 (vcenter.contoso.com) 托管。The VMware environment is managed by vCenter Server 6.5 (vcenter.contoso.com), running on a VM.
  • Contoso 有本地数据中心 (contoso-datacenter),其中包含本地域控制器 (contosodc1)。Contoso has an on-premises datacenter (contoso-datacenter), with an on-premises domain controller (contosodc1).
  • 迁移完成后,Contoso 数据中心的本地 VM 将停止使用。The on-premises VMs in the Contoso datacenter will be decommissioned after the migration is done.

建议的体系结构Proposed architecture

  • 应用程序的前端部署为主要 Azure 区域中的 Azure App Service web 应用。The front end of the application is deployed as an Azure App Service web app in the primary Azure region.

  • 一个 Azure 函数将提供宠物照片上传功能,站点将与此功能进行交互。An Azure function provides uploads of pet photos, and the site interacts with this functionality.

  • 宠物照片函数使用 Azure 认知服务的计算机视觉 API 以及 Azure Cosmos DB。The pet photo function uses the Computer Vision API of Azure Cognitive Services along with Azure Cosmos DB.

  • 站点的后端是使用微服务生成的。The back end of the site is built by using microservices. 这些微服务将部署到在 AKS 中托管的容器。These microservices will be deployed to containers that are managed in AKS.

  • 将使用 Azure DevOps 生成容器,并将其推送到 Azure 容器注册表。Containers will be built using Azure DevOps and then pushed to Azure Container Registry.

  • 现在,Contoso 将使用 Visual Studio 手动部署 web 应用和函数代码。For now, Contoso will manually deploy the web app and function code by using Visual Studio.

  • Contoso 将使用调用 Kubernetes 命令行工具的 PowerShell 脚本来部署微服务。Contoso will deploy microservices by using a PowerShell script that calls Kubernetes command-line tools.

    迁移到 Azure 的方案体系结构示意图。Diagram of scenario architecture for migration to Azure. 图1:方案体系结构。Figure 1: Scenario architecture.

解决方案评审Solution review

Contoso 通过将利弊清单放置在一起来评估其建议的设计。Contoso evaluates the proposed design by putting together a pros and cons list.

注意事项Consideration 详细信息Details
优点Pros 使用 PaaS 和无服务器解决方案进行端到端部署,可大大减少 Contoso 必须提供的管理时间。Using PaaS and serverless solutions for the end-to-end deployment significantly reduces the management time that Contoso must provide.

通过迁移到基于微服务的体系结构,Contoso 可以在一段时间内轻松扩展解决方案。Moving to a microservices-based architecture allows Contoso to easily extend the solution over time.

新功能可以联机,而不会中断现有解决方案的任何代码库。New functionality can be brought online without disrupting any of the existing solutions' code bases.

Web 应用将配置为具有多个实例,无单点故障。The web app will be configured with multiple instances, with no single point of failure.

将启用自动缩放,以便应用程序可以处理不同的流量量。Autoscaling will be enabled so that the application can handle differing traffic volumes.

随着移动到 PaaS 服务,Contoso 可以停用在 Windows Server 2008 R2 操作系统上运行的过时解决方案。With the move to PaaS services, Contoso can retire out-of-date solutions that run on the Windows Server 2008 R2 operating system.

Azure Cosmos DB 具有内置容错能力,Contoso 不需要进行任何配置。Azure Cosmos DB has built-in fault tolerance, which requires no configuration by Contoso. 这意味着数据层不再是单一故障转移点。This means that the data tier is no longer a single point of failover.
缺点Cons 容器比其他迁移选项更加复杂。Containers are more complex than other migration options. 学习曲线对于 Contoso 来说可能是一个问题。The learning curve could be an issue for Contoso. 它们引入了一种新的复杂级别,它可以提供值(尽管是曲线)。They introduce a new level of complexity that provides value in spite of the curve.

Contoso 的运营团队需要增加以了解并支持应用程序的 Azure、容器和微服务。The operations team at Contoso needs to ramp up to understand and support Azure, containers, and microservices for the application.

Contoso 还没有完全为整个解决方案实现 DevOps。Contoso hasn't fully implemented DevOps for the entire solution. Contoso 需要考虑将服务部署到 AKS、Azure Functions 和 Azure 应用服务。Contoso needs to consider that for the deployment of services to AKS, Azure Functions, and Azure App Service.

迁移过程Migration process

  1. Contoso 预配 Azure 容器注册表、AKS 和 Azure Cosmos DB。Contoso provisions Azure Container Registry, AKS, and Azure Cosmos DB.

  2. Contoso 预配部署的基础结构,包括 Azure App Service web 应用、存储帐户、功能和 API。Contoso provisions the infrastructure for the deployment, including the Azure App Service web app, storage account, function, and API.

  3. 基础结构准备就绪后,Contoso 将使用 Azure DevOps 生成其微服务容器映像,并将映像推送到容器注册表。After the infrastructure is in place, Contoso builds their microservices container images by using Azure DevOps, which pushes the images to the container registry.

  4. Contoso 使用 PowerShell 脚本将这些微服务部署到 AKS。Contoso deploys these microservices to AKS by using a PowerShell script.

  5. 最后,Contoso 部署函数和 web 应用。Finally, Contoso deploys the function and web app.

    从准备部署到云中的迁移过程的示意图。Diagram of the migration process from preparation to deployment in the cloud. 图2:迁移过程。Figure 2: The migration process.

Azure 服务Azure services

服务Service 说明Description 成本Cost
Azure Kubernetes 服务Azure Kubernetes Service 简化 Kubernetes 管理、部署和操作。Simplifies Kubernetes management, deployment, and operations. 提供完全托管的 Kubernetes 容器业务流程服务。Provides a fully managed Kubernetes container orchestration service. AKS 是一项免费服务。AKS is a free service. 仅为使用的 Vm 和关联的存储和网络资源付费。Pay for only the VMs and the associated storage and networking resources that are consumed. 了解详细信息Learn more.
Azure FunctionsAzure Functions 通过事件驱动型无服务器计算体验加快开发速度。Accelerates development with an event-driven, serverless compute experience. 按需缩放。Scale on demand. 只需要为使用的资源付费。Pay only for consumed resources. 计划按每秒资源消耗和执行次数收费。Plan is billed based on per-second resource consumption and executions. 了解详细信息Learn more.
Azure 容器注册表Azure Container Registry 用于存储所有类型的容器部署的映像。Stores images for all types of container deployments. 成本基于功能、存储和使用持续时间。Cost is based on features, storage, and usage duration. 了解详细信息Learn more.
Azure 应用服务Azure App Service 快速生成、部署和缩放在任何平台上运行的企业级 web 应用、移动应用和 API 应用。Quickly build, deploy, and scale enterprise-grade web, mobile, and API apps that run on any platform. 应用服务计划以秒为单位进行计费。App Service plans are billed on a per-second basis. 了解详细信息Learn more.

先决条件Prerequisites

对于此方案,Contoso 需具备以下项:Here's what Contoso needs for this scenario:

要求Requirements 详细信息Details
Azure 订阅Azure subscription
  • Contoso 在前面的文章中创建了订阅。Contoso created subscriptions in an earlier article. 如果还没有 Azure 订阅,可以创建一个免费帐户If you don't have an Azure subscription, create a free account.
  • 如果你创建一个免费帐户,你就是订阅的管理员,可以执行所有操作。If you create a free account, you're the admin of your subscription and can perform all actions.
  • 如果你使用现有的订阅,而你不是管理员,则需要与管理员一起为你分配所有者或参与者权限。If you use an existing subscription and you're not the admin, you need to work with the admin to assign Owner or Contributor permissions to you.
  • Azure 基础结构Azure infrastructure
  • 了解 Contoso 如何设置 Azure 基础结构Learn how Contoso set up an Azure infrastructure.
  • 开发人员先决条件Developer prerequisites Contoso 要求开发人员工作站上具有以下工具:Contoso needs the following tools on a developer workstation:
  • Visual Studio 社区2017版本15。5Visual Studio Community 2017 version 15.5
  • .NET 工作负荷,已启用.NET workload, enabled
  • GitGit
  • Azure PowerShellAzure PowerShell
  • Azure CLIThe Azure CLI
  • Docker 社区版 (windows 10) 或 Docker Enterprise edition (Windows Server) ,设置为使用 windows 容器Docker Community Edition (Windows 10) or Docker Enterprise Edition (Windows Server), set to use Windows containers
  • 方案步骤Scenario steps

    Contoso 按如下方式运行迁移:Here's how Contoso will run the migration:

    • 步骤1:预配 AKS 和 Azure 容器注册表。Step 1: Provision AKS and Azure Container Registry. Contoso 使用 PowerShell 预配托管 AKS 群集和容器注册表。Contoso provisions the managed AKS cluster and the container registry by using PowerShell.
    • 步骤2:生成 Docker 容器。Step 2: Build Docker containers. Contoso 使用 Azure DevOps 设置 Docker 容器的持续集成 (CI) ,并将容器推送到容器注册表。Contoso sets up continuous integration (CI) for Docker containers by using Azure DevOps and pushes the containers to the container registry.
    • 步骤3:部署后端微服务。Step 3: Deploy back-end microservices. Contoso 部署后端微服务将使用的基础结构的其余部分。Contoso deploys the rest of the infrastructure that will be used by back-end microservices.
    • 步骤4:部署前端基础结构。Step 4: Deploy front-end infrastructure. Contoso 部署前端基础结构,其中包括宠物手机、Azure Cosmos DB 和计算机视觉 API 的 Blob 存储。Contoso deploys the front-end infrastructure, including Blob Storage for the pet phones, Azure Cosmos DB, and the Computer Vision API.
    • 步骤5:迁移后端。Step 5: Migrate the back end. Contoso 部署微服务,并在 AKS 上运行它们来迁移后端。Contoso deploys microservices and runs them on AKS to migrate the back end.
    • 步骤6:发布前端。Step 6: Publish the front end. Contoso 发布 SmartHotel360 应用程序,Azure App Service,以及宠物服务要调用的函数应用。Contoso publishes the SmartHotel360 application to Azure App Service along with the function app to be called by the pet service.

    预配后端资源Provision back-end resources

    Contoso 管理员通过使用 AKS 和 Azure 容器注册表,运行部署脚本来创建托管 Kubernetes 群集。Contoso admins run a deployment script to create the managed Kubernetes cluster by using AKS and Azure Container Registry. 本部分的说明使用 SmartHotel360 GitHub 存储库。The instructions for this section use the SmartHotel360-Backend GitHub repository. 存储库包含部署的此部分中的所有软件。The repository contains all the software for this part of the deployment.

    确保满足先决条件Ensure that prerequisites are met

    在开始之前,Contoso 管理员确保在用于部署的开发计算机上安装了所有必备软件。Before they start, Contoso admins ensure that all prerequisite software is installed on the dev machine they're using for the deployment. 使用 Git 将存储库克隆到开发计算机:They clone the repository locally to the dev machine by using Git:

    git clone https://github.com/Microsoft/SmartHotel360-Backend.git

    设置 AKS 和 Azure 容器注册表Provision AKS and Azure Container Registry

    Contoso 管理员预配 AKS 和 Azure 容器注册表,如下所示:The Contoso admins provision AKS and Azure Container Registry as follows:

    1. 在 Visual Studio Code 中,它们会打开文件夹,并中转到 /deploy/k8s 包含脚本的目录 gen-aks-env.ps1In Visual Studio Code, they open the folder and go to the /deploy/k8s directory, which contains the script gen-aks-env.ps1.

    2. 他们使用 AKS 和 Azure 容器注册表运行该脚本,以创建托管的 Kubernetes 群集。They run the script to create the managed Kubernetes cluster, using AKS and Azure Container Registry.

      显示 Visual Studio Code 中 AKS 脚本的屏幕截图。Screenshot showing the AKS script in Visual Studio Code. 图3:创建托管 Kubernetes 群集。Figure 3: Creating the managed Kubernetes cluster.

    3. 打开该文件后,会将 $location 参数更新为 eastus2 ,并保存该文件。With the file open, they update the $location parameter to eastus2, and save the file.

      显示更新为 eastus2 的 AKS $location 参数的屏幕截图。Screenshot showing AKS $location parameter updated to eastus2. 图4:保存文件。Figure 4: Saving the file.

    4. 它们选择 "查看 > " "集成终端",在 Visual Studio Code 中打开集成终端。They select View > Integrated terminal to open the integrated terminal in Visual Studio Code.

      显示 "集成终端" 链接的屏幕截图。Screenshot showing the Integrated Terminal link. 图5: Visual Studio Code 中的终端。Figure 5: The terminal in Visual Studio Code.

    5. 在 PowerShell 集成终端中,使用命令登录到 Azure Connect-AzureRmAccountIn the PowerShell integrated terminal, they sign in to Azure using the Connect-AzureRmAccount command. 有关详细信息,请参阅 PowerShell 入门For more information, see Get started with PowerShell.

      PowerShell 集成终端的登录窗口的屏幕截图。Screenshot of the sign-in window for the PowerShell integrated terminal. 图6: PowerShell 集成终端。Figure 6: The PowerShell integrated terminal.

    6. 它们通过运行 az login 命令并按照说明使用其 web 浏览器进行身份验证来对 Azure CLI 进行身份验证。They authenticate the Azure CLI by running the az login command and following the instructions to authenticate using their web browser. 了解有关 用 Azure CLI 登录的详细信息。Learn more about signing in with the Azure CLI.

      显示 Azure CLI 的身份验证窗口的屏幕截图。Screenshot showing the authentication window for the Azure CLI. 图7:对 Azure CLI 进行身份验证。Figure 7: Authenticating the Azure CLI.

    7. 它们运行以下命令,同时传递的资源组名称 ContosoRG 、AKS 群集的名称 smarthotel-aks-eus2 和新的注册表名称。They run the following command while passing the resource group name of ContosoRG, the name of the AKS cluster smarthotel-aks-eus2, and the new registry name.

      .\gen-aks-env.ps1 -resourceGroupName ContosoRg -orchestratorName smarthotelakseus2 -registryName smarthotelacreus2

      显示 "资源组" 窗格上的 "smarthotel" 命令的屏幕截图。Screenshot showing the smarthotel commands on the resource group pane. 图8:运行命令。Figure 8: Running the command.

    8. Azure 会创建另一个资源组,其中包含 AKS 群集的资源。Azure creates another resource group that contains the resources for the AKS cluster.

      资源组创建的屏幕截图。Screenshot of resource group creation. 图9: Azure 创建资源组。Figure 9: Azure creating a resource group.

    9. 部署完成后,它们将安装 kubectl 命令行工具。After the deployment is finished, they install the kubectl command-line tool. 此工具已安装在 Azure Cloud Shell 上。The tool is already installed on the Azure Cloud Shell.

      az aks install-cli

    10. 它们通过运行命令来验证与群集的连接 kubectl get nodesThey verify the connection to the cluster by running the kubectl get nodes command. 节点与自动创建的资源组中的 VM 具有相同的名称。The node has the same name as the VM in the automatically created resource group.

      显示与群集的连接验证的屏幕截图。 图10:验证与群集的连接。Screenshot showing verification of the connection to the cluster. Figure 10: Verifying the connection to the cluster.

    11. 它们运行以下命令来启动 Kubernetes 仪表板:They run the following command to start the Kubernetes dashboard:

      az aks browse --resource-group ContosoRG --name smarthotelakseus2

    12. 浏览器选项卡将打开到仪表板。A browser tab opens to the dashboard. 这是使用 Azure CLI 的隧道连接。This is a tunneled connection that uses the Azure CLI.

      显示隧道连接的屏幕截图。 图11:隧道连接。Screenshot showing a tunneled connection. Figure 11: A tunneled connection.

    步骤 2:配置后端管道Step 2: Configure the back-end pipeline

    创建 Azure DevOps 项目和版本Create an Azure DevOps project and build

    Contoso 创建一个 Azure DevOps 项目,配置 CI 生成以创建容器,然后将其推送到容器注册表。Contoso creates an Azure DevOps project, configures a CI build to create the container, and then pushes it to the container registry. 本部分中的说明使用 SmartHotel360-后端 存储库。The instructions in this section use the SmartHotel360-Backend repository.

    1. 从中 visualstudio.com ,他们将创建一个 () 的新组织 contosodevops360.visualstudio.com ,并将其配置为使用 Git。From visualstudio.com, they create a new organization (contosodevops360.visualstudio.com) and configure it to use Git.

    2. 它们创建一个新项目 (SmartHotelBackend) ,为工作流选择用于版本控制和 敏捷GitThey create a new project (SmartHotelBackend), selecting Git for version control and Agile for the workflow.

      Azure DevOps * * "创建新项目" 窗格的屏幕截图。Screenshot of the Azure DevOps Create new project pane. 图12:创建新项目。Figure 12: Creating a new project.

    3. 导入 GitHub 存储库They import the GitHub repo.

      Azure DevOps 的屏幕截图 * * 导入 Git 存储库 * * 窗格。Screenshot of the Azure DevOps Import a Git repository pane. 图13:导入 GitHub 存储库。Figure 13: Importing the GitHub repo.

    4. 管道 中,它们选择 " 生成 ",并通过将 Azure Repos Git 用作存储库中的源来创建新管道。In Pipelines, they select Build and create a new pipeline by using Azure Repos Git as a source from the repository.

      用于创建新管道的 "DevOps" 窗格的屏幕截图。Screenshot of DevOps pane for creating a new pipeline. 图14:创建新管道。Figure 14: Creating a new pipeline.

    5. 它们选择 空作业They select Empty job.

      Azure DevOps 中的 * * Empty job * * 链接的屏幕截图。Screenshot of the Empty job link in Azure DevOps. 图15:从空作业开始。Figure 15: Starting with an empty job.

    6. 对于生成管道,选择“托管 Linux 预览版”。They select Hosted Linux Preview for the build pipeline.

      在 Azure DevOps 中设置生成管道的屏幕截图。Screenshot of setting up the build pipeline in Azure DevOps. 图16:设置生成管道。Figure 16: Setting up the build pipeline.

    7. 步骤 1 中,他们添加了 Docker Compose 任务。In Step 1, they add a Docker Compose task. 此任务生成 Docker Compose。This task builds the Docker Compose.

      在 Azure DevOps 中构建 Docker Compose 任务的屏幕截图。Screenshot of building a Docker Compose task in Azure DevOps. 图17:构建 Docker Compose。Figure 17: Building the Docker Compose.

    8. 重复操作并添加另一个 Docker Compose 任务。They repeat and add another Docker Compose task. 这会将容器推送到容器注册表。This one pushes the containers to the container registry.

      在 Azure DevOps 中添加另一个 Docker Compose 任务的屏幕截图。Screenshot of adding another Docker Compose task in Azure DevOps. 图18:添加另一个 Docker Compose 任务。Figure 18: Adding another Docker Compose task.

    9. 它们选择第一个任务来生成并配置 Azure 订阅、授权和容器注册表的生成。They select the first task to build and configure the build with the Azure subscription, authorization, and Container Registry.

      在 Azure DevOps 中构建和配置生成的屏幕截图。Screenshot of building and configuring the build in Azure DevOps. 图19:生成并配置生成。Figure 19: Building and configuring the build.

    10. 它们指定存储库的 docker-compose.yaml 文件夹中的文件的路径 srcThey specify the path of the docker-compose.yaml file in the src folder of the repo. 它们选择生成服务映像并包含最新的标记。They choose to build service images and include the latest tag. 当操作更改为“生成服务映像”时,Azure DevOps 任务的名称变为“自动生成服务”。When the action changes to Build service images, the name of the Azure DevOps task changes to Build services automatically.

      Azure DevOps 中各种任务构建详细信息的屏幕截图。 图20:任务的详细信息。Screenshot of various task-building specifics in Azure DevOps. Figure 20: The specifics of the task.

    11. 现在,配置第二个(要推送的)Docker 任务。Now, they configure the second Docker task (to push). 它们选择订阅和容器注册表 (smarthotelacreus2) 。They select the subscription and the container registry (smarthotelacreus2).

      在 Azure DevOps 中配置第二个 Docker 任务的屏幕截图。 图21:配置第二个 Docker 任务。Screenshot of configuring the second Docker task in Azure DevOps. Figure 21: Configuring the second Docker task.

    12. 它们输入 docker-compose.yaml 文件名,然后选择 " 推送服务映像",其中包括最新标记。They enter the docker-compose.yaml file name and select Push service images, including the latest tag. 当操作更改为“推送服务映像”时,Azure DevOps 任务的名称变为“自动推送服务”。When the action changes to Push service images, the name of the Azure DevOps task changes to Push services automatically.

      更改 Azure DevOps 任务名称的屏幕截图。 图22:更改 Azure DevOps 任务名称。Screenshot of changing the Azure DevOps task name. Figure 22: Changing the Azure DevOps task name.

    13. 配置 Azure DevOps 任务后,Contoso 保存生成管道并启动生成过程。With the Azure DevOps tasks configured, Contoso saves the build pipeline and starts the build process.

      在 Azure DevOps 中启动生成过程的屏幕截图。 图23:启动生成过程。Screenshot of starting the build process in Azure DevOps. Figure 23: Starting the build process.

    14. 选择生成作业来检查进度。They select the build job to check progress.

      在 Azure DevOps 中检查生成进度的屏幕截图。 图24:检查进度。Screenshot of checking build progress in Azure DevOps. Figure 24: Checking the progress.

    15. 生成完成后,容器注册表将显示新的存储库,其中填充了微服务使用的容器。After the build finishes, the container registry shows the new repos, which are populated with the containers used by the microservices.

      在 Azure DevOps 中生成完成后查看新存储库的屏幕截图。 图25:生成完成后查看新存储库。Screenshot of viewing new repos after the build finishes in Azure DevOps. Figure 25: Viewing new repos after the build finishes.

    部署后端基础结构Deploy the back-end infrastructure

    创建 AKS 群集并生成 Docker 映像后,Contoso 管理员现在部署后端微服务将使用的基础结构的其余部分。With the AKS cluster created and the Docker images built, Contoso admins now deploy the rest of the infrastructure that will be used by back-end microservices.

    • 本部分中的说明使用 SmartHotel360-后端 存储库。Instructions in this section use the SmartHotel360-Backend repo.
    • 在该 /deploy/k8s/arm 文件夹中,有一个用于创建所有项的脚本。In the /deploy/k8s/arm folder, there's a single script to create all items.

    管理员部署基础结构,如下所示:The admins deploy the infrastructure as follows:

    1. 它们打开开发人员命令提示符,然后使用 az login Azure 订阅的命令。They open a developer command prompt and then use the command az login for the Azure subscription.

    2. 他们使用该 deploy.cmd 文件 ContosoRG East US 2 通过键入以下命令来部署资源组和区域中的 Azure 资源:They use the deploy.cmd file to deploy the Azure resources in the ContosoRG resource group and East US 2 region by typing the following command:

      .\deploy.cmd azuredeploy ContosoRG -c eastus2

      部署后端的屏幕截图。Screenshot of deploying the back end. 图26:部署后端。Figure 26: Deploying the back end.

    3. 在 Azure 门户中,它们捕获每个数据库的连接字符串供以后使用。In the Azure portal, they capture the connection string for each database for later use.

      显示每个数据库的连接字符串的屏幕截图。Screenshot showing the connection string for each database. 图27:捕获每个数据库的连接字符串。Figure 27: Capturing the connection string for each database.

    创建后端发布管道Create the back-end release pipeline

    现在,Contoso 管理员执行以下操作:Now, Contoso admins do the following:

    • 部署 NGINX 入口控制器,以允许入站流量发送到服务。Deploy the NGINX ingress controller to allow inbound traffic to the services.
    • 将微服务部署到 AKS 群集。Deploy the microservices to the AKS cluster.
    • 作为第一步,管理员使用 Azure DevOps 将连接字符串更新为微服务。As a first step, admins update the connection strings to the microservices by using Azure DevOps. 然后,它们配置新的 Azure DevOps release 管道来部署微服务。They then configure a new Azure DevOps release pipeline to deploy the microservices.
    • 本部分中的说明使用 SmartHotel360-后端 存储库。The instructions in this section use the SmartHotel360-Backend repo.
    • 某些配置设置 (例如 Active Directory B2C) 不在本文中介绍。Some of the configuration settings (for example, Active Directory B2C) aren't covered in this article. 有关这些设置的详细信息,请查看前面提到的 SmartHotel360-Backend 存储库。For more information about these settings, review the previously mentioned SmartHotel360-Backend repo.

    管理员创建管道:The admins create the pipeline:

    1. 在 Visual Studio 中,它们 /deploy/k8s/config_local.yml 将用前面提到的数据库连接信息更新文件。In Visual Studio, they update the /deploy/k8s/config_local.yml file with the database connection information that they noted earlier.

    2. 他们打开 Azure DevOps,并在 SmartHotel360 项目中,在 "发布" 窗格中选择 " + 新建管道"。They open Azure DevOps and, in the SmartHotel360 project, they select + New pipeline on the Releases pane.

      显示 Azure DevOps 中的 "新建管道" 按钮的屏幕截图。Screenshot showing the New pipeline button in Azure DevOps. 图29:创建新管道。Figure 29: Creating a new pipeline.

    3. 选择“空作业”启动不带模板的管道。They select Empty Job to start the pipeline without a template.

    4. 提供阶段和管道名称。They provide the stage and pipeline names.

      显示在 Azure DevOps 中创建阶段名称的屏幕截图。Screenshot showing creation of a stage name in Azure DevOps. 图30:阶段名称。Figure 30: The stage name.

      显示在 Azure DevOps 中创建管道名称的屏幕截图。Screenshot showing creation of a pipeline name in Azure DevOps. 图31:管道名称。Figure 31: The pipeline name.

    5. 添加项目。They add an artifact.

      显示在 Azure DevOps 中添加项目的屏幕截图。Screenshot showing adding an artifact in Azure DevOps. 图32:添加项目。Figure 32: Adding an artifact.

    6. 它们选择 Git 作为源类型,并为 SmartHotel360 应用程序指定项目、源和 main 分支。They select Git as the source type and specify the project, source, and main branch for the SmartHotel360 application.

      "添加项目" 窗格的屏幕截图,其中包含 Git 作为源类型。Screenshot of the Add an artifact pane, with Git as the source type. 图33:项目设置窗格。Figure 33: The artifact settings pane.

    7. 选择任务链接。They select the task link.

      显示在 Azure DevOps 中突出显示的任务链接的屏幕截图。Screenshot showing the task link highlighted in Azure DevOps. 图34:任务链接。Figure 34: The task link.

    8. 添加一个新的 Azure PowerShell 任务,以便在 Azure 环境中运行 PowerShell 脚本。They add a new Azure PowerShell task so that they can run a PowerShell script in an Azure environment.

      在 Azure 中添加新 PowerShell 任务的屏幕截图。Screenshot of adding a new PowerShell task in Azure. 图35:添加新的 PowerShell 任务。Figure 35: Adding a new PowerShell task.

    9. 它们为任务选择 Azure 订阅,并 deploy.ps1 从 Git 存储库中选择脚本。They select the Azure subscription for the task and select the deploy.ps1 script from the Git repo.

      从 Git 存储库中选择要运行的脚本的屏幕截图。Screenshot of selecting a script to run from the Git repo. 图36:运行脚本。Figure 36: Running the script.

    10. 将参数添加到脚本。They add arguments to the script. 脚本将删除所有群集内容(入口和入口控制器除外),并部署微服务。The script will delete all cluster content (except ingress and ingress controller), and deploy the microservices.

      显示要添加到脚本的参数的屏幕截图。 图37:向脚本添加参数。Screenshot showing arguments to be added to the script. Figure 37: Adding arguments to the script.

    11. 它们将首选 Azure PowerShell 版本设置为最新版本,并保存管道。They set the preferred Azure PowerShell version to the latest version, and save the pipeline.

    12. 它们将返回到 "新建 发布 " 窗格,并手动创建新版本。They go back to the Create a new release pane and manually create a new release.

      * * "创建新发布" 窗格的屏幕截图。 图38:手动创建新版本。Screenshot of the Create a new release pane. Figure 38: Manually creating a new release.

    13. 创建发布后,它们将其选中,然后在 " 操作" 下,选择 " 部署"。After they create the release, they select it and, under Actions, they select Deploy.

      显示用于部署发布的 "部署" 按钮的屏幕截图。 图39:部署发布。Screenshot highlighting the Deploy button for deploying a release. Figure 39: Deploying a release.

    14. 部署完成后,它们将运行以下命令来检查服务的状态,并使用 Azure Cloud Shell: kubectl get servicesWhen the deployment is complete, they run the following command to check the status of services, using the Azure Cloud Shell: kubectl get services.

    步骤 3:预配前端服务Step 3: Provision front-end services

    Contoso 管理员需要部署前端应用程序将使用的基础结构。Contoso admins need to deploy the infrastructure that will be used by the front-end applications. 它们创建:They create:

    • 用于存储宠物映像的 Blob 存储容器。A Blob Storage container to store the pet images.
    • 用于存储包含宠物信息的文档的 Azure Cosmos DB 数据库。An Azure Cosmos DB database to store documents containing pet information.
    • 网站的计算机视觉 API。The Computer Vision API for the website.

    本部分的说明使用 SmartHotel360 存储库。Instructions for this section use the SmartHotel360-website repo.

    创建 Blob 存储容器Create Blob Storage containers

    1. 在 Azure 门户中,管理员打开创建的存储帐户,然后选择 " blob"。In the Azure portal, the admins open the storage account that was created, and then select Blobs.

    2. 它们创建一个名为的新容器 Pets ,该容器的公共访问级别设置为。They create a new container named Pets with the public-access level set for the container. 用户会将他们的宠物照片上传到此容器。Users will upload their pet photos to this container.

      在 Azure 门户中创建新容器的屏幕截图。Screenshot of creating a new container in the Azure portal. 图40:创建新的容器。Figure 40: Creating a new container.

    3. 它们将创建另一个名为 settings 的新容器。They create a second new container named settings. 一个包含前端应用设置的文件将放置在此容器中。A file with all the front-end app settings will be placed in this container.

      在 Azure 门户中创建第二个新容器的屏幕截图。Screenshot of creating a second new container in the Azure portal. 图41:创建第二个容器。Figure 41: Creating a second container.

    4. 它们捕获文本文件中存储帐户的访问详细信息,以供将来参考。They capture the access details for the storage account in a text file for future reference.

      捕获访问详细信息的文本文件的屏幕截图。Screenshot of a text file capturing access details. 图42:捕获访问详细信息的文本文件。Figure 42: A text file capturing access details.

    预配 Azure Cosmos DB 数据库Provision an Azure Cosmos DB database

    Contoso 管理员预配了用于宠物信息的 Azure Cosmos DB 数据库。Contoso admins provision an Azure Cosmos DB database to be used for pet information.

    1. 它们在 Azure Marketplace 中创建 Azure Cosmos DB 的数据库。They create an Azure Cosmos DB database in Azure Marketplace.

      显示在 Azure Marketplace 中创建 Azure Cosmos DB 数据库的屏幕截图。Screenshot showing the creation of an Azure Cosmos DB database in Azure Marketplace. 图43:创建 Azure Cosmos DB 数据库。Figure 43: Creating an Azure Cosmos DB database.

    2. 它们指定一个名称 contososmarthotel ,选择 SQL API,并将其放在主区域内的生产资源组中 ContosoRG East US 2They specify a name contososmarthotel, select the SQL API, and place it in the production resource group ContosoRG in the main region East US 2.

      Azure Cosmos DB 数据库名称和其他设置的屏幕截图。Screenshot of the Azure Cosmos DB database name and other settings. 图44:命名 Azure Cosmos DB 数据库。Figure 44: Naming an Azure Cosmos DB database.

    3. 向数据库中添加一个具有默认容量和吞吐量的新集合。They add a new collection to the database, with default capacity and throughput.

      Azure Cosmos DB 的 "添加集合" 窗格的屏幕截图。Screenshot of the Add Collection pane for Azure Cosmos DB. 图45:向数据库添加新的集合。Figure 45: Adding a new collection to the database.

    4. 它们记下数据库的连接信息以供将来参考。They note the connection information for the database for future reference.

      Azure Cosmos DB 数据库的连接信息的屏幕截图。Screenshot of the connection information for the Azure Cosmos DB database. 图46:数据库的连接信息。Figure 46: The connection information for the database.

    预配计算机视觉 APIProvision the Computer Vision API

    Contoso 管理员预配计算机视觉 API。Contoso admins provision the Computer Vision API. 该函数将调用 API 来评估用户上载的照片。The API will be called by the function, to evaluate pictures that are uploaded by users.

    1. 管理员在 Azure Marketplace 中创建 计算机视觉 实例。The admins create a Computer Vision instance in Azure Marketplace.

      在 Azure Marketplace 中创建新计算机视觉实例的屏幕截图。Screenshot of creating a new computer vision instance in Azure Marketplace. 图47: Azure Marketplace 中的新实例。Figure 47: A new instance in Azure Marketplace.

    2. 它们预配 smarthotelpets) 在生产资源组中的 API (ContosoRG (East US 2) 。They provision the API (smarthotelpets) in the production resource group ContosoRG, in the main region (East US 2).

      在生产资源组中设置 API 的屏幕截图。Screenshot of setting up an API in a production resource group. 图48:在生产资源组中预配 API。Figure 48: Provisioning an API in a production resource group.

    3. 将该 API 的连接字符串保存到一个文本文件供以后参考。They save the connection settings for the API to a text file for later reference.

      将 API 连接设置保存到文本文件的屏幕截图。Screenshot of saving the API connection settings to a text file. 图49:保存 API 连接设置。Figure 49: Saving the API connection settings.

    预配 Azure Web 应用Provision the Azure web app

    Contoso 管理员使用 Azure 门户预配 web 应用。Contoso admins provision the web app by using the Azure portal.

    1. 在门户中选择“Web 应用”。They select Web App in the portal.

      在 Azure 门户中选择 web 应用的屏幕截图。Screenshot of selecting a web app in the Azure portal. 图50:选择 web 应用。Figure 50: Selecting the web app.

    2. 它们提供 web 应用名称 (smarthotelcontoso) ,在 Windows 上运行,并将其放在生产资源组中 ContosoRGThey provide a web app name (smarthotelcontoso), run it on Windows, and place it in the production resource group ContosoRG. 它们为应用程序监视创建新的 Application Insights 实例。They create a new Application Insights instance for application monitoring.

      提供 web 应用名称和其他详细信息的屏幕截图。Screenshot of providing a web app name and other details. 图51: web 应用名称。Figure 51: The web app name.

    3. 完成后,管理员将浏览到应用程序的地址,以检查是否已成功创建该应用程序。After they're done, the admins browse to the address of the application to check on whether it has been created successfully.

    4. 在 Azure 门户中,它们为代码创建一个过渡槽。In the Azure portal, they create a staging slot for the code. 管道将部署到此槽。The pipeline will be deployed to this slot. 此方法确保在管理员执行发布之前,不会将代码投入生产。This approach ensures that code isn't put into production until the admins perform a release.

      添加 web 应用过渡槽的屏幕截图。Screenshot of adding a web app staging slot. 图52:添加 web 应用过渡槽。Figure 52: Adding a web app staging slot.

    预配 function appProvision the function app

    在 Azure 门户中,Contoso 管理员预配 function app。In the Azure portal, Contoso admins provision the function app.

    1. 选择 Function App。They select Function App.

      显示函数应用创建的屏幕截图。Screenshot showing the creation of a function app. 图53:选择 function app。Figure 53: Selecting the function app.

    2. 它们提供函数应用 () 的名称 smarthotelpetcheckerThey provide a name for the function app (smarthotelpetchecker). 它们将函数应用放在生产资源组中 (ContosoRG) 。They place the function app in the production resource group (ContosoRG). 它们将托管地点设置为 消耗计划,并将函数应用放置在该 East US 2 区域中。They set the hosting place to Consumption Plan, and place the function app in the East US 2 region. 将创建新的存储帐户以及用于监视的 Application Insights 实例。A new storage account is created along with an Application Insights instance for monitoring.

      显示函数应用设置的屏幕截图。Screenshot showing the function app's settings. 图54: Function app 设置。Figure 54: Function app settings.

    3. 在部署函数应用后,管理员浏览到其地址以验证是否已成功创建。After they've deployed the function app, the admins browse to its address to verify that it has been created successfully.

    步骤 4:设置前端管道Step 4: Set up the front-end pipeline

    Contoso 管理员为前端站点创建两个不同的项目。Contoso admins create two different projects for the front-end site.

    1. 在 Azure DevOps 中,他们将创建一个项目 SmartHotelFrontendIn Azure DevOps, they create a project SmartHotelFrontend.

      前端项目的创建屏幕截图。Screenshot of the creation of a front-end project. 图55:创建前端项目。Figure 55: Creating a front-end project.

    2. SmartHotel360 前端 Git 存储库导入到新项目中。They import the SmartHotel360 front end Git repository into the new project.

    3. 对于 function app,它们将创建另一个 Azure DevOps 项目 (SmartHotelPetChecker) 并将 PetChecker Git 存储库导入到此项目中。For the function app, they create another Azure DevOps project (SmartHotelPetChecker) and import the PetChecker Git repository into this project.

    配置 Web 应用Configure the web app

    现在,Contoso 管理员将 Web 应用配置为使用 Contoso 资源。Now Contoso admins configure the web app to use Contoso resources.

    1. 管理员连接到 Azure DevOps 项目,并在本地将存储库克隆到开发计算机。The admins connect to the Azure DevOps project and clone the repository locally to the development machine.

    2. 在 Visual Studio 中,打开文件夹以显示存储库中的所有文件。In Visual Studio, they open the folder to show all the files in the repo.

      Visual Studio 的屏幕截图,其中显示了存储库中的所有文件的文件夹。Screenshot of Visual Studio showing a folder with all the files in the repo. 图56:查看存储库中的所有文件。Figure 56: Viewing all files in the repo.

    3. 更新所需的配置更改。They update the configuration changes as required.

      • 当 web 应用启动时,它会查找 SettingsUrl 应用设置。When the web app starts up, it looks for the SettingsUrl app setting.
      • 此变量必须包含指向配置文件的 URL。This variable must contain a URL that points to a configuration file.
      • 默认情况下,使用的设置是公共终结点。By default, the setting that's used is a public endpoint.
    4. 更新 /config-sample.json/sample.json 文件。They update the /config-sample.json/sample.json file.

      • 这是 web 使用公共终结点时的配置文件。This is the configuration file for the web when it uses the public endpoint.
      • 它们会编辑 urlspets_config 部分,其中包含 AKS API 终结点、存储帐户和 Azure Cosmos DB 数据库的值。They edit the urls and pets_config sections with the values for the AKS API endpoints, storage accounts, and Azure Cosmos DB database.
      • URL 应当与 Contoso 将创建的新 Web 应用的 DNS 名称匹配。The URLs should match the DNS name of the new web app that Contoso will create.
      • 对于 Contoso,这是 smarthotelcontoso.eastus2.cloudapp.azure.comFor Contoso, this is smarthotelcontoso.eastus2.cloudapp.azure.com.

      Visual Studio 中的 json 设置的屏幕截图。Screenshot of the .json settings in Visual Studio. 图57: json 设置。Figure 57: The .json settings.

    5. 更新该文件后,管理员会将其重命名, smarthotelsettingsurl 并将其上传到它们之前创建的 Blob 存储。After they update the file, the admins rename it smarthotelsettingsurl and upload it to the Blob Storage they created earlier.

      重命名和上传 json 文件的屏幕截图。Screenshot of renaming and uploading the .json file. 图58:重命名和上传文件。Figure 58: Renaming and uploading the file.

    6. 选择文件以获取 URL。They select the file to get the URL. 当应用程序拉出配置文件时,将使用该 URL。The URL is used by the application when it pulls down the configuration files.

      应用程序使用的文件的 URL 的屏幕截图。Screenshot of the URL of the file that's used by the application. 图59:应用程序 URL。Figure 59: The application URL.

    7. appsettings.Production.json 文件中,它们将更新 SettingsURL 为新文件的 URL。In the appsettings.Production.json file, they update the SettingsURL to the URL of the new file.

      更新新文件的 URL 的屏幕截图。Screenshot of updating the URL to the new file. 图60:更新新文件的 URL。Figure 60: Updating the URL to the new file.

    将网站部署到 Azure 应用服务Deploy the website to Azure App Service

    Contoso 管理员现在可以发布该网站。Contoso admins can now publish the website.

    1. 它们在 SmartHotelFrontend 生成和发布 的项目中打开 Azure DevOps,并选择 " + 新建管道"。They open Azure DevOps and, in the SmartHotelFrontend project in Builds and Releases, they select + New pipeline.

    2. 选择 Azure DevOps Git 作为源。They select Azure DevOps Git as a source.

    3. 选择 ASP.NET Core 模板。They select the ASP.NET Core template.

    4. 它们查看管道并进行检查以确保选择了 " 发布 Web 项目 " 和 " Zip 已发布项目 "。They review the pipeline and check to ensure that Publish Web Projects and Zip Published Projects are selected.

      Web 项目的管道设置的屏幕截图。Screenshot of the web project's pipeline settings. 图61:管道设置。Figure 61: Pipeline settings.

    5. 触发器 中,它们会启用持续集成并添加 main 分支。In Triggers, they enable continuous integration and add the main branch. 这可确保在解决方案每次将新代码提交到 main 分支时都启动生成管道。This ensures that the build pipeline starts each time the solution has new code committed to the main branch.

      启用持续集成和添加 main 分支的屏幕截图。Screenshot of enabling continuous integration and adding the main branch. 图62:启用持续集成。Figure 62: Enabling continuous integration.

    6. 选择“保存并排队”以启动生成。They select Save & Queue to start a build.

    7. 生成完成后,它们使用 Azure App Service 部署 来配置发布管道。After the build finishes, they configure a release pipeline by using Azure App Service Deployment.

    8. 它们提供阶段名称和 过渡They provide a stage name, Staging.

      为环境提供阶段名称的屏幕截图。Screenshot of providing a stage name for the environment. 图63:命名环境。Figure 63: Naming the environment.

    9. 它们将添加一个项目,并选择它们已配置的生成。They add an artifact and select the build that they've configured.

      添加项目的屏幕截图,生成为源类型。Screenshot of adding an artifact, with Build as the source type. 图64:添加项目。Figure 64: Adding an artifact.

    10. 它们选择项目中的闪电形图标,然后将 "持续部署" 设置为 " 已启用"。They select the lightning bolt icon on the artifact and then set continuous deployment to Enabled.

      启用连续部署的屏幕截图。 图65:启用连续部署。Screenshot of enabling continuous deployment. Figure 65: Enabling continuous deployment.

    11. 在“环境”中,选择“暂存”下的“1 个作业、1 个任务”。In Environment, they select 1 job, 1 task under Staging.

    12. 选择订阅和 web 应用名称后,管理员打开 " 部署 Azure App Service " 任务。After selecting the subscription and web app name, the admins open the Deploy Azure App Service task. 部署配置为使用“暂存”部署槽位。The deployment is configured to use the staging deployment slot. 这会在此槽位中自动生成供评审和批准的代码。This automatically builds code for review and approval in this slot.

      将 web 应用部署到槽的屏幕截图。 图66:部署到槽。Screenshot of deploying the web app to a slot. Figure 66: Deploying to a slot.

    13. 在“管道”中,添加新的阶段。In the Pipeline, they add a new stage.

      "管道" 选项卡的屏幕截图,并添加一个新阶段。 图67:添加新的阶段。Screenshot of the Pipeline tab and adding a new stage. Figure 67: Adding a new stage.

    14. 它们选择 " Azure App Service 部署 ",然后将环境命名为 " 生产"。They select Azure App Service deployment with slot and then name the environment Prod.

    15. 它们选择 " 作业"、"2 个任务 ",然后选择 "订阅"、"应用服务名称" 和 " 过渡 槽"。They select 1 job, 2 tasks and then select the subscription, the app service name, and the staging slot.

      显示环境命名的屏幕截图。 图68:命名环境。Screenshot showing naming the environment. Figure 68: Naming the environment.

    16. 从管道中删除“将 Azure 应用服务部署到槽位中”。They remove the Deploy Azure App Service to Slot from the pipeline. 它是由前面的步骤放置在这里的。It was placed there by the previous steps.

      显示从管道中删除槽的屏幕截图。 图69:从管道中删除槽。Screenshot showing removing a slot from the pipeline. Figure 69: Removing a slot from the pipeline.

    17. 保存管道。They save the pipeline. 在管道中,选择“后期部署条件”。On the pipeline, they select Post-deployment conditions.

      "部署后条件" 按钮的屏幕截图。 图70:部署后条件。Screenshot of the Post-deployment conditions button. Figure 70: Post-deployment conditions.

    18. 它们启用 后期部署审批 ,然后添加开发人员主管作为审批者。They enable Post-deployment approvals and then add a dev lead as the approver.

      启用后部署审批者列表的屏幕截图。 图71:添加审批者。Screenshot of the enabled post-deployment approvers list. Figure 71: Adding an approver.

    19. 在生成管道中,管理员手动启动生成。In the build pipeline, the admins manually kick off a build. 这会触发新的发布管道,该发布管道会将站点部署到过渡槽。This triggers the new release pipeline, which deploys the site to the staging slot. 对于 Contoso,该槽的 URL 是 https://smarthotelcontoso-staging.azurewebsites.net/For Contoso, the URL for the slot is https://smarthotelcontoso-staging.azurewebsites.net/.

    20. 在生成完成并且将发布部署到槽后,Azure DevOps 会向开发人员提供批准的电子邮件。After the build finishes and the release is deployed to the slot, Azure DevOps emails the dev lead for approval.

    21. 开发人员主管选择 查看批准 ,可以在 Azure DevOps 门户中批准或拒绝该请求。The dev lead selects View approval and can approve or reject the request in the Azure DevOps portal.

      部署后审批的屏幕截图 * * 批准或拒绝 * * 链接。 图72:挂起的发布批准请求。Screenshot of the post-deployment approval Approve or reject link. Figure 72: A pending release approval request.

    22. 开发人员主管进行注释并批准。The dev lead makes a comment and approves. 这将开始交换 过渡生产 槽,并将生成转移到生产中。This starts swapping the staging and prod slots and moves the build into production.

      部署后审批和评论的屏幕截图。 图73:将内部版本移到生产环境中。Screenshot of post-deployment approval and comment. Figure 73: Moving the build into production.

    23. 该管道完成交换。The pipeline completes the swap.

      显示生成部署状态的屏幕截图。 图74:完成交换。Screenshot showing the statuses of the build deployment. Figure 74: Completing the swap.

    24. 团队通过访问 https://smarthotelcontoso.azurewebsites.net/ 检查生产槽以验证 Web 应用是否在生产。The team checks the prod slot to verify that the web app is in production at https://smarthotelcontoso.azurewebsites.net/.

    部署 PetChecker function 应用Deploy the PetChecker function app

    Contoso 管理员通过执行以下操作来部署应用程序:Contoso admins deploy the application by doing the following:

    1. 通过连接到 Azure DevOps 项目,将存储库克隆到本地开发计算机。They clone the repository locally to the development machine by connecting to the Azure DevOps project.

    2. 在 Visual Studio 中,打开文件夹以显示存储库中的所有文件。In Visual Studio, they open the folder to show all the files in the repo.

    3. 它们打开该 src/PetCheckerFunction/local.settings.json 文件,并添加存储、Azure Cosmos DB 数据库和计算机视觉 API 的应用设置。They open the src/PetCheckerFunction/local.settings.json file and add the app settings for storage, the Azure Cosmos DB database, and the Computer Vision API.

      Visual Studio 中的 json 文件中的应用设置的屏幕截图。Screenshot of the app settings in the .json file in Visual Studio. 图75:部署函数。Figure 75: Deploying the function.

    4. 它们将提交代码,并将其同步回 Azure DevOps,并推送其更改。They commit the code and sync it back to Azure DevOps, pushing their changes.

    5. 它们将添加新的生成管道,然后为源选择 " Azure DevOps Git "。They add a new build pipeline and then select Azure DevOps Git for the source.

    6. 选择 ASP.NET Core (.NET Framework) 模板。They select the ASP.NET Core (.NET Framework) template.

    7. 接受模板的默认设置。They accept the defaults for the template.

    8. 在 " 触发器" 下,选择 " 启用持续集成 ",然后选择 " 保存 & 队列 " 以启动生成。Under Triggers, they select Enable continuous integration and then select Save & Queue to start a build.

    9. 生成成功后,它们将生成一个发布管道, 并使用槽添加 Azure App Service 部署After the build succeeds, they build a release pipeline, adding Azure App Service deployment with slot.

    10. 它们将环境命名为 " 生产 ",然后选择订阅。They name the environment Prod and then select the subscription. 他们将 应用程序类型 设置为 Function App ,将应用服务名称设置为 smarthotelpetcheckerThey set the App type to Function App and the app service name as smarthotelpetchecker.

      应用类型和应用服务名称的屏幕截图。 图76:函数应用。Screenshot of the app type and app service name. Figure 76: The function app.

    11. 它们将添加项目 " 生成"。They add an artifact, Build.

      使用生成源类型添加项目的屏幕截图。 图77:添加项目。Screenshot of adding an artifact, with the Build source type. Figure 77: Adding an artifact.

    12. 它们启用 连续部署触发器 ,然后选择 " 保存"。They enable Continuous deployment trigger and then select Save.

    13. 选择“对新版本进行排队”运行完整的 CI/CD 管道。They select Queue new build to run the full CI/CD pipeline.

    14. 部署函数后,它将出现在状态为 " 正在运行" 的 Azure 门户中。After the function is deployed, it appears in the Azure portal with the status Running.

      函数应用屏幕截图,显示 * * 正在运行的 * * 状态。 图78:更新函数的状态。Screenshot of the function app, showing a Running status. Figure 78: Updating the function's status.

    15. 他们浏览到宠物检查器应用程序,以 http://smarthotel360public.azurewebsites.net/pets 验证它是否正常工作。They browse to the pet checker application, at http://smarthotel360public.azurewebsites.net/pets, to verify that it's working properly.

    16. 选择头像来上传图片。They select the avatar to upload a picture.

      用于将图片分配给头像的窗格屏幕截图。 图79:将图片分配给头像。Screenshot of the pane for assigning a picture to an avatar. Figure 79: Assigning a picture to an avatar.

    17. 他们要检查的第一张照片是一只小狗的照片。The first photo they want to check is of a small dog.

      显示狗照片的屏幕截图。 图80:检查照片。Screenshot showing a photo of a dog. Figure 80: Checking the photo.

    18. 应用程序返回接受消息。The application returns an acceptance message.

      接受消息的屏幕截图。 图81:接受消息。Screenshot of an acceptance message. Figure 81: An acceptance message.

    查看部署Review the deployment

    Azure 显示已迁移的资源后,Contoso 现在需要积极行动、全面保护新的基础结构。With the migrated resources in Azure, Contoso now needs to fully operationalize and secure the new infrastructure.

    安全性Security

    备份和灾难恢复Backups and disaster recovery

    许可和成本优化Licensing and cost optimization

    • 部署所有资源后,Contoso 应当根据其基础结构规划分配 Azure 标记。After all resources are deployed, Contoso should assign Azure tags based on their infrastructure planning.
    • 所有许可成本都包括在 Contoso 使用的 PaaS 服务的成本中。All licensing is built into the cost of the PaaS services that Contoso is consuming. 这将从企业协议中扣减。This will be deducted from the Enterprise Agreement.
    • Contoso 将启用 Azure 成本管理 + 计费 ,以帮助监视和管理 azure 资源。Contoso will enable Azure Cost Management + Billing to help monitor and manage the Azure resources.

    结论Conclusion

    在本文中,Contoso 在 Azure 中重新生成 SmartHotel360 应用程序。In this article, Contoso rebuilds the SmartHotel360 application in Azure. 为 Azure App Service web 应用重新生成了本地应用程序前端 VM。The on-premises application front-end VM is rebuilt for Azure App Service web apps. 应用程序后端是使用部署到由 AKS 管理的容器的微服务生成的。The application back end is built by using microservices that are deployed to containers managed by AKS. Contoso 使用宠物照片应用程序增强了功能。Contoso enhanced functionality with a pet photo application.

    建议的技能Suggested skills

    Microsoft Learn 是学习的一种新方法。Microsoft Learn is a new approach to learning. 对云采用带来的新技能和新责任准备就绪并不容易。Readiness for the new skills and responsibilities that come with cloud adoption doesn't come easily. Microsoft Learn 提供了更好的方法来进行实践学习,有助于更快地实现目标。Microsoft Learn provides a more rewarding approach to hands-on learning that helps you achieve your goals faster. 使用 Microsoft Learn,你可以获得积分,通过级别上升,实现更多。With Microsoft Learn, you can earn points, rise through levels, and achieve more.

    下面是两个示例,介绍如何在与 Azure 中的 Contoso SmartHotel360 应用程序一致的 Microsoft Learn 上定制学习路径。Here are two examples of tailored learning paths on Microsoft Learn that align with the Contoso SmartHotel360 application in Azure.

    • 使用 Azure App Service 将网站部署到 Azure 通过在 Azure 中创建 web 应用,可以轻松地发布和管理网站,而无需使用基础服务器、存储或网络资产。Deploy a website to Azure with Azure App Service: By creating web apps in Azure, you can publish and manage your website easily without having to work with the underlying servers, storage, or network assets. 相反,你可以专注于你的网站功能,并依赖于可靠的 Azure 平台,以帮助提供对你的网站的安全访问。Instead, you can focus on your website features and rely on the robust Azure platform to help provide secure access to your site.

    • 利用 Azure 认知愿景服务处理图像并对其进行分类 Azure 认知服务提供预先构建的功能,可在应用程序中启用计算机视觉功能。Process and classify images with the Azure cognitive vision services: Azure Cognitive Services offers prebuilt functionality to enable computer vision functionality in your applications. 了解如何使用 Azure 认知愿景服务来检测人脸、标记和分类图像以及确定对象。Learn how to use the Azure cognitive vision services to detect faces, tag and classify images, and identify objects.