Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Meistern des Inner Dev Loop für .NET-Containerapplikationen

Meistern des Inner Dev Loop für .NET-Containerapplikationen

Sie möchten für Ihre .NET-Applikation auf Container und Microservices setzen und fragen sich, was sich dadurch am Entwicklungsprozess ändert? In dieser Session zeigt Ihnen Daniel Lindemann wie Multicontainerapplikationen erstellt, debuggt und mit dem Containerorchestrator Kubernetes betrieben werden. Lernen Sie Tricks und Tools für den Inner Dev Loop kennen, die Entwickler:innen helfen, sich voll und ganz auf die Entwicklung der Software zu konzentrieren.

Code: https://dlmn.link/lotto-microservices

Daniel Lindemann

October 11, 2022
Tweet

More Decks by Daniel Lindemann

Other Decks in Technology

Transcript

  1. Daniel Lindemann Begeisterter .NET- Entwickler und Consultant mit einer seltsamen

    Liebe für das Optimieren, Automatisieren und Containerisieren Was ich mache: ▪ Cloud-native & Serverless architectures ▪ Container technologies ▪ DevOps - Dev by night, Ops by day Web: https://www.dlindemann.de LinkedIn: https://linkedin.com/in/daniel-lindemann Twitter: @daniellindemann GitHub: https://github.com/daniellindemann
  2. AGENDA ▪ The Inner-Loop ▪ Development & Testing ▪ Applikationsarchitektur

    ▪ Deployment Vorbereitung ▪ Debugging in Kubernetes-Cluster ▪ Projekt-Onboarding
  3. DISCLAIMER Demos ▪ Code in C# mit .NET 6 ▪

    VS Code Rulez ▪ WSL Rulez ▪ Das Terminal ist unser Freund ▪ Services benutzen HTTP zur Kommunikation ▪ Container sind Linux Container ▪ Kubernetes
  4. DEV LOOP Inner and Outer Dev Loop Push Build Test

    Code Integrate Test Release Deploy Inner Loop Outer Loop
  5. INNER DEV LOOP Traditional Inner Dev Loop Code (3 mins)

    Build & Reload (1 min) Inspect (1 min) Commit (10 s)
  6. INNER DEV LOOP Container Inner Dev Loop Z e i

    t Build (1 min) Inspect (1 min) Commit (10 s) Code (3 mins) Container build, Upload & deploy (4 mins)
  7. INNER DEV LOOP Container Inner Dev Loop Z e i

    t Build (1 min) Inspect (1 min) Commit (10 s) Code (3 mins) Container build, Upload & deploy (4 mins)
  8. INNER DEV LOOP Container Inner Dev Loop Z e i

    t Build (1 min) Inspect (1 min) Commit (10 s) Code (3 mins) Run (1 min)
  9. HERAUSFORDERUNGEN Heutige Herausforderungen für Entwickler ▪ Starten von mehreren Projekten

    ▪ Debugging ▪ Installation von Abhängigkeiten in Dev-Umgebung ▪ Service Discovery ▪ Erstellen von Images und Containern ▪ Aufbau lose gekoppelter Systeme ▪ Entwicklungsumgebung aufsetzen ▪ Onboarding von neuen Kollegen
  10. APPLIKATION Beispiel-Applikation: Lotto Service Web RandomNumber Service Lotto Service /api/LottoNumber

    ​ /api​ /LottoNumber​ /history /api/RandomNumber https://dlmn.link/lotto-microservices
  11. PROJECT TYE Was ist Tye? ▪ Vereinfacht das Entwickeln, Testen

    und Deployen von Container-Applikationen und Microservices ▪ Mehrere Dienste lokal ausführen ▪ Service Discovery über Konfigurationskonventionen ▪ Versteht .NET Projekte ▪ Lokales Dashboard für Logs und Metriken ▪ Ausführen von Abhängigkeiten als Docker Container https://github.com/dotnet/tye
  12. PROJECT TYE Installation und Ausführung ▪ Tye ist ein CLI-Tool

    ▪ Globale Installation als .NET Tool > dotnet tool install -g Microsoft.Tye --version "0.11.0-alpha.22111.1" ▪ Tye erkennt Solutions und tye.yaml-Konfigurationsdateien > tye run ▪ Tye Konfigurationsdateien sind ähnlich zu Docker Compose Konfigurationsdateien
  13. PROJECT TYE Projekt Startup ~/../lotto-microservices ❯❯❯ tye run Loading Application

    Details... Launching Tye Host... [09:48:33 INF] Executing application from ~/../lotto-microservices/tye.yaml [09:48:33 INF] Dashboard running on http://127.0.0.1:8000 [09:48:33 INF] Build Watcher: Watching for builds... [09:48:33 INF] Building projects [09:48:33 INF] Application lotto-microservices started successfully with Pid: 14407 [09:48:33 INF] Launching service web_6a503ef0-a: /home/dli/repos/lotto-microservices/src/Web/bin/Debug/net6.0/Web [09:48:33 INF] Launching service randomnumberservice_2ea96c3d-2: /home/dli/repos/lotto- microservices/src/RandomNumberService/bin/Debug/net6.0/RandomNumberService [09:48:33 INF] Launching service lottoservice_05a48c2c-f: /home/dli/repos/lotto- microservices/src/LottoService/bin/Debug/net6.0/LottoService [09:48:33 INF] lottoservice_05a48c2c-f running on process id 14637 bound to http://*:33425, https://*:39505 [09:48:33 INF] web_6a503ef0-a running on process id 14638 bound to http://*:36841, https://*:46755 [09:48:33 INF] randomnumberservice_2ea96c3d-2 running on process id 14636 bound to http://*:39639, https://*:44553 [09:48:33 INF] Replica lottoservice_05a48c2c-f is moving to a ready state [09:48:33 INF] Replica randomnumberservice_2ea96c3d-2 is moving to a ready state [09:48:33 INF] Replica web_6a503ef0-a is moving to a ready state
  14. PROJECT TYE Weitere Features ▪ Ausführen aller Applikationsbestandteile als Container

    ▪ Anbinden von Application Logging Diensten ▪ Distributed Logs: Application Insights, Elasticsearch, Seq ▪ Distributed Tracing: Zipkin ▪ Azure Functions Support ▪ Ingress ▪ Images erstellen und deployen
  15. APPLIKATIONSARCHITEKTUR Ziel ▪ Cloud Ready ▪ Läuft auf virtualisierter Hardware

    ▪ Self-contained; kann als Image ausgeführt werden ▪ Cloud Friendly ▪ Besteht aus lose gekoppelten Diensten ▪ Dienste können über Namen gefunden ▪ Nach 12-Factor App Prinzipien entwickelt (https://12factor.net/) ▪ Infrastuktur- und Cloud-agnostisch ▪ Austausch von Komponenten zwischen DEV und PROD möglich ▪ Datenbank ▪ Message Bus
  16. DAPR Was ist Dapr? ▪ Distributed Application Runtime ▪ Entkopplung

    von Applikationsbestandteilen ▪ Best-Practices Building Blocks ▪ Erweiterbares und integrierbares Komponentensystem ▪ Programmiersprachen- und Framework-Unabhängig ▪ Plattform-agnostisch (Cloud + Edge) ▪ Ausführung in Self-hosted- und Kubernetes-Umgebungen ▪ CLI Tools bestehend aus Dapr CLI und Runtime ▪ Open Source ▪ Dapr Client SDK für .NET https://dapr.io
  17. DAPR Installation und Ausführung ▪ Installation ▪ Dapr bietet Installationsskripte

    für​Windows,​MacOS​und​Linux:​https://docs.dapr.io/getting-started/install-dapr- cli/ ▪ Dapr initialisieren ~\..\lotto-microservices ❯❯❯ dapr init ⌛ Making the jump to hyperspace... ℹ️ Container images will be pulled from Docker Hub ℹ️ Installing runtime version 1.8.4 ↙ Downloading binaries and setting up components... Dapr runtime installed to /home/dli/.dapr/bin, you may run the following to add it to your path if you want to run daprd directly: export PATH=$PATH:/home/dli/.dapr/bin ✅ Downloading binaries and setting up components... ✅ Downloaded binaries and completed components set up. ℹ️ daprd binary has been installed to /home/dli/.dapr/bin. ℹ️ dapr_placement container is running. ℹ️ dapr_redis container is running. ℹ️ dapr_zipkin container is running. ℹ️ Use `docker ps` to check running containers. ✅ Success! Dapr is up and running. To get started, go here: https://aka.ms/dapr-getting-started
  18. DAPR Sidecar starten ~\..\lotto-microservices ❯❯❯ dapr run --app-id "randomnumberservice" --app-port

    "5000" --app-protocol "http" --app-ssl=false --components-path "dapr/components" --dapr-grpc-port "50001" --dapr-http-port "3500" ℹ️ Starting Dapr with id randomnumberservice. HTTP Port: 3500. gRPC Port: 50001 INFO[0000] starting Dapr Runtime -- version 1.8.4 -- commit 18575823c74318c811d6cd6f57ffac76d5debe93 INFO[0000] log level set to: info INFO[0000] metrics server started on :39209 INFO[0000] standalone mode configured INFO[0000] app id: randomnumberservice INFO[0000] local service entry announced: randomnumberservice -> 172.31.29.51:44539 INFO[0000] Initialized name resolution to mdns INFO[0000] loading components INFO[0000] component loaded. name: lottostatestore-redis, type: state.redis/v1 INFO[0000] all outstanding components processed ... INFO[0000] http server is running on port 3500 ... INFO[0000] application protocol: http. waiting on port 5000. This will block until the app is listening on that port. INFO[0000] application discovered on port 5000 INFO[0000] application configuration loaded INFO[0000] dapr initialized. Status: Running. Init Elapsed 49.355699ms ✅ You're up and running! Dapr logs will appear here.
  19. DAPR Service Invocation Web RandomNumber Service Lotto​Service { "min": 1,

    "max": 49 } http://localhost:3500/v1.0/invoke/randomnumberservice/method/api/randomnumber Multicast​DNS component { "min": 1, "max": 49 } Post Post http://10.0.0.2:5000/api/randomnumber 1 7 2 3 6 4 5
  20. DAPR State Store Lotto Service { key: 'lottoFieldsTop100', value: [

    {"numbers":[8,19,34,36,40,45],"superNumber":6}, {"numbers":[2,6,7,19,24,39],"superNumber":1} ] } http://localhost:3500/v1.0/state/lottostatestore Post [ {"numbers":[8,19,34,36,40,45],"superNumber":6}, {"numbers":[2,6,7,19,24,39],"superNumber":1} ] http://localhost:3500/v1.0/state/lottostatestore/lottoFieldsTop100 Get Key Value lottoFieldsTop100 [ { "numbers":[8,19,34,36,40,45], "superNumber":6 }, { "numbers":[2,6,7,19,24,39], "superNumber":1 } ] someOtherCacheKey Hello BASTA! State Store der Wahl ...
  21. ANNAHMEN ÜBER INFRASTRUKTUR Anmerkung ▪ Keine Annahme über Infrastruktur im

    Code treffen ▪ Dateisystem ▪ Netzwerk ▪ Sicherheit Beispiel: // do not use https - networking assumptions are not the job of the program app.UseHttpsRedirection();
  22. DRAFT Was ist Draft? ▪ Erstellen von Dockerfiles auf Basis

    von Projekten ▪ Erstellen von Kubernetes Deployment Files ▪ Manifest-Dateien ▪ Kustomize Manifests ▪ Helm Charts ▪ Erstellen von Github Actions ▪ Image erstellen und in Container Registry pushen ▪ Applikation in Kubernetes bereitstellen ▪ Version 2 aktuell in Entwicklung mit Preview Status https://draft.sh
  23. DRAFT Installation und Ausführung ▪ Installation ▪ Draft ist für

    Windows, MacOS und Linux verfügbar: https://github.com/Azure/draft/releases ▪ Azure CLI Extension verfügbar: az aks draft ▪ Draft erkennt Projekttypen anhand der Programmiersprache ~\..\lotto-microservices\src\randomnumberservice ❯❯❯ draft create [Draft] --- Detecting Language --- [Draft] --> Draft detected JSON (96.271358%) [Draft] --> Could not find a pack for JSON. Trying to find the next likely language match... [Draft] --> Draft detected csharp (1.339857%) Use the arrow keys to navigate: ↓ ↑ → ← ? We found Dockerfile in the directory, would you like to recreate the Dockerfile?: ▸ yes no
  24. DOCKERFILE MIT VS CODE Anmerkung ▪ Dockerfiles können auch mit

    Code erstellt werden ▪ VS Code: Command Palette öffnen → Docker: Add Docker Files To Workspace...
  25. BRIDGE TO KUBERNETES Was ist Bridge to Kubernetes? ▪ Remote

    Debugging ▪ Umleiten von Requests zwischen Dev Box und Kubernetes Cluster ▪ Verringert den Deployment-Aufwand um Code testen ▪ Vorteilhaft für große Applikationen mit vielen Containern ▪ Debugging innerhalb eines spezifischen Applikationkontexts ▪ Keine Erstellung von spezifischen Docker- oder Kuberneteskonfigurationen notwendig ▪ Extension für ▪ Visual Studio Code ▪ Visual Studio https://learn.microsoft.com/ en-us/visualstudio/bridge/
  26. APPLIKATION IN KUBERNETES Bridge to Kubernetes: Lotto Service Web​Pod Web

    Service Deployment Lotto Service Pod Deployment Lotto Service RandomNumber Service Pod Deployment RandomNumber Service Ingress
  27. DEBUGGING TUNNEL Bridge to Kubernetes Web Pod Web Service Deployment

    Lotto Service Pod Deployment Lotto Service RandomNumber Service Ingress RandomNumber Service Pod Clone
  28. RandomNumber Service Pod Clone DEBUGGING TUNNEL Bridge to Kubernetes Web​Pod

    Web Service Deployment Lotto Service Pod Deployment Lotto Service RandomNumber Service Ingress Bridge​to​ Kubernetes​ Agent Envoy Proxy Pod Tunnel / port-forward RandomNumber Service Instanz ▪ Update hosts ▪ Inject environment variables
  29. DEV CONTAINER Was sind Dev Container? ▪ Full-Featured Development Environment

    in einem Container ▪ Installation von projektspezifischen Extensions ▪ Erweiterbar über devcontainer.json Konfigurationsdatei ▪ Installation von Abhängigkeiten über Dockerfile ▪ Umgebung personalisieren mit Dotfiles Repository ▪ Laufen nur mit Linux ▪ Technologie hinter Github Codespaces ▪ Start + Code ▪ Ist die Umgebung verfrickelt, einfach neuen Dev Container erstellen https://code.visualstudio.com /docs/remote/containers
  30. DEV CONTAINERS Installation und Konfiguration ▪ Voraussetzung Docker ▪ Podman

    kann genutzt werden, ist aber offiziell nicht supportet ▪ Installation der Dev Container Extension - Dev Containers - Visual Studio Marketplace ▪ Erstellen der Dev Container Konfiguration ▪ Command Palette → Dev Containers: Add Dev Container Configuration Files... ▪ Basis Image auswählen ▪ Zusätzliche Features aktivieren
  31. abtis verfügt über mehr als 15 Jahre Erfahrung in der

    Planung und dem Betrieb von Microsoft Infrastrukturen und betreut bereits mehr als 100.000 Anwender der Cloudplattformen Microsoft 365 und Azure. Als einer der zehn Fokuspartner von Microsoft in Deutschland mit 14 Gold-Kompetenzen setzen wir ein starkes Zeichen als Vorreiter in der IT-Branche. www.abtis.de +49 7231 4431 - 100 [email protected]