.NET 微服務:容器化 .NET 應用程式的架構.NET Microservices: Architecture for Containerized .NET Applications

書籍封面

版本 3.1 -更新為 ASP.NET Core 3。1EDITION v3.1 - Updated to ASP.NET Core 3.1

本指南介紹如何開發微服務應用程式及使用容器進行管理,This guide is an introduction to developing microservices-based applications and managing them using containers. 並討論使用 .NET Core 和 Docker 容器的架構設計和實作方法。It discusses architectural design and implementation approaches using .NET Core and Docker containers.

為了讓您更輕鬆地開始使用,本指南將重點放在您可以探索的容器化和微服務應用程式。To make it easier to get started, the guide focuses on a reference containerized and microservice-based application that you can explore. 此參考應用程式位於 eShopOnContainers GitHub 存放庫中。The reference application is available at the eShopOnContainers GitHub repo.

簡介Introduction

企業透過容器,逐漸實現成本節約、解決部署問題,以及改善 DevOps 和生產環境作業。Enterprises are increasingly realizing cost savings, solving deployment problems, and improving DevOps and production operations by using containers. Microsoft 藉由建立 Azure Kubernetes Service 和 Azure Service Fabric 等產品,以及藉由與 Docker、Mesosphere 和 Kubernetes 等業界領導者合作,不斷為 Windows 和 Linux 創新容器。Microsoft has been releasing container innovations for Windows and Linux by creating products like Azure Kubernetes Service and Azure Service Fabric, and by partnering with industry leaders like Docker, Mesosphere, and Kubernetes. 這些產品提供容器解決方案,可協助公司以雲端速度和規模建置及部署應用程式,而不論其選擇的平台或工具為何。These products deliver container solutions that help companies build and deploy applications at cloud speed and scale, whatever their choice of platform or tools.

Docker 成為容器產業的既定標準,並受到 Windows 和 Linux 生態系統中最重要廠商的支援Docker is becoming the de facto standard in the container industry, supported by the most significant vendors in the Windows and Linux ecosystems. (Microsoft 是支援 Docker 的主要雲端廠商之一)。在未來,Docker 可能會在雲端或內部部署的任何資料中心內普及。(Microsoft is one of the main cloud vendors supporting Docker.) In the future, Docker will probably be ubiquitous in any datacenter in the cloud or on-premises.

此外,微服務架構已躍升為分散式關鍵任務應用程式的重要方法。In addition, the microservices architecture is emerging as an important approach for distributed mission-critical applications. 在微服務架構中,應用程式會建置在一組可獨立開發、測試、部署及設定版本的服務之上。In a microservice-based architecture, the application is built on a collection of services that can be developed, tested, deployed, and versioned independently.

關於本指南About this guide

本指南介紹如何開發微服務應用程式及使用容器進行管理,This guide is an introduction to developing microservices-based applications and managing them using containers. 並討論使用 .NET Core 和 Docker 容器的架構設計和實作方法。It discusses architectural design and implementation approaches using .NET Core and Docker containers. 為了讓您更輕鬆地開始使用容器和微服務,本指南將重點放在您可以探索的容器化和微服務應用程式。To make it easier to get started with containers and microservices, the guide focuses on a reference containerized and microservice-based application that you can explore. 此範例應用程式位於 eShopOnContainers GitHub 存放庫中。The sample application is available at the eShopOnContainers GitHub repo.

本指南提供主要在開發環境層級的基本開發和架構指引,並著重於兩項技術:Docker 和 .NET Core。This guide provides foundational development and architectural guidance primarily at a development environment level with a focus on two technologies: Docker and .NET Core. 我們的用意是讓您在思考應用程式設計,但不想要將重點放在生產環境的基礎結構 (雲端或內部部署) 時,可以閱讀本指南。Our intention is that you read this guide when thinking about your application design without focusing on the infrastructure (cloud or on-premises) of your production environment. 稍後,當您建立可實際執行的應用程式時,您將會制定基礎結構的相關決策。You will make decisions about your infrastructure later, when you create your production-ready applications. 因此,本指南與基礎結構無關,而是偏重開發環境。Therefore, this guide is intended to be infrastructure agnostic and more development-environment-centric.

研讀本指南之後,您的下一個步驟是了解 Microsoft Azure 上可實際執行的微服務。After you have studied this guide, your next step would be to learn about production-ready microservices on Microsoft Azure.

版本Version

本指南已經過修訂,以涵蓋 .Net core 3.1版本,以及與 .net core 3.1 版 coinciding 的相同「wave」技術(也就是 Azure 和其他協力廠商技術)相關的許多其他更新。This guide has been revised to cover .NET Core 3.1 version along with many additional updates related to the same “wave” of technologies (that is, Azure and additional third-party technologies) coinciding in time with the .NET Core 3.1 release. 這就是為什麼書籍版本也已更新至3.1版的原因。That’s why the book version has also been updated to version 3.1.

本指南未涵蓋的內容What this guide does not cover

