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. MEISTERN DES INNER DEV LOOP FÜR
    .NET-CONTAINERAPPLIKATIONEN
    BASTA! 2022

    View Slide

  2. 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

    View Slide

  3. AGENDA
    ▪ The Inner-Loop
    ▪ Development & Testing
    ▪ Applikationsarchitektur
    ▪ Deployment Vorbereitung
    ▪ Debugging in Kubernetes-Cluster
    ▪ Projekt-Onboarding

    View Slide

  4. 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

    View Slide

  5. MICROSERVICES ≠ CONTAINERS
    "Microservices" ist ein
    Architekturansatz für Software
    Container sind ein
    Implementierungsdetail, das oft hilft

    View Slide

  6. THE INNER LOOP
    Developer Workflow

    View Slide

  7. DEV LOOP
    Inner and Outer Dev Loop
    Push
    Build
    Test
    Code
    Integrate
    Test
    Release
    Deploy
    Inner
    Loop
    Outer
    Loop

    View Slide

  8. INNER DEV LOOP
    Traditional Inner Dev Loop
    Code
    (3 mins)
    Build & Reload
    (1 min)
    Inspect
    (1 min)
    Commit
    (10 s)

    View Slide

  9. 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)

    View Slide

  10. 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)

    View Slide

  11. 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)

    View Slide

  12. 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

    View Slide

  13. APPLIKATION
    Beispiel-Applikation: Lotto Service
    Web
    RandomNumber
    Service
    Lotto Service
    /api/LottoNumber

    /api​
    /LottoNumber​
    /history
    /api/RandomNumber
    https://dlmn.link/lotto-microservices

    View Slide

  14. DEVELOPMENT & TESTING
    Developer Workflow mit Tye

    View Slide

  15. 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

    View Slide

  16. 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

    View Slide

  17. 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

    View Slide

  18. PROJECT TYE
    Dashboard

    View Slide

  19. DEMO

    View Slide

  20. 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

    View Slide

  21. APPLIKATIONSARCHITEKTUR
    Lose Kopplung mit Dapr

    View Slide

  22. 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

    View Slide

  23. 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

    View Slide

  24. DAPR
    Building Blocks
    https://docs.dapr.io/concepts/overview/

    View Slide

  25. DAPR
    Sidecar Pattern
    https://docs.dapr.io/concepts/overview/

    View Slide

  26. DAPR
    Components
    https://docs.dapr.io/concepts/components-concept/

    View Slide

  27. 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

    View Slide

  28. 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.

    View Slide

  29. 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

    View Slide

  30. DEMO

    View Slide

  31. 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
    ...

    View Slide

  32. DEMO

    View Slide

  33. 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();

    View Slide

  34. DEPLOYMENT VORBEREITUNG
    Bootstrap Dockerfiles und Manifests mit Draft

    View Slide

  35. 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

    View Slide

  36. 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

    View Slide

  37. DEMO

    View Slide

  38. DOCKERFILE MIT VS CODE
    Anmerkung
    ▪ Dockerfiles können auch mit Code erstellt werden
    ▪ VS Code: Command Palette öffnen → Docker: Add Docker Files To Workspace...

    View Slide

  39. DEBUGGING IN KUBERNETES-CLUSTER
    Local und Remote Debugging mit Bridge to Kubernetes

    View Slide

  40. 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/

    View Slide

  41. DEBUGGING
    Bridge to Kubernetes

    View Slide

  42. 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

    View Slide

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

    View Slide

  44. 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

    View Slide

  45. DEMO

    View Slide

  46. PROJEKT ONBOARDING
    Vorgefertigte Entwicklungsumgebung mit Dev Containern

    View Slide

  47. 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

    View Slide

  48. 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

    View Slide

  49. DEV CONTAINERS
    Funktionsweise
    https://code.visualstudio.com/docs/remote/containers

    View Slide

  50. DEV CONTAINER
    Startup

    View Slide

  51. DEMO

    View Slide

  52. View Slide

  53. 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]

    View Slide