Slide 1

Slide 1 text

Cloud-Native Webinar-Reihe Cloud-Native: ASP.NET Core Services fit machen

Slide 2

Slide 2 text

.NET Consultant @ Thinktecture AG Boris Wilhelms ▪ Architecting ☁️-native solutions ▪ Helps customer building Backend-Things with .NET ▪ Takes care of authentication & authorization / Identity Access Management Solutions ▪ Loves 🐧 [email protected] @boriswilhelms thinktecture.com ASP.NET Core Services fit machen Cloud-Native

Slide 3

Slide 3 text

Make ASP.NET Core Services Cloud-Native ready! Is it a lot of work? 3 ASP.NET Core Services fit machen Cloud-Native

Slide 4

Slide 4 text

No! 4 ASP.NET Core Services fit machen Cloud-Native

Slide 5

Slide 5 text

”… is highly distributed, must operate in a constantly changing environment, and is itself constantly changing.” Cornelia Davis, Author of Cloud Native Patterns: Designing change-tolerant software Cloud-Native Software 5 ASP.NET Core Services fit machen Cloud-Native

Slide 6

Slide 6 text

Availability Scalability Resilience Configurability Observability Cloud-Native Applications Cloud-Native Attributes 6 ASP.NET Core Services fit machen Cloud-Native

Slide 7

Slide 7 text

- Observability - Logging - Open Telemetry - Health Checks - Configurability - Resilience - Reverse Proxy gotchas Cloud-Native ASP.NET Core Services fit machen Topics for today 7

Slide 8

Slide 8 text

Observability 8 ASP.NET Core Services fit machen Cloud-Native

Slide 9

Slide 9 text

- Use ILogger - Log to console - Log as JSON! Cloud-Native ASP.NET Core Services fit machen Logging 9

Slide 10

Slide 10 text

- Use OpenTelemetry - OpenTelemetry is a collection of tools, APIs, and SDKs. Use it to instrument, generate, collect, and export telemetry data (metrics, logs, and traces) to help you analyze your software’s performance and behavior. - ASP.NET Core/.NET emits telemetry data consumeable by OpenTelemetry - Use System.Diagnostics.Activity to create custom traces - Use System.Diagnostics.Meter to create custom metrics Cloud-Native ASP.NET Core Services fit machen Observability 10

Slide 11

Slide 11 text

- Ready vs Live - Ready: - Is the application ready to serve requests? - Only checked until ready - Live: Is the application still alive? - Checked periodically after ready check - Keep them simple! - Keep “Live” health checks even simpler! - Don’t check for dependencies - This might result in unnecessary restarts of container Cloud-Native ASP.NET Core Services fit machen Health Checks 11

Slide 12

Slide 12 text

Configurability 12 ASP.NET Core Services fit machen Cloud-Native

Slide 13

Slide 13 text

ConfigurationBuilder merges the values of different providers together 1. appsettings.json 2. appsettings.{environment}.json (ASPNETCORE_ENVIRONMENT) 3. User Secrets (read once at startup in development) 4. Environment variables (read once at startup) 5. Commandline arguments (read once at startup) Cloud-Native ASP.NET Core Services fit machen How does configuration work in ASP.NET Core? 13

Slide 14

Slide 14 text

- All these providers provide only a snapshot at startup - Microsoft.Extensions.Configuration.KeyPerFile to the rescue! - Maps a folder of files into the configuration - Filename is the key - Content of the file is the key - Can be used for e.g. ConfigMaps in Kubernetes Cloud-Native ASP.NET Core Services fit machen How does configuration work in ASP.NET Core? 14

Slide 15

Slide 15 text

Resilience 15 ASP.NET Core Services fit machen Cloud-Native

Slide 16

Slide 16 text

- Be prepared that a dependency is not there! - Let the platform handle resilience if possible! - If not: - Some libraries have retries and fallbacks build in (e.g. Azure Storage SDK) - EF Core: “EnableRetryOnFailure” or custom “Execution strategies” - Everything else: Use Polly - Polly is a .NET resilience and transient-fault-handling library that allows developers to express policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, and Fallback in a fluent and thread-safe manner. Cloud-Native ASP.NET Core Services fit machen Resilience 16

Slide 17

Slide 17 text

Reverse Proxy gotchas 17 ASP.NET Core Services fit machen Cloud-Native

Slide 18

Slide 18 text

Cloud-Native ASP.NET Core Services fit machen How do reverse proxies work? 18 https://myapp.com/api/products https://myapp.com/api/orders IP: 212.127.12.13 External IP: 112.22.15.43 Internal IP: 10.0.0.1

Slide 19

Slide 19 text

Reverse Proxy gotchas 19 ASP.NET Core Services fit machen Cloud-Native

Slide 20

Slide 20 text

- A reverse proxies - receives the request from the client - inspects the request to find the proper target - makes the actual http request to the container/service - adds additional headers with data about the client and the called URLs (X-Forwarded-*) - The service - sees the reverse proxy as a client - will be called with a different url/host then it is reachable from the internet - might have different HTTP routes then the reverse proxy - Proxy Route: /api/products - Service Route /products Cloud-Native ASP.NET Core Services fit machen How do reverse proxies work? 20

Slide 21

Slide 21 text

- Let the platform handle things, if possible! - There is not much to do to be cloud-native ready! - Make infrastructure components as configurable as possible! - Use (defacto-)standards where possible! - Be aware of reverse proxy! They are everywhere! Cloud-Native ASP.NET Core Services fit machen Conclusion 21

Slide 22

Slide 22 text

thinktecture.com/ cloud-30-11-2022 thinktecture.com/ cloud-25-01-2023 Cloud-Native Webinar-Reihe – weitere Termine thinktecture.com/ cloud-14-12-2022 thinktecture.com/ cloud-11-01-2023 Alle Webinare unserer Cloud-Native-Reihe finden Sie hier: thinktecture.com/cloud-native-webinare/ 03. November 2022 – 25. Januar 2023 ASP.NET Core Services fit machen Cloud-Native 22

Slide 23

Slide 23 text

https://www.thinktecture.com/ueber-uns/karriere/ Dankeschön! Demos aus der Session: https://github.com/thinktecture-labs/aspnetcore- cloudnative Boris Wilhelms https://thinktecture.com/boris-wilhelms 23