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

迁移到 Bridge to KubernetesMigrating to Bridge to Kubernetes

重要

Azure Dev Spaces 将于2023年10月31日停用。Azure Dev Spaces will be retired on October 31, 2023. 客户应转向使用客户开发人员工具,通过 Kubernetes。Customers should move to using Bridge to Kubernetes, a client developer tool.

Azure Dev Spaces 的目的是便于用户在 Kubernetes 上进行开发。The purpose of Azure Dev Spaces was about easing users into developing on Kubernetes. Azure Dev Spaces 的一项重大折衷是,对用户造成了额外的负担,以了解 Docker 和 Kubernetes 的配置以及 Kubernetes 的部署概念。A significant tradeoff in the approach of Azure Dev Spaces was putting extra burden on users to understand Docker and Kubernetes configurations as well as Kubernetes deployment concepts. 随着时间的推移,这种方法也显而易见了,Azure Dev Spaces 的方法不能有效地降低 Kubernetes 上的内部循环开发速度。Over time, it also became clear that the approach of Azure Dev Spaces did not effectively decrease the speed of inner loop development on Kubernetes. 桥接 Kubernetes 可有效降低内部循环开发的速度,并避免对用户造成不必要的负担。Bridge to Kubernetes effectively decreases the speed of inner loop development and avoids unnecessary burden on users.

核心任务保持不变:在更大的应用程序的上下文中生成用于开发、测试和调试微服务代码的最佳体验。The core mission remains unchanged: Build the best experiences to develop, test, and debug microservice code in the context of the larger application.

桥接 Kubernetes 为使用 Azure Dev Spaces 的许多开发方案提供更轻量的替代方法。Bridge to Kubernetes provides a lighter weight alternative to many of the development scenarios that work with Azure Dev Spaces. 桥接 Kubernetes 是在Visual Studio   和 Visual Studio Code中使用扩展的仅限客户端体验。Bridge to Kubernetes is a client-side only experience using extensions in Visual Studio and Visual Studio Code.

桥接 Kubernetes 通过允许已建立的 Kubernetes 应用程序包括在本地开发工作站上运行的服务,帮助你的开发体验。Bridge to Kubernetes helps your development experience by allowing an established Kubernetes application to include a service running on your local development workstation. 与开发人员共享空间不同,桥接于 Kubernetes 可减少内部循环复杂性,因为需要创建 Docker 和 Kubernetes 配置,使开发人员能够专注于其微服务代码的业务逻辑。Unlike Dev Spaces, Bridge to Kubernetes reduces inner loop complexities by side-stepping the need to create Docker and Kubernetes configurations, allowing developers to focus purely on the business logic of their microservice code.

桥接 Kubernetes 可帮助您循环访问开发计算机上运行的代码,同时使用依赖项和 Kubernetes 环境中的现有配置。Bridge to Kubernetes helps you to iterate on code running on your development computer while consuming dependencies and existing configuration from your Kubernetes environment. 与此相反,Azure Dev Spaces 将微服务部署到 Kubernetes 环境中,然后才能远程调试服务并循环访问代码。In contrast, Azure Dev Spaces deploys your microservice into the Kubernetes environment before you can remotely debug your service and iterate on your code.

本文提供 Azure Dev Spaces 与 Kubernetes 之间的比较,以及从 Azure Dev Spaces 迁移到 Kubernetes 的说明。This article provides a comparison between Azure Dev Spaces and Bridge to Kubernetes as well as instructions for migrating from Azure Dev Spaces to Bridge to Kubernetes.

开发方法Development Approaches

开发方法

Azure Dev Spaces 帮助 Kubernetes 开发人员使用直接在其 AKS 群集中运行的代码,从而避免了对不类似于已部署环境的本地环境的需求。Azure Dev Spaces helped Kubernetes developers work with code running directly in their AKS cluster, avoiding the need for a local environment that did not resemble the deployed environment. 这种方法可以改进开发的某些方面,但也引入了学习和维护其他概念(如 Docker、Kubernetes 和 Helm),然后才能开始使用 Azure Dev Spaces。This approach improved certain aspects of development, but it also introduced a prerequisite of learning and maintaining additional concepts such as Docker, Kubernetes, and Helm before you could start using Azure Dev Spaces.

桥接 Kubernetes 使开发人员能够直接在其开发计算机上工作,同时与群集的其余部分交互。Bridge to Kubernetes allows developers to work directly on their development computers while interacting with the rest of their cluster. 此方法在共享其群集提供的依赖关系和环境的同时,直接利用在开发计算机上运行代码的熟悉和速度。This approach takes advantage of the familiarity and speed of running code directly on their development computers while sharing the dependencies and environment provided by their cluster. 此方法还利用了在 Kubernetes 中运行的保真度和缩放。This approach also takes advantage of the fidelity and scaling that comes from running in Kubernetes.

