architecture for containerized .net applications and...
TRANSCRIPT
Architecture for Containerized.NET Applications and AZURE
■ Cloud Computing with Azure
■ Docker and Containerization
■ Building an ASP.NET Core Application with Docker
■ Deploying a Docker Container to Azure
2 von 109School of Engineering © K. Rege, ZHAW
Cloud Computingwith Azure
3 von 109School of Engineering © K. Rege, ZHAW 3
Azure: the color of the sky ona clear summer's day
wikipedia
Azure: the color of the sky ona clear summer's day
© wikipedia
Azure?
4 von 109School of Engineering © K. Rege, ZHAW
What is Cloud Computing?
5 von 109School of Engineering © K. Rege, ZHAW
What is Cloud Computing?
“The practice of using a network of remote servers hosted on the Internet tostore, manage, and process data, rather than a local server or a personalcomputer.”
Oxford Dictionary
“The practice of using a network of remote servers hosted on the Internet tostore, manage, and process data, rather than a local server or a personalcomputer.”
Oxford Dictionary
“The practice of storing regularly used computer data on multiple servers that
can be accessed through the Internet.”
Webster Dictionary
“The practice of storing regularly used computer data on multiple servers that
can be accessed through the Internet.”
Webster Dictionary
Cloud computing is a model for enabling ubiquitous,convenient, on-demand network access to a shared pool ofconfigurable computing resources (e.g., networks, servers,
storage, applications, and services) that can be rapidlyprovisioned and released with minimal management effort
or service provider interaction. This cloud model iscomposed of five essential characteristics, three service
models, and four deployment models.
National Institute of Standards and Technology
© Microsoft
6 von 109School of Engineering © K. Rege, ZHAW
Cloud Computing Perspectives
Perspectives highly influenced by roles andresponsibilities within an organization
Further perspectives include:■ “An approach to computing that’s about Internet scale and connecting to a
variety of devices and endpoints.”■ “Treating hardware and software resources as a utility.”
■ “A way to save a ton of money by only paying for what you need.”
■ “A way to scale huge when you need something done fast.”
■ End-User■ Application Developer■ IT Infrastructure Manager■ CIO■ CFO■ Service Provider
© Microsoft
7 von 109School of Engineering © K. Rege, ZHAW
Evolution of Cloud Computing
Stage Characteristics
Grid Computing Solving large problems with parallel computingMade mainstream by Global Alliance
Utility Computing Computing resources offered as a metered serviceLate 1990s
Software as a Service Subscription-based software accessed over the InternetGained momentum after 2001
Cloud Computing Next-generation datacenters with virtualization technologyFull stack of service - IasS, PaaS, & SaaS
Ord
er o
f Evo
lutio
n &
Tim
e
© Microsoft
8 von 109School of Engineering © K. Rege, ZHAW
Key Enabling Technologies
Ubiquitous fast wide-area networksPowerful and inexpensive serversHigh-performance virtualization technology
WidespreadBroadband
HadoopLinux Web
HostingMicrosoft SQL
ServerWindows
Windows Server
we called it languageenvironment on ourIBM mainframes - kid!
we called it languageenvironment on ourIBM mainframes - kid!
© Microsoft
9 von 109School of Engineering © K. Rege, ZHAW
Five Key Cloud Characteristics
On-demand self-serviceUbiquitous network accessLocation-independent resource poolingRapid adjustment to loadPay for what you use
© Microsoft
10 von 109School of Engineering © K. Rege, ZHAW
Cloud Service Models
© Microsoft
11 von 109School of Engineering © K. Rege, ZHAW
Cloud Computing Service Models
Model Description
Software as a Service (SaaS) Consume itEnd-User Applications delivered as a service, ratherthan by on-premises software
Platform as a Service (PaaS) Build on itApplication platform or middleware provided as aservice on which developers can build and deploycustom applications
Infrastructure as a Service (IaaS) Migrate to itComputing, storage, or other IT infrastructureprovided as a service, rather than as a dedicatedcapability
© Microsoft
12 von 109School of Engineering © K. Rege, ZHAW
Service Model Division of Responsibility
Networking
Storage
Servers
Virtualization
Operating System
Middleware
Runtime
Data
Applications
Software(as a Service)
Managed by P
rovider
Networking
Storage
Servers
Virtualization
Operating System
Middleware
Runtime
Data
Applications
Platform(as a Service)
User M
anagedM
anaged by Provider
Networking
Storage
Servers
Virtualization
Operating System
Middleware
Runtime
Data
Applications
Infrastructure(as a Service)
Managed by P
roviderU
ser Managed
Networking
Storage
Servers
Virtualization
Operating System
Middleware
Runtime
Data
Applications
On-Premises
User M
anaged
Networking
Storage
Servers
Virtualization
Operating System
Middleware
Runtime
Data
Applications
Software(as a Service)
Managed by P
rovider
Networking
Storage
Servers
Virtualization
Operating System
Middleware
Runtime
Data
Applications
Platform(as a Service)
User M
anagedM
anaged by Provider
Networking
Storage
Servers
Virtualization
Operating System
Middleware
Runtime
Data
Applications
Infrastructure(as a Service)
Managed by P
roviderU
ser Managed
Networking
Storage
Servers
Virtualization
Operating System
Middleware
Runtime
Data
Applications
On-Premises
User M
anaged
13 von 109School of Engineering © K. Rege, ZHAW
Software as a Service (SaaS)
Internet hosted software
Full vendor maintenance
No upfront cost
Pay for services as they are consumed
Networking
Storage
Servers
Virtualization
OperatingSystem
Middleware
Runtime
Data
Applications
Managed by P
rovider
© Microsoft
14 von 109School of Engineering © K. Rege, ZHAW
Platform as a Service (PaaS)
Delivers and manages variousdevelopment environments
Environment and tools can be easilyprovisioned and torn down
Networking
Storage
Servers
Virtualization
OperatingSystem
Middleware
Runtime
Data
Applications
User M
anagedM
anaged by Provider
© Microsoft
15 von 109School of Engineering © K. Rege, ZHAW
Infrastructure as a Service (IaaS)
Dedicated virtual machines (VMs)
Users configure server type, operating
system, storage, network, etc.
Scale up and down
Networking
Storage
Servers
Virtualization
OperatingSystem
Middleware
Runtime
Data
Applications
Managed by P
roviderU
ser Managed
© Microsoft
16 von 109School of Engineering © K. Rege, ZHAW
Cloud Deployment Models
© Microsoft
17 von 109School of Engineering © K. Rege, ZHAW
Cloud Deployment Model
Hybrid Cloud
Private Cloud
Community Cloud
Public Cloud
Bridge
© Microsoft
18 von 109School of Engineering © K. Rege, ZHAW
Cloud Deployment Models – Advantages &Characteristics
Model Advantages and Characteristics
Public Shifts capital expense to operating expenseOffers pay-as-you-go pricingSupports multiple tenants
Private Leverages existing capital expenseCan help reduce operating costsIntended for a single tenant
Hybrid Bridges one or more community, private, or publiccloudsAllows manipulation of CapEx and OpEx to optimizecostSupports resource portability
Community Allows sharing of CapEx and OpEx to reduce costsBrings together groups with a common interestSupports resource portability
© Microsoft
19 von 109School of Engineering © K. Rege, ZHAW
Why Cloud Computing?
© Microsoft
20 von 109School of Engineering © K. Rege, ZHAW
Why Cloud Computing?
Why CloudComputing?
Lower TCO
Free UpInternal
Resources
Pas AsYou Go24x7
Support
Device- &Location-
Independent
Easy & AgileDeployment
Reliability,Scalability
LowerCapital
Expenditure
Utility Based HighlyAutomated
Adjust toDemand
© Microsoft
key criterion: btw.same as for "rent acar vs. buy a car"
key criterion: btw.same as for "rent acar vs. buy a car"
depends onusage scenario
depends onusage scenario
fewer engineersbut more lawyers
fewer engineersbut more lawyers
Pas AsYou Go24x7
Support
Device- &Location-
Independent
Easy & AgileDeployment
Reliability,Scalability
LowerCapital
Expenditure
Utility Based HighlyAutomated
Pay AsYou Go24x7
Support
Device- &Location-
Independent
Easy & AgileDeployment
Reliability,Scalability
LowerCapital
Expenditure
Utility Based HighlyAutomated
21 von 109School of Engineering © K. Rege, ZHAW
Time
Com
pute
InactivityPeriod
On and Off
Variable Demand for Computing Power
■ On & off workloads■ Batch jobs:
■ only for very BIG companies■ and COBOL and PL1 don't run on AZURE
■ Wasted Capacity
■ Time to market can be cumbersome
© Microsoft
22 von 109School of Engineering © K. Rege, ZHAW
Time
Com
pute
RapidGrowth
… Variable Demand for Computing Power
■ Rapidly growing company
■ Dream of any startup - but rarely
happens
■ Major challenge for IT dept. to keep up
with growth
■ Potential loss of business opportunity
■ Potential customer service problems
© Microsoft
23 von 109School of Engineering © K. Rege, ZHAW
Time
Com
pute
UnpredictableBursting
… Variable Demand for Computing Power
■ Unexpected peak in demand
■ Mentioned on popular Web Site,■ "slashdot effect"
■ Loss of business opportunity
■ Wasted capacity if demand wanes
© Microsoft
24 von 109School of Engineering © K. Rege, ZHAW
… Variable Demand for Computing Power
■ Seasonal peaks and troughs
■ Football club fan website
■ Provisioning dilemma■ Wasted capacity or■ Loss of business
Time
Com
pute
PredictableBurstingDecline
Time
Com
pute
PredictableBursting
© Microsoft
25 von 109School of Engineering © K. Rege, ZHAW
Servers
Laptops
ApplicationPlatform
Infrastructure
Desktop
Phones
Tablets
Cloud Computing
Cloud Computing Nutshell
■ End-users connect over the Internet to
the cloud from their own personal
computers or portable devices in orderto access services.
■ To the end-user, the underlying
infrastructure such as the hardware,
operating system, etc., is invisible
© Microsoft
Much like a mainframewith terminals - myyoungster!
Much like a mainframewith terminals - myyoungster!
26 von 109School of Engineering © K. Rege, ZHAW
Cloud Vendors
© Microsoft
27 von 109School of Engineering © K. Rege, ZHAW
Amazon AWS Datacenter Regions
© Microsoft
28 von 109School of Engineering © K. Rege, ZHAW
The Azure Platform
■ There are 54 active Azure regions (rapidly growing)
© Microsoft
29 von 109School of Engineering © K. Rege, ZHAW
Cloud Vendor - Azure & AWS
Category Azure Service AWS Service
Computing infrastructure Virtual Machines EC2
Object storage infrastructure Blob Storage S3
Networking Virtual Network Virtual Private Cloud
Relational database-as-a-service
SQL Database RDS
NoSQL document database DocumentDB DynamoDB
Big data processing HDInsight Elastic MapReduce (EMR)
Visualization Power BI QuickSight© Microsoft
30 von 109School of Engineering © K. Rege, ZHAW
Cloud Vendor - Bluemix & Google
Category Bluemix Google Service
Computing infrastructure Virtual Server, Containers Compute Engine
Object storage infrastructure Object, Block Storage Cloud Storage
Networking Virtual Private Network Cloud Virtual Network
Relational database-as-a-service
SQL Database Cloud SQL
NoSQL document database MongoDB Cloud Datastore, Bigtable
Big data processing Analytics for Apache Hadoop BigQuery, Cloud Dataproc
Visualization
© Microsoft
31 von 109School of Engineering © K. Rege, ZHAW
Azure Services
© Microsoft
32 von 109School of Engineering © K. Rege, ZHAW
Azure Usage
■ Azure Active Directory Users■ More than 500 Million
■ Storage transactions per day■ More than 777 Trillion
■ Messages processed by Azure IoT permonth
■ More than 1.5 Trillion
■ Active Websites■ More than 250,000
■ Percentage of Fortune 500 Companies
using Azure■ More than 80%
■ Authentications per week■ More than 13 Billion
■ SQL Databases in Azure■ More than 1.5 Million
■ Developers registered with Visual Studio
Online■ More than 1 million
33 von 109School of Engineering © K. Rege, ZHAW
Risks: Vendor Lock-In
Companies that adopt cloud computing must bewary of potential vendor lock-in issues
■ Company’s entire data is stored with a single vendor’s cloud storage
■ Company relies on a single vendor for all of its computations
■ Changing vendors can be very costly
© Microsoft
34 von 109School of Engineering © K. Rege, ZHAW
Risks: Everything as a Service
■ Platform as a Service -> PaaS
■ Infrastructure as a Service -> IaaS
■ Software as a Service -> SaaS
■ Antivirus as a Service -> AaaS
■ However, also some critical voices
Cloud computing is a trap.It's stupidity. It's worsethan stupidity: it's amarketing hype campaign
Cloud computing is a trap.It's stupidity. It's worsethan stupidity: it's amarketing hype campaign
Richard StallmanFounder GNU Projects
Steve WozniakFounder Apple
I think there are going tobe a lot of horribleproblems in the next fiveyears.
I think there are going tobe a lot of horribleproblems in the next fiveyears.
Larry EllisonFounder Oracle
the computer industry is morefashion-driven than women'sfashion
the computer industry is morefashion-driven than women'sfashion
a new business model,new opportunities anda new source ofimmense revenue
a new business model,new opportunities anda new source ofimmense revenue
Virus TotalVirus Total
36 von 109School of Engineering © K. Rege, ZHAW
Summary Cloud Computing
■ Cloud Computing■ Ubiquitous via network access■ Location-independent shared pool of computing resources■ On-demand rapid provisioning and tear down■ Pay only for current client requirements
■ Service Models■ IaaS, PaaS, SaaS, AaaS, XaaS
■ Deployment Models■ Public, Private, Community, and Hybrid
37 von 109School of Engineering © K. Rege, ZHAW
ContainersDocker
38 von 109School of Engineering © K. Rege, ZHAW
Containers
■ Containerization is an approach to software development in which an application
or service, its dependencies, and its configuration (abstracted as deploymentmanifest files) are packaged together as a container image.
■ Containers isolate applications from each other on a shared OS.
■ Containerized applications run on top of a container host that in turn runs on the
OS (Linux or Windows).
■ From an application point of view, instantiating an image (creating a container) is
similar to instantiating a process
39 von 109School of Engineering © K. Rege, ZHAW
A Shipping Container System for Code
© Darren Chen (Docker)
40 von 109School of Engineering © K. Rege, ZHAW
Docker Eliminates Matrix from Hell
© Darren Chen (Docker)
41 von 109School of Engineering © K. Rege, ZHAW
Build, Ship, Run
Build Ship
Run
PersistencymanagementPersistencymanagement
SecurityserviceSecurityservice
TransactioncontrolTransactioncontrol
StatemanagementStatemanagement
DirectoryserviceDirectoryservice
Livecycle ManagementLivecycle Management
Monitoring & ConfigurationMonitoring & Configuration
42 von 109School of Engineering © K. Rege, ZHAW
Run: Docker vs VM vs App Container
■ Virtual Machine
■ vs. Lightweight Container (Docker)
■ vs. Application Container (e.g. EJB)
ServerServer ServerServer ServerServer
Host OSHost OS Host OSHost OS Host OSHost OS
HypervisorHypervisor Docker EngineDocker Engine EJB/SFEJB/SF
Guest OSGuest OS
Bins/LibsBins/Libs
App AApp A
Guest OSGuest OS
Bins/LibsBins/Libs
App BApp B
Bins/LibsBins/Libs
App AApp A
Bins/LibsBins/Libs
App BApp B
VM1 VM2
App AApp A Services Services
Container 1 Container 2
EJBs
Managed Entity
PersistencymanagementPersistencymanagement
SecurityserviceSecurityservice
TransactioncontrolTransactioncontrol
StatemanagementStatemanagement
DirectoryserviceDirectoryservice
Livecycle ManagementLivecycle ManagementMonitoring & Configuration
Monitoring & Configuration
Virtual Machine Docker EJB/Service Fabric
43 von 109School of Engineering © K. Rege, ZHAW
ServerServer
Host OSHost OS
Bins/LibBins/Lib
App AApp A App BApp B
Container 1 Process
Run: Docker vs Processes
■ Process (real Processes have dependencies to file system)
■ vs. Lightweight Container
■ vs. Real Application (real Application have dependencies)
ServerServer
Host OSHost OS
Docker EngineDocker Engine
Bins/LibsBins/Libs
App AApp A
Bins/LibsBins/Libs
App BApp B
Container 1 Docker
/etc
/lib
ServerServer
Host OSHost OS
Docker EngineDocker Engine
Bins/LibsBins/Libs
App AApp A
Bins/LibsBins/Libs
App BApp B
Container 1 Docker
/etc
/lib
security
Data Bases
Transactions. . .
Docker ModelProcess Docker Reality
44 von 109School of Engineering © K. Rege, ZHAW
.NET Core with Docker
45 von 109School of Engineering © K. Rege, ZHAW
.NET Core with Docker (Linux or Windows)
■ The modularity and lightweight nature of .NET Core makes it perfect for
containers.
■ You have cross-platform needs.■ For example, you want to use both Linux and Windows Containers.
■ Your application architecture is based on microservices.
■ You need to start containers fast and want a small footprint per container■ achieve better density or more containers per hardware unit in order to lower your costs.
■ Need to run different .NET versions for applications within the same machine.
■ Don't use .NET Core if■ Your application currently uses .NET Framework and has strong dependencies on Windows.■ You need to use Windows APIs that are not supported by .NET Core.■ You need to use third-party .NET libraries that are not available for .NET Core 2.2
■ ASP.NET Web Forms, Win Forms*, WPF* (* in Core 3.0)■ WCF Server, Workflow Foundation, some Azure services
46 von 109School of Engineering © K. Rege, ZHAW
What OS to target with .NET containers
■ Docker Containers run on .NET Core , Server Core, Nano Server, Linux
small footprint, noGUI, only 64 bit -20 times smallerthan Server Core
small footprint, noGUI, only 64 bit -20 times smallerthan Server Core
Docker Image ofWindows Server:4.5 GByte
Docker Image ofWindows Server:4.5 GByte
47 von 109School of Engineering © K. Rege, ZHAW
Install Docker for Windows
■ Create Account (if not yet done)
■ Get Started: Needs group■ compmgmt.msc (as administrator) and add docker-users group to own account
https://docs.docker.com/docker-for-windows/?install_site=vsonwin
https://docs.docker.com/docker-for-windows/install/
48 von 109School of Engineering © K. Rege, ZHAW
Install Visual Studio Tools for Docker
■ Install Docker Support for VS 19
https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/docker/visual-studio-tools-for-docker?view=aspnetcore-3.1
https://docs.docker.com/docker-for-windows/
49 von 109School of Engineering © K. Rege, ZHAW
Check (and fix) Docker container
■ Right click on Docker -> Setting■ See if Docker is running■ Kubernetes may be enabled here too
sometimes for LinuxContainer the Windowsshare is lost: simplyreconnect
sometimes for LinuxContainer the Windowsshare is lost: simplyreconnect
switch between windows andLinux Docker
switch between windows andLinux Docker
50 von 109School of Engineering © K. Rege, ZHAW
Development for Docker
■ Development Process for Container Based Applications
51 von 109School of Engineering © K. Rege, ZHAW
Step 1. Start Coding
■ Create your initial application or Service
■ Developing a Docker application is similar to the way you develop an application
without Docker
■ The difference is that while developing for Docker, you’re deploying and testing
your application or services running within Docker containers in your localenvironment.
■ But roundtrip is slower and needs a lot of memory (=> 16 GByte, Xeon, W10 Data Center Server)■ Buy a very big machine !!!!
■ Probably Alternative: develop native application on your Platform and
containerize later
52 von 109School of Engineering © K. Rege, ZHAW
Step 2. Create a Dockerfile
■ You need a Dockerfile for each custom image you want to build■ deploy automatically from Visual Studio■ manually using the Docker CLI
■ If your application contains multiple services (as in a microservices architecture),you need one Dockerfile for each service
Add Docker Support to Existing ProjectSolution Explorer and selecting Add > Docker Support,
https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/docker/visual-studio-tools-for-docker?view=aspnetcore-3.1
a Dockerfile isgenerated
a Dockerfile isgenerated
53 von 109School of Engineering © K. Rege, ZHAW
… Create a Dockerfile (via Microsoft VS)
■ Using an existing official .NET Docker image
■ For instance, if you want to use ASP.NET Core (Linux or Windows)
■ Linux Container
■ Windows Container
■ For Web Apps, you also need Docker to listen on the TCP port you will use atruntime (in this case, port 80, as configured with the EXPOSE setting).
https://docs.microsoft.com/dotnet/core/docker/building-net-docker-images
FROM microsoft/dotnet:2.2-aspnetcore-runtimeARG sourceWORKDIR /appEXPOSE 80COPY ${source:-obj/Docker/publish} .ENTRYPOINT ["dotnet", " MySingleContainerWebApp.dll "]
has to match yourHost OS Version
has to match yourHost OS Version
FROM mcr.microsoft.com/dotnet/core/runtime:3.1-buster-slim AS baseWORKDIR /app
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-nanoserver-1809 AS baseWORKDIR /app...
54 von 109School of Engineering © K. Rege, ZHAW
… Create a Dockerfile (via Microsoft VS)
■ Container Server is pulled automatically from the Repo
■ However: build 1809 of nanoserver has a bug■ Build 1809 of nanoserver the USERNAME was switched from ContainerAdministrator to
ContainerUser which has no permissions to write to the root of C:
■ Add the following lines
https://stackoverflow.com/questions/58757587/how-to-fix-docker-command-failed-with-exit-code-125-when-using-visual-studio
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-nanoserver-1809 AS baseWORKDIR /app...
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-nanoserver-1809 AS baseUSER ContainerAdministratorRUN net localgroup administrators /add "User Manager\ContainerUser"USER ContainerUserWORKDIR /app
Docker command failed with exitcode 125.
Docker command failed with exitcode 125.
. . .
55 von 109School of Engineering © K. Rege, ZHAW
Create a Dockerfile (via Docker CMD)
■ Dockerize an ASP.NET Core application■ create a Dockerfile
■ Build and run the Docker image■ navigate to your project folder, and enter
https://docs.docker.com/engine/examples/dotnetcore/
has to match yourApp name
has to match yourApp name
56 von 109School of Engineering © K. Rege, ZHAW
… Create a Dockerfile (via Docker CMD)
■ Bug Docker File position for CMD and VS■ Dockerfile generated by VS is in a Subdirectory
■ When calling the docker CLI build command the .sln file has to be in the same directory as theDockerfile
■ Solution
https://stackoverflow.com/questions/49512727/docker-copy-failed-createfile-looking-for-file-in-strange-location
move Dockerfile ../Dockerfile
57 von 109School of Engineering © K. Rege, ZHAW
Step 3. Create your custom Docker images
■ By Pressing F5 in VS the Container is built■ fails sometimes the first time; just redo it■ All dependent images are download
■ for really big images (e.g. W10 Server) better use docker pull
■ To create a custom image in your local environment by using Docker CLI and
your Dockerfile, you can use the docker build command
■ to run it (interactively)
docker build -t WebApplication2 .docker images
docker exec -i bd710891accb cmd
58 von 109School of Engineering © K. Rege, ZHAW
Docker CLI Commands - build, run, images
https://devhints.io/docker
59 von 109School of Engineering © K. Rege, ZHAW
… Docker CLI Commands create, exec, start
Technically, docker run =docker create + docker start.
Technically, docker run =docker create + docker start.
$ docker pull microsoft/windowsservercore:1803
docker pull
60 von 109School of Engineering © K. Rege, ZHAW
4. Add Orchestration support
■ Add Orchestrator support for Docker Compose to a solution
■ For the first time, Visual Studio creates the Dockerfile for the project and creates
a new (service section) project in your solution with several global docker-compose*.yml files, and then adds the project to those files.
■ You can then open the docker-compose.yml files and update them with
additional features
version: '3.4'
services: dockerassembly1: image: ${DOCKER_REGISTRY-}dockerassembly1 build: context: . dockerfile: DockerAssembly1/Dockerfile ports: - "8000:80" webapplication2: image: ${DOCKER_REGISTRY-}webapplication2 build: context: . dockerfile: WebApplication2/Dockerfile ports: - "8001:80"
https://docs.docker.com/compose/compose-file/
https://channel9.msdn.com/Events/Build/2017/B8106
61 von 109School of Engineering © K. Rege, ZHAW
… Define your services in Docker Compose
■ It contains static configuration data for each container
■ configuration information that might depend on the deployment environment■ like the connection string
■ If you want to take a peek at all the drudgery, take a look at the file:■ {root solution folder}-compose.vs.debug.g.yml
62 von 109School of Engineering © K. Rege, ZHAW
Step 5. Build and run your Docker Application
■ Single Container Application
■ If your application only has a single container, you can run it by deploying it to
your Docker host (VM or physical server)
■ This create a new container instance from the specified image, every time it’s
run.
■ You can use the –name parameter to give a name to the container and then usedocker start {name} (or use the container id or automatic name) to run an
existing container instance
docker run -it --rm -p 5000:80 --name WebApplication2
63 von 109School of Engineering © K. Rege, ZHAW
… Build and run your Docker Application
■ Multi-Container Application
■ In most real world scenarios, a Docker application will be composed of multiple
services, which means you need to run a multi-container application
■ To run a multi-container application with the Docker CLI,
you use the docker-compose up command.
■ This command uses the docker-compose.yml file that you have at the solution level to deploy a
multi-container application.
64 von 109School of Engineering © K. Rege, ZHAW
… Build and run your Docker Application
■ Setting up the docker-compose project as the startup project.
■ Visual Studio handles all needed setup, so you can create breakpoints as usual
and debug what finally become independent processes running in “remoteservers”.
65 von 109School of Engineering © K. Rege, ZHAW
Step 6. Test your Docker application
■ You can also test the application using PS Commandlet wget and curl from the
terminal
■ Docker application can be Debugged in VS much like normal applications
Testing and debugging containers with VS19
66 von 109School of Engineering © K. Rege, ZHAW
DifferentOrchestrationTechnologies
67 von 109School of Engineering © K. Rege, ZHAW
What are Service Fabrics?
■ Service Fabric isn’t directly comparable to container orchestrators such asKubernetes as it is more of an application server that supports a specific style ofdistributed system e.g. Stateless, Statefull, …. -> much like EJB ;-)
Problems of Service Fabric■ Lack of Portability
■ Native Service Fabric services are based on very specific styles ofimplementation
■ Service Fabric does seem to be getting squeezed out of a growing Azurecontainer ecosystem
■ If you commit to Service Fabric, you will be tied into a specific SDK andapplication server for good. This is some way from the kind of cloud-native.
■ Market is evolving towards providing a PaaS-based implementation ofKubernetes, which is ideal if you want to orchestrate applications withoutoperational overhead
https://www.ben-morris.com/azure-service-fabric-kubernetes/
68 von 109School of Engineering © K. Rege, ZHAW
Docker Compose & Swarm vs Kubernetes
Docker Compose
■ Allows configuring and starting■ multiple Docker containers.■ starting containers on the same host
Docker Swarm
■ The native docker orchestration tool that isembedded in the Docker Engine.
■ Allows for running and connecting containers■ on multiple hosts.■ a container cluster management and
orchestration tool.
■ scaling, starting a new containerwhen one crashes, networkingcontainers ...
■ The docker swarm file named stack file is verysimilar to a docker compose file.
Kubernetes
■ Kubernetes goal is very similar as that forDocker swarm.
■ A container orchestration tool
■ developed by Google.
■ Docker Compose Files may be translated toKubernetes
https://kubernetes.io/docs/tasks/configure-pod-container/translate-compose-kubernetes/
69 von 109School of Engineering © K. Rege, ZHAW
What is Kubernetes?
■ How Kubernetes works■ Applications grow to span multiple containers deployed across multiple servers,■ Provide Open source API that controls how and where those containers will run.
■ With Kubernetes,■ Orchestrate a cluster of virtual machines■ Schedule containers to run on those virtual machines
■ based on their available compute resources and the resource requirements of each container.Containers are grouped into Pods
■ Pods are the basic operational unit for Kubernetes.■ Scale those containers and pods to your desired state and manage their lifecycle to keep your
apps up and running.
■ Kubernetes Functions■ Manage service discovery■ Incorporate load balancing,■ Track resource allocation,■ Scale based on compute utilization,■ Check the health of individual resources, enable■ Enable apps to self-heal by automatically restarting or replicating containers.
https://azure.microsoft.com/en-us/topic/kubernetes/
70 von 109School of Engineering © K. Rege, ZHAW
Configuration of Kubernetes
■ All information is stored in YAML Files
path to docker Filepath to docker File
name of image in repositoryname of image in repository
71 von 109School of Engineering © K. Rege, ZHAW
Why Services?Interaction Styles
72 von 109School of Engineering © K. Rege, ZHAW
The Industrial Revolution
■ Craftsmanship: separation of duties■ Specialization increases efficiency
■ Manufactory 18th century: colocation of craftsmen■ Craftsmen are colocated
■ Task is reduced to single "core" competence■ Auxiliary task are centralized
■ Automatization 19th century■ Manpower partially replaced by machines
■ Assembly (line) of components 20th century■ Assembly of prefabricated components■ Separation into:
■ Component builder■ Assembler
73 von 109School of Engineering © K. Rege, ZHAW
The Hardware Revolution
Levels of abstractions■ Single electronic components
■ Resistors, transistors
■ Integrated logic gates: TTL
■ Highly integrated circuits
74 von 109School of Engineering © K. Rege, ZHAW
The Software Revolution
Levels of abstractions■ Individual programming statements
■ Software library function calls■ ANSI C library■ Win32 API calls
■ Software components/services■ Components: Activex (COM/OLE)■ The only universal component standard that
ever succeeded■ Technically and commercially
■ Now abandoned by Microsoft■ Basis of WinRT/UWP Implementation
75 von 109School of Engineering © K. Rege, ZHAW
Software Components and Services
■ A software component is (according Szyperski)■ i) a unit of composition and subject to third-party composition■ ii) with contractually specified interfaces■ iii) explicit context dependencies only.■ iv) software component can be deployed independently
■ A service■ i)..iii) dito■ iv) is already deployed -> federated, discovered and accessed remotely
a service is a remotely accessible, instantiated component
76 von 109School of Engineering © K. Rege, ZHAW
Benefits of SOA
■ From application silos with massive code & data duplication to
components/services
■ Microservices: SOA without logic on Transport Infrastructure (vs. ESB, Adapters)
© Mohamed Marwan Selim
https://www.youtube.com/watch?v=wgdBVIX9ifAFowler Goto 2014
77 von 109School of Engineering © K. Rege, ZHAW
Interaction Styles for Services Architecture
■ Three fundamental interaction SOA styles
■ RPC style■ Provide a functional access to the service logic via services
■ Document style■ Transfer of the data/documents that can be processed by be service logic (as bulks)
■ Representational State Transfer (REST) style■ Provide a generic (CRUD type) access to data representations (date instances)
■ The interactions styles has various implications■ Synchronous or asynchronous communication protocols■ Infrastructure requirements■ Responsiveness and latency■ etc.
78 von 109School of Engineering © K. Rege, ZHAW
RPC-Style Interaction
■ Provide a remote functional access to the service logic via services
■ Messages exchanged corresponds to the exposed operations
■ Over a synchronous transport protocol (e.g. HTTP)
■ For example
■ A payment service that accepts payments and returns a status
© Sun, Patterns andStrategies
79 von 109School of Engineering © K. Rege, ZHAW
Document Based Style Interaction
■ Transfer of data/documents that can be processed by be service logic (as bulks)
■ For task services
■ Service consumer interacts using documents that are meant to be processed as complete entities
■ Asynchronous communication architectures preferred: "Message Oriented"
■ For example
■ Transporter's web service thataccepts bid requests from ashipping company and repliesback with an appropriate bid
© Sun, Patterns andStrategies
80 von 109School of Engineering © K. Rege, ZHAW
REST as an Architecture
■ Provide a generic (CRUD type) access to the logic viewed as a data
representations (date instances i.e. state)■ REST is a paradigm and a protocol■ Application state and functionality are abstracted into resources■ Every resource is uniquely addressable using a universal syntax for use in hypermedia links■ All resources share a uniform interface for the transfer of
state between client and resource, consisting of■ A constrained set of well-defined operations■ A constrained set of content types■ Optionally supporting data/code on demand
■ ROA: Resource Oriented Architecture
as shown in Roy Fielding's dissertationin the context of informationand media access on the Web)
81 von 109School of Engineering © K. Rege, ZHAW
REST as a Protocol
■ Interfaces are limited to HTTP verbs:■ GET is used for obtaining a representation of a resource.■ DELETE is used for removing representations of a resource.■ POST is used for updating or creating the representations■ PUT is used for creating representations of a resource.
■ Messages are mostly in XML, confined by optional schemas
■ Simple messages can be encoded with URL encoding
■ Service and service providers must be resources while a consumer can be a
resource
■ REST as a protocol: pass data via xml or json and use of http mechanism and
infrastructure, etc.■ REST as a protocol (POX = plain old XML) can be used as a base for SOA too
82 von 109School of Engineering © K. Rege, ZHAW
Microservice Definition
■ Is (logic + state) that is independently versioned, deployed, and scaled
■ Has a unique name that can be resolved■ e.g. fabric:/myapplication/myservice
■ Interacts with other microservices over well defined interfaces and protocols likeREST or gRPC
■ Remains always logically consistent in the presence of failures (!)
■ Hosted inside a “container” (code + config)
■ Can be written in any language and framework
■ Developed by a small engineering team
83 von 109School of Engineering © K. Rege, ZHAW
Types of Microservices
■ Stateless Microservice■ Has either no state or it can be retrieved from an external store■ There can be N instances■ e.g. web frontends, protocol gateways, Azure Cloud Services etc.
■ Stateful Microservice■ Maintain hard, authoritative state■ N consistent copies achieved through replication and local persistence■ e.g. database, documents, workflow, user profile, shopping cart etc.
84 von 109School of Engineering © K. Rege, ZHAW
Stateless vs Stateful - Taxi Analogy
Stateless: Airport Taxi■ simply use next free taxi in queue■ Advantage:
■ Taxi resource is used optimally■ if number of guest and taxis is well balanced
■ Disadvantage:■ all I need I have to take with me■ no state, cannot deposit (excess luggage)■ hat to pay trustworthy taxi driver
Stateful : Personal Car■ I park my car on the parking lot■ Advantage:
■ may deposit something■ is ready to go, when I come back
■ Disadvantage:■ Bad use of resources (car is not in use)■ parking lot may be full■ I have to pay high parking fees
85 von 109School of Engineering © K. Rege, ZHAW
3-Tier Service Pattern
Queues Storage
Front End(StatelessWeb)
StatelessMiddle-tierCompute
Cache
Load BalancerLoad Balancer
86 von 109School of Engineering © K. Rege, ZHAW
Stateful Services for Persistency
data stores
Load Balancer
StatefulMiddle-tierDB access
Front End(StatelessWeb)
87 von 109School of Engineering © K. Rege, ZHAW
Designing a Microservice OrientedArchitecture
88 von 109School of Engineering © K. Rege, ZHAW
Designing a Microservice-oriented application
■ Assumption: The application must support a variety of clients with GUI■ Traditional web apps■ Web apps running as Single Page Applications (SPAs),■ Mobile web apps, and native mobile apps.
■ The application might also expose an API for third parties to consume.■ It should also be able to integrate its microservices or external applications
■ Will also help resiliency of the microservices in the case of partial failures
■ The application will consist of the following components:■ Presentation components. These are responsible for handling the UI and consuming remote
services.■ Domain or business logic. This is the application’s domain logic.■ Database access logic. This consists of data access components responsible for accessing
databases (SQL or NoSQL).■ Application integration logic. This includes a messaging channel, mainly based on message
brokers.
89 von 109School of Engineering © K. Rege, ZHAW
eShopOnContainers: A Reference Application
■ A simplified e-commerce (e-shop) application that presents a catalog of products
90 von 109School of Engineering © K. Rege, ZHAW
Communication Architecture
■ Synchronous Http client-to-microservice communication through API Gateway■ API Gateways
■ to funnel all requests, single point of entry.■ For new Applications use gRPC protocol (or REST)
■ Asynchronous event-based communication.■ This occurs through an event bus to propagate updates across microservices or to integrate with
external applications.■ The event bus can be implemented with any messaging-broker infrastructure
■ SignalR or RabbitMQ, or using higher-level (abstraction-level) service buses like Azure ServiceBus, NServiceBus, MassTransit, or Brighter
91 von 109School of Engineering © K. Rege, ZHAW
Architecture: Data Sovereignty
■ For Reference each microservice owns its own database or data source,■ although all SQL Server databases are deployed as a single container.
■ In a real production environment, for high availability and for scalability, thedatabases should be based on database servers in the cloud or on-premises,
but not in a container.
■ Benefits of a microservice-based solution■ Each microservice is relatively small - easy to manage and evolve.■ It is easy for a developer to understand and get started quickly with good productivity.■ Containers start fast, which makes developers more productive.■ An IDE like Visual Studio can load smaller projects fast, making developers productive.■ Each microservice can be designed, developed, and deployed independently of other microservices
-> Problem: Interfaces and Versioning of Interfaces (see later)
92 von 109School of Engineering © K. Rege, ZHAW
Architecture: External versus internal
■ The external architecture is the microservice architecture composed by multiple
services,
■ The internal architectures, may be chosen differently depending on the variousconstraints, may even use different technology or programming language
93 von 109School of Engineering © K. Rege, ZHAW
Architecture: Polyglot Microservices
■ You can also build microservices with many technologies and languages, such
as ASP.NET Core Web APIs, NancyFx, ASP.NET Core SignalR (available with.NET Core 2), F#, Node.js, Python, Java, C++, GoLang, and more.
94 von 109School of Engineering © K. Rege, ZHAW
Creating a simple CRUD microservice
■ When you are developing this kind of service, you only need ASP.NET Core and
a data-access API or ORM like Entity Framework Core
Interface Definitionas Proto File
Interface Definitionas Proto File
95 von 109School of Engineering © K. Rege, ZHAW
Downsides of a microservice-based solution
■ Distributed application: adds complexity for developers when they are designing
and building the services.
■ Deployment complexity: application consisting of dozens of microservices typesand needs high scalability (it needs to be able to create many instances per
service and balance those services across many hosts)
■ Atomic transactions. Atomic transactions between multiple microservices usually
are not possible.
■ Increased global resource needs (total memory, drives, and network resources
for all the servers or hosts).
■ Partitioning into the microservices: challenge is deciding how to partition an end-to-end application into multiple microservices.
96 von 109School of Engineering © K. Rege, ZHAW
Key Takeaways
■ Benefits of using Containers■ Reduce deployment problems caused by failing dependencies in production environments.■ Also useful for monolithic application, use of single deployment mechanism■ Future: Containers will be ubiquitous and units of deployment
■ Docker-based containers are becoming the de facto standard in the Industry
■ Microservices advantages■ The microservices architecture is becoming the preferred approach for distributed and large or
complex mission-critical applications based on many independent subsystems.
■ Microservices challenges■ fragmented and independent data models, resilient communication between microservices,
eventual consistency, and operational complexity that results from aggregating logging andmonitoring information from multiple sources.
■ Risk of partial failure or slow responses: redundancy, retry mechanism, caching, automatic restart
■ Security■ critical element of building safer apps is having a secure way of communicating with
■ requires credentials, tokens, passwords, application secrets, trusted server relations
■ Orchestration■ Container-based orchestrators, such as Azure Kubernetes Service are key
97 von 109School of Engineering © K. Rege, ZHAW
Azure
98 von 109School of Engineering © K. Rege, ZHAW
Creating a free Azure account
■ Azure offers a free trial account that’s good for 12 Months and provides up to
$200 of free credit https://azure.microsoft.com/free
99 von 109School of Engineering © K. Rege, ZHAW
Azure Platform
■ There are more than 100 services in Azure
■ Grouped in families of related services■ e.g. compute, web + mobile, containers, and identity
■ Most of what you create in Azure falls into the IaaS and PaaS areas.
You purchase the basecompute resources froma vendor that managesthe core infrastructure.You create and managethe VMs, data, andapplications
You purchase the basecompute resources froma vendor that managesthe core infrastructure.You create and managethe VMs, data, andapplications
Don’t worry about VMs orthe virtual network, andyour operations team canfocus more of their time onapplication reliability andperformance.
Don’t worry about VMs orthe virtual network, andyour operations team canfocus more of their time onapplication reliability andperformance.
100 von 109School of Engineering © K. Rege, ZHAW
Virtualization in Azure
■ A VM is one of the most common resources in cloud computing. A VM
contains a virtual CPU (vCPU), memory (vRAM), storage (vDisk), andnetwork connectivity (vNIC),
Runs on a modifiesVersion of WindowsServer
Runs on a modifiesVersion of WindowsServer
But supportsalso Linux -better!
But supportsalso Linux -better!
And WindowsAnd Windows
Hyper-V is a type 1(bare-metal) hypervisor
Hyper-V is a type 1(bare-metal) hypervisor
101 von 109School of Engineering © K. Rege, ZHAW
Management Tools
■ AZURE PORTAL■ and it’s a convenient way to use Azure without
installing anything on your computer.■ New features and services are constantly being
added to Azure
■ AZURE CLOUD SHELL■ is a web-based interactive console that provides
a Bash or Power shell■ VS Integrated
■ LOCAL AZURE CLI AND
POWERSHELL TOOLS■ allows for access to your local filesystem and
tools.
aka.ms/azops-cloudshell
102 von 109School of Engineering © K. Rege, ZHAW
Creating a VM from your Web browser
■ The Azure portal is a web-based graphical tool■ lets you see how all the different components come together■ do a quick sanity check
■ Open a web browser to https://portal.azure.com■ 1. Select Create a Resource in the upper-left corner of the dash-board■ 2. Choose Compute from the list of resources you can create■ 3. Select Ubuntu Server by Canonical, and then choose e.g. Ubuntu 18.04 LTS■ 4. To get started, select Create. In the settings window that opens, type a name for your VM, such
as webvm.■ 5. Choose VM disk type: Premium or Standard SSD disk : Premium low-latency, Standard HDD
disks■ 6. enter a username for a user account in the Portal■ Goto Portal
■ Select Bash from the drop-down menu in the upper-left corner
103 von 109School of Engineering © K. Rege, ZHAW
Azure Containers
■ Creating a single container instance
■ Image was pushed to the Docker Hub.■ create a container instance using this prebuilt public image from Docker Hub, which provides a
ready-to-run application image.
https://docs.microsoft.com/azure/vs-azure-tools-docker-hosting-web-apps-in-docker
104 von 109School of Engineering © K. Rege, ZHAW
… Azure Containers
■ Open the Azure portal, and select the Cloud Shell icon from the top menu.
■ Create a container instance. Specify that you’d like a public IP address and to
open port 80. The container will be pulled from the Hub
■ To see what was created, look at the details of the container:
■ Check for the assigned public IP address:
■ Open in Browser with this IP
105 von 109School of Engineering © K. Rege, ZHAW
Azure Kubernetes Service
■ Microsoft also pushes towards Kubernetes Orchestrator
■ As the name implies, a container orchestrator manages your container instances,
monitors their health, and can scale as needed.
■ Creating a cluster with Azure Kubernetes Services
https://azure.microsoft.com/en-gb/services/kubernetes-service/?cdn=disablehttps://docs.microsoft.com/en-us/azure/dev-spaces/how-to/create-cluster-cloud-shell
106 von 109School of Engineering © K. Rege, ZHAW
… Azure Kubernetes Service
simply add Kubernetes Supportto project
simply add Kubernetes Supportto project
107 von 109School of Engineering © K. Rege, ZHAW
Fragen ?Flying: the air is notat all dangerous but
the ground
108 von 109School of Engineering © K. Rege, ZHAW
Build Samples on Windows and Linux
■ Navigate to C:\Users\<user name>\source\repos
■ Download the samples in
■ In the Docker client, switch to Linux or Windows containers.
■ Navigate to the Dockerfile folder at dotnet-docker/samples/aspnetapp.
■ Run the following commands to build and run the sample in Dock
■ Start your browser to test on http://localhost:5000/
git clone https://github.com/dotnet/dotnet-dockerdocker build -t aspnetapp .
git clone https://github.com/dotnet/dotnet-docker
109 von 109School of Engineering © K. Rege, ZHAW
The DB Connection String
■ ConnectionString property to your settings.json UNSAFE
■ Docker-compose.yml UNSAFE
■ Azure Key Vault SAFE■ Allows a detailed control level of the application secrets usage■ Applications have to be registered in the organization’s Active Directory, so they can use the Key
Vault.
https://azure.microsoft.com/en-us/services/key-vault/?cdn=disable