本指南的重點不在應用程式生命週期、DevOps、CI/CD 管線或小組合作。This guide does not focus on the application lifecycle, DevOps, CI/CD pipelines, or team work. 補充性指南 Containerized Docker Application Lifecycle with Microsoft Platform and Tools (Microsoft 平台和工具的容器化 Docker 應用程式生命週期) 會以該主題為重點。The complementary guide Containerized Docker Application Lifecycle with Microsoft Platform and Tools focuses on that subject. 目前的指南也不提供 Azure 基礎結構的實作詳細資料,例如特定 Orchestrator 的相關資訊。The current guide also does not provide implementation details on Azure infrastructure, such as information on specific orchestrators.

其他資源Additional resources

  • Microsoft 平台和工具的容器化 Docker 應用程式生命週期 (可下載的電子書)Containerized Docker Application Lifecycle with Microsoft Platform and Tools (downloadable e-book)
    https://aka.ms/dockerlifecycleebook

誰應該使用本指南Who should use this guide

本指南的撰寫對象是剛接觸 Docker 應用程式開發和微服務架構的開發人員和解決方案架構師。We wrote this guide for developers and solution architects who are new to Docker-based application development and to microservices-based architecture. 如果您想要了解如何使用 Microsoft 開發技術 (特別是 .NET Core) 和 Docker 容器,來架構、設計及實作概念證明應用程式,則本指南很適合您。This guide is for you if you want to learn how to architect, design, and implement proof-of-concept applications with Microsoft development technologies (with special focus on .NET Core) and with Docker containers.

如果您是技術決策者 (例如企業架構師),想概括了解架構和技術,再決定要選取哪個方法以用於新的現代化分散式應用程式,您也會發現本指南很實用。You will also find this guide useful if you are a technical decision maker, such as an enterprise architect, who wants an architecture and technology overview before you decide on what approach to select for new and modern distributed applications.

本指南的使用方式How to use this guide

本指南的第一部分介紹 Docker 容器、討論如何在 .NET Core 和 .NET Framework 之間選擇開發架構,並提供微服務概觀。The first part of this guide introduces Docker containers, discusses how to choose between .NET Core and the .NET Framework as a development framework, and provides an overview of microservices. 此內容適用於需要概觀但重點不在程式碼實作詳細資料的架構師和技術決策者。This content is for architects and technical decision makers who want an overview but don't need to focus on code implementation details.

本指南的第二部分以 Docker 應用程式的開發程序一節開頭,The second part of the guide starts with the Development process for Docker based applications section. 並將重點放在使用 .NET Core 和 Docker 實作應用程式的開發和微服務模式。It focuses on development and microservice patterns for implementing applications using .NET Core and Docker. 本節對於想要專注於程式碼、模式和實作詳細資料的開發人員和架構師最為重要。This section will be of most interest to developers and architects who want to focus on code and on patterns and implementation details.

eShopOnContainers 應用程式是 .NET Core 和微服務的開放原始碼參考應用程式,專為使用 Docker 容器進行部署所設計。The eShopOnContainers application is an open-source reference app for .NET Core and microservices that is designed to be deployed using Docker containers. 此應用程式是由多個子系統所組成,包括數個電子商店 UI 前端 (Web MVC 應用程式、Web SPA 和原生行動應用程式)。The application consists of multiple subsystems, including several e-store UI front ends (a Web MVC app, a Web SPA, and a native mobile app). 它也包含用來執行所有必要伺服器端作業的後端微服務和容器。It also includes the back-end microservices and containers for all required server-side operations.

應用程式的目的是要展示架構模式。The purpose of the application is to showcase architectural patterns. 這不是用於生產環境的範本,無法用來啟動真實世界應用程式。IT IS NOT A PRODUCTION-READY TEMPLATE to start real-world applications. 事實上,應用程式永久處於 beta 版狀態,因為在出現可能有興趣的新技術時,也會使用它來進行測試。In fact, the application is in a permanent beta state, as it’s also used to test new potentially interesting technologies as they show up.

將您的意見反應傳送給我們!Send us your feedback!

本指南的撰寫目的是為了協助您了解 .NET 中的容器化應用程式和微服務架構。We wrote this guide to help you understand the architecture of containerized applications and microservices in .NET. 本指南和相關參考應用程式會不斷改進,因此歡迎您提供寶貴的意見反應!The guide and related reference application will be evolving, so we welcome your feedback! 如果您有關于如何改進本指南的意見,請在 https://aka.ms/ebookfeedback提交意見反應。If you have comments about how this guide can be improved, submit feedback at https://aka.ms/ebookfeedback.

學分Credits

共同作者:Co-Authors:

Cesar de la Torre,Sr. Microsoft Corp. .NET 產品小組 PMCesar de la Torre, Sr. PM, .NET product team, Microsoft Corp.

Bill Wagner,Sr. Microsoft Corp. C+E 內容開發人員Bill Wagner, Sr. Content Developer, C+E, Microsoft Corp.

Mike Rousos,Microsoft DevDiv CAT 小組首席軟體工程師Mike Rousos, Principal Software Engineer, DevDiv CAT team, Microsoft