功能对比Feature Comparison

Azure Dev Spaces 和桥接 Kubernetes 具有类似的功能,它们在多个区域中也有所不同:Azure Dev Spaces and Bridge to Kubernetes have similar features, they also differ in several areas:

要求Requirement Azure Dev SpacesAzure Dev Spaces Bridge to KubernetesBridge to Kubernetes
Azure Kubernetes 服务Azure Kubernetes Service 15个 Azure 区域In 15 Azure regions 任何 AKS 服务区域Any AKS service region
安全性Security
群集上所需的安全访问Security access needed on your cluster AKS 群集参与者AKS Cluster contributor Kubernetes RBAC-部署更新Kubernetes RBAC -Deployment update
开发计算机上所需的安全访问Security access needed on your development computer 空值N/A 本地管理/sudoLocal admin / sudo
可用性Usability
独立于 Kubernetes 和 Docker 项目Independent from Kubernetes and Docker artifacts No Yes
自动回滚更改,后期调试Automatic rollback of changes, post-debug No Yes
支持的客户端工具Supported Client Tooling
适用于 Visual Studio 2019Works with Visual Studio 2019 Yes Yes
适用于 Visual Studio CodeWorks with Visual Studio Code Yes Yes
使用 CLIWorks with a CLI Yes No
操作系统兼容性Operating System Compatibility
适用于 Windows 10Works on Windows 10 Yes Yes
适用于 LinuxWorks on Linux Yes Yes
适用于 macOSWorks on macOS Yes Yes
功能Capabilities
开发人员隔离或团队开发Developer Isolation or Team Development Yes Yes
有选择地覆盖环境变量Selectively overwrite environment variables No Yes
创建 Dockerfile 和 Helm 图表Creation of Dockerfile and Helm chart Yes No
将代码永久性部署到 KubernetesPersistent deployment of code to Kubernetes Yes No
Kubernetes pod 中的远程调试Remote debugging in a Kubernetes pod Yes No
本地调试,连接到 KubernetesLocal debugging, connected to Kubernetes No Yes
在同一工作站上同时调试多个服务Debugging multiple services at the same time, on the same workstation Yes Yes

Kubernetes 内部循环开发Kubernetes inner loop development

Azure Dev Spaces 和桥接到 Kubernetes 之间的最大差异在于代码的运行位置。The biggest difference between Azure Dev Spaces and Bridge to Kubernetes is where your code runs. Azure Dev Spaces 有助于开发和调试微服务代码,但需要在群集中运行该代码。Azure Dev Spaces helps develop and debug your microservice code, but requires that you run that code in your cluster. 桥接 Kubernetes 使你可以直接在开发计算机上开发和调试微服务代码,同时仍处于 Kubernetes 中运行的更大的应用程序的上下文中。Bridge to Kubernetes allows you to develop and debug your microservice code directly on your development computer while still in the context of the larger application running in Kubernetes. 桥接 Kubernetes 扩展 Kubernetes 群集的外围,并允许本地进程从 Kubernetes 继承配置。Bridge to Kubernetes extends the perimeter of the Kubernetes cluster and allows local processes to inherit configuration from Kubernetes.

内部循环开发

使用 Bridge 连接到 Kubernetes 时,会建立开发计算机与群集之间的网络连接。When using Bridge to Kubernetes, a network connection between your development computer and your cluster is established.在此连接的生存期内,会将代理添加到群集中,以替代将请求重定向到开发计算机的 Kubernetes 部署。 For the lifetime of this connection, a proxy is added to your cluster in place of your Kubernetes deployment that redirects requests to the service to your development computer. 断开连接后,应用程序部署将恢复为使用群集上运行的部署的原始版本。When you disconnect, the application deployment will revert to using the original version of the deployment running on the cluster. 这种方法与 Azure Dev Spaces 的工作方式不同,其中的代码与群集同步,然后运行。This approach differs from how Azure Dev Spaces works in which code is synchronized to the cluster, built, then run. Azure Dev Spaces 也不会回滚您的代码。Azure Dev Spaces also doesn’t roll back your code.

桥接 Kubernetes 可以灵活地使用在 Kubernetes 中运行的应用程序,而无需考虑它们的部署方法。Bridge to Kubernetes has the flexibility to work with applications running in Kubernetes regardless of their deployment method. 如果你使用 CI/CD 构建并运行应用程序,无论你使用的是已建立的工具还是自定义脚本,你仍可以使用 Bridge Kubernetes 来开发和调试代码。If you use CI/CD to build and run your application, regardless of whether you use established tools or custom scripts, you can still use Bridge to Kubernetes to develop and debug your code.

提示

利用 Microsoft Kubernetes extension ,你可以通过 Intellisense 快速开发 Kubernetes 清单并帮助基架 Helm 图表。The Microsoft Kubernetes extension lets you quickly develop Kubernetes manifests with Intellisense and helps scaffold Helm charts.

从 Azure Dev Spaces 过渡到 KubernetesTransition to Bridge to Kubernetes from Azure Dev Spaces

  1. 如果使用的是 Visual Studio,请将 Visual Studio IDE 更新到版本16.7 或更高版本,并从 Visual Studio Marketplace将桥安装到 Kubernetes 扩展。If you're using Visual Studio, update your Visual Studio IDE to version 16.7 or greater and install the Bridge to Kubernetes extension from the Visual Studio Marketplace. 如果使用 Visual Studio Code,请将 Bridge 安装 到 Kubernetes 扩展If you're using Visual Studio Code, install the Bridge to Kubernetes extension.

  2. 使用 Azure 门户或 AZURE DEV SPACES CLI禁用 Azure Dev Spaces 控制器。Disable the Azure Dev Spaces controller using the Azure portal or the Azure Dev Spaces CLI.

  3. 使用 Azure Cloud ShellUse Azure Cloud Shell. 或者,在安装了 bash 的 Mac、Linux 或 Windows 上,打开 bash shell 提示。Or on Mac, Linux or Windows with bash installed, open a bash shell prompt. 请确保命令行环境中提供以下工具: Azure CLI、docker、kubectl、卷曲、tar 和 gunzip。Make sure that the following tools are available in your command-line environment: Azure CLI, docker, kubectl, curl, tar, and gunzip.

  4. 创建容器注册表,或使用现有容器。Create a container registry, or use an existing one. 可以使用 Azure 容器注册表 或使用 Docker Hub在 azure 中创建容器注册表。You can create a container registry in Azure using Azure Container Registry or by using Docker Hub. 使用 Azure Cloud Shell 时,只有 Azure 容器注册表可用于承载 docker 映像。When using Azure Cloud Shell, only Azure Container Registry is available for hosting docker images.

  5. 运行迁移脚本,将 Azure Dev Spaces 资产转换为 Kubernetes 资产。Run the migration script to convert Azure Dev Spaces assets to Bridge to Kubernetes assets. 此脚本会构建一个与 Kubernetes 兼容的新映像,将其上传到指定的注册表,然后使用 Helm 更新包含该映像的群集。The script builds a new image compatible with Bridge to Kubernetes, uploads it to the designated registry, and then uses Helm to update the cluster with the image. 必须提供资源组、AKS 群集的名称和容器注册表。You must provide the resource group, the name of the AKS cluster, and a container registry. 还有其他命令行选项,如下所示:There are other command-line options as shown here:

    curl -sL https://aka.ms/migrate-tool | bash -s -- -g ResourceGroupName -n AKSName -h ContainerRegistryName -r PathOfTheProject -y
    

    该脚本支持以下标志:The script supports the following flags:

     -g Name of resource group of AKS Cluster [required]
     -n Name of AKS Cluster [required]
     -h Container registry name. Examples: ACR, Docker [required]
     -k Kubernetes namespace to deploy resources (uses 'default' otherwise)
     -r Path to root of the project that needs to be migrated (default = current working directory)
     -t Image name & tag in format 'name:tag' (default is 'projectName:stable')
     -i Enable a public endpoint to access your service over internet. (default is false)
     -c Docker build context path. (default = project root path passed to '-r' option)
     -y Doesn't prompt for non-tty terminals
     -d Helm Debug switch
    
  6. azds 中的任何自定义项(如环境变量设置)手动迁移到项目的 docker-compose.override.yml 文件中。Manually migrate any customizations, such as environment variable settings, in azds.yaml into your project's values.yml file.

  7. (可选) azds.yaml 从项目中删除该文件。(optional) Remove the azds.yaml file from your project.

  8. 在已部署的应用程序上将桥配置为 Kubernetes。Configure Bridge to Kubernetes on your deployed application. 若要详细了解如何在 Visual Studio 中使用 Bridge Kubernetes,请参阅 在 Visual studio 中使用 bridge 来 KubernetesFor more information on using Bridge to Kubernetes in Visual Studio, see Use Bridge to Kubernetes in Visual Studio. 有关 VS Code,请参阅 在 VS Code 中使用 Bridge KubernetesFor VS Code, see Use Bridge to Kubernetes in VS Code.

  9. 使用新创建的桥启动调试,以 Kubernetes 调试/启动配置文件。Start debugging using the newly created Bridge to Kubernetes debug/launch profile.

  10. 你可以根据需要再次运行该脚本以重新部署到群集。You can run the script again as needed to redeploy to your cluster.