編輯者:Editors:

Mike PopeMike Pope

Steve HoagSteve Hoag

參與者和檢閱者:Participants and reviewers:

Jeffrey Ritcher,Microsoft Azure 小組合作夥伴軟體工程師Jeffrey Richter, Partner Software Eng, Azure team, Microsoft

Jimmy Bogard,Headspring 首席架構師Jimmy Bogard, Chief Architect at Headspring

Udi Dahan,Particular Software 創辦人暨執行長Udi Dahan, Founder & CEO, Particular Software

Jimmy Nilsson,Factor10 共同創辦人暨執行長Jimmy Nilsson, Co-founder and CEO of Factor10

Glenn Condron,Sr. ASP.NET 小組計畫經理Glenn Condron, Sr. Program Manager, ASP.NET team

Mark Fussell,Microsoft Azure Service Fabric 小組 PM 主管Mark Fussell, Principal PM Lead, Azure Service Fabric team, Microsoft

Diego Vega,Microsoft Entity Framework 小組 PM 主管Diego Vega, PM Lead, Entity Framework team, Microsoft

Barry Dorrans,Sr. 安全性計畫經理Barry Dorrans, Sr. Security Program Manager

Rowan Miller,Sr. Microsoft 計畫經理Rowan Miller, Sr. Program Manager, Microsoft

Ankit Asthana,Microsoft .NET 小組 PM 總經理Ankit Asthana, Principal PM Manager, .NET team, Microsoft

Scott Hunter,Microsoft .NET 小組合夥人暨 PM 主管Scott Hunter, Partner Director PM, .NET team, Microsoft

Nish Anil,Microsoft NET 小組資深方案經理Nish Anil, Sr. Program Manager, .NET team, Microsoft

Dylan Reisenberger,Polly 架構師暨開發部門主管Dylan Reisenberger, Architect and Dev Lead at Polly

Steve "ardalis" Smith - 軟體架構設計人員和講師 - Ardalis.comSteve "ardalis" Smith - Software Architect and Trainer - Ardalis.com

Ian Cooper,Brighter 程式碼架構師Ian Cooper, Coding Architect at Brighter

Unai Zorrilla,Plain Concepts 架構師暨開發部門主管Unai Zorrilla, Architect and Dev Lead at Plain Concepts

Eduard Tomas,Plain Concepts 開發部門主管Eduard Tomas, Dev Lead at Plain Concepts

Ramon Tomas,Plain Concepts 開發人員Ramon Tomas, Developer at Plain Concepts

David Sanz,Plain Concepts 開發人員David Sanz, Developer at Plain Concepts

Javier Valero,Grupo Solutio 營運長Javier Valero, Chief Operating Officer at Grupo Solutio

Pierre Millet,Sr. Microsoft 顧問Pierre Millet, Sr. Consultant, Microsoft

Michael Friis,Docker Inc. 產品經理Michael Friis, Product Manager, Docker Inc

Charles Lowell,Microsoft VS CAT 小組軟體工程師Charles Lowell, Software Engineer, VS CAT team, Microsoft

以一般概念Miguel veloso turing challenge軟體發展工程師Miguel Veloso, Software Development Engineer at Plain Concepts

發行者PUBLISHED BY

Microsoft 開發人員部門 .NET 和 Visual Studio 產品小組Microsoft Developer Division, .NET and Visual Studio product teams

Microsoft Corporation 部門A division of Microsoft Corporation

One Microsoft WayOne Microsoft Way

Redmond, Washington 98052-6399Redmond, Washington 98052-6399

Microsoft Corporation 的著作權©2020Copyright © 2020 by Microsoft Corporation

著作權所有,並保留一切權利。All rights reserved. 本書內容的任何部分在未經過發行者書面許可下,不得以任何形式或透過任何方式進行重製或傳送。No part of the contents of this book may be reproduced or transmitted in any form or by any means without the written permission of the publisher.

本書是以「現況」提供,代表作者的觀點和意見。This book is provided “as-is” and expresses the author’s views and opinions. 本書中所述之觀點、意見與資訊 (包括 URL 及其他網際網路網站參考) 可能會隨時變更,恕不另行通知。The views, opinions and information expressed in this book, including URL and other Internet website references, may change without notice.

此處描述的一些範例僅供說明之用,純屬虛構。Some examples depicted herein are provided for illustration only and are fictitious. 並未影射或關聯任何真實的人、事、物。No real association or connection is intended or should be inferred.

Microsoft 與列於 https://www.microsoft.com 「商標」網頁的商標是 Microsoft 集團的商標。Microsoft and the trademarks listed at https://www.microsoft.com on the “Trademarks” webpage are trademarks of the Microsoft group of companies.

Mac 與 macOS 是 Apple Inc. 的商標。Mac and macOS are trademarks of Apple Inc.

Docker whale 標誌是 Docker,Inc. 的注冊商標,由許可權使用。The Docker whale logo is a registered trademark of Docker, Inc. Used by permission.

所有其他商標和標誌屬於其各自擁有者的財產。All other marks and logos are property of their respective owners.