共享群集中的团队开发Team development in a shared cluster

你还可以将特定于开发人员的路由用于 Kubernetes。You can also use developer-specific routing with Bridge to Kubernetes. Azure Dev Spaces 团队开发方案使用多个 Kubernetes 命名空间,使用父和子命名空间的概念将服务与应用程序的其余部分隔离开来。The Azure Dev Spaces team development scenario uses multiple Kubernetes namespaces to isolate a service from the rest of the application using the concept of parent and child namespaces. 桥接到 Kubernetes 提供了相同的功能,但具有改进的性能特征,并在相同的应用程序命名空间内。Bridge to Kubernetes offers the same capability, but with improved performance characteristics and within the same application namespace.

桥接到 Kubernetes 和 Azure Dev Spaces 要求在整个应用程序中存在并传播 HTTP 标头。Both Bridge to Kubernetes and Azure Dev Spaces require HTTP headers to be present and propagated throughout the application. 如果已将应用程序配置为处理 Azure Dev Spaces 的标头传播,则需要更新该标头。If you have already configured your application to handle header propagation for Azure Dev Spaces, then the header needs to be updated. 若要从 Azure Dev Spaces 过渡到 Kubernetes,请将 azds 中配置的标头更新为 " Kubernetes"。To transition to Bridge to Kubernetes from Azure Dev Spaces, update configured header from azds-route-as to kubernetes-route-as.

评估桥与 KubernetesEvaluate Bridge to Kubernetes

如果要在群集中禁用 Azure Dev Spaces 之前尝试使用 Bridge 进行 Kubernetes,最简单的方法是使用新群集。If you’d like to experiment with Bridge to Kubernetes before you disable Azure Dev Spaces in your cluster, the easiest way is to use a new cluster. 如果在同一群集上尝试同时使用 Azure Dev Spaces 并桥接到 Kubernetes,则在两者上使用路由功能时将遇到问题。If you try to use Azure Dev Spaces and Bridge to Kubernetes at the same time on the same cluster, you will run into issues when using the routing features on both.

使用 Visual Studio 将 Bridge 评估到 KubernetesUse Visual Studio to evaluate Bridge to Kubernetes

  1. 将 Visual Studio IDE 更新到版本16.7 或更高版本,并从 Visual Studio Marketplace将桥安装到 Kubernetes 扩展。Update your Visual Studio IDE to version 16.7 or greater and install the Bridge to Kubernetes extension from the Visual Studio Marketplace.
  2. 创建新的 AKS 群集并部署你的应用程序。Create a new AKS cluster and deploy your application. 你还可以使用 示例应用程序You can also use a sample application.
  3. 在已部署的应用程序上将桥配置为 Kubernetes。Configure Bridge to Kubernetes on your deployed application. 若要详细了解如何在 Visual Studio 中使用 Bridge Kubernetes,请参阅 将 bridge 与 Kubernetes 配合使用For more information on using Bridge to Kubernetes in Visual Studio, see Use Bridge to Kubernetes.
  4. 在 Visual Studio 中使用新创建的桥 Kubernetes 调试配置文件开始调试。Start debugging in Visual Studio using the newly created Bridge to Kubernetes debug profile.

使用 Visual Studio Code 将 Bridge 评估 KubernetesUse Visual Studio Code to evaluate Bridge to Kubernetes

  1. 桥安装到 Kubernetes 扩展Install the Bridge to Kubernetes extension.
  2. 创建新的 AKS 群集并部署你的应用程序。Create a new AKS cluster and deploy your application. 你还可以使用 示例应用程序You can also use a sample application.
  3. 在已部署的应用程序上将桥配置为 Kubernetes。Configure Bridge to Kubernetes on your deployed application. 有关在 Visual Studio Code 中使用 Bridge Kubernetes 的详细信息,请参阅 将 bridge 与 Kubernetes 配合使用For more information on using Bridge to Kubernetes in Visual Studio Code, see Use Bridge to Kubernetes.
  4. 在 Visual Studio 中使用新创建的桥 Kubernetes 启动配置文件开始调试。Start debugging in Visual Studio using the newly created Bridge to Kubernetes launch profile.

后续步骤Next steps

详细了解 Bridge 到 Kubernetes 的工作原理。Learn more about how Bridge to Kubernetes works.