Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Continuous Deployment with Akka.Cluster and Kubernetes (Akka.NET)


Published on

In this 60 minute long webinar Petabridge and Akka.NET co-founder Aaron Stannard you will learn about how companies ranging from the Fortune 500 to brand new startups are changing the way the build .NET applications to leverage the very latest offerings from Microsoft and the .NET open source community.

You'll learn how and why companies are moving their applications onto .NET Core; rearchitecting them to use Akka.NET for fault tolerance, scalability, and the ability to respond to customers in real-time; containerizing them with Docker; putting everything together using Kubernetes for orchestration on-premise or on the cloud with Azure Container Services.

This session will provide an overview of how all of these technologies fit together and why companies are adopting them.

Published in: Technology
  • Login to see the comments

Continuous Deployment with Akka.Cluster and Kubernetes (Akka.NET)

  1. 1. Continuous Deployment with Akka.Cluster and Kubernetes By Aaron Stannard, Petabridge CEO Akka.NET Co-Founder
  2. 2. What We’re Going to Learn Today • Akka.Cluster Overview • Docker & .NET Core Fundamentals • Akka.Cluster & Docker Best Practices • Kubernetes Concepts • Azure Kubernetes Service • Putting it all Together into Continuous Deployment
  3. 3. Why .NET Core? • Cross-platform • Extremely fast • Lightweight • Future of .NET • Plays well with Docker
  4. 4. Why Docker? • Ubiquitous – runs everywhere, used everywhere. • Easy, reproducible configuration format – Dockerfiles. • Composable. • Easy to share output via compiled Docker images.
  5. 5. Why Kubernetes? • Ubiquitous – runs on- premise, on the cloud, etc… • Robust deployment models – including handling for stateful apps. • Rich ecosystem.
  6. 6. Why Azure Kubernetes Service? • Takes only a few minutes to setup. • Integrates well with Azure DevOps. • Great environment for learning K8s.
  7. 7. Akka.Cluster Continuous Deployment Process
  8. 8. Demo
  9. 9. View of an Akka.NET Cluster Each node is its own ActorSystem
  10. 10. How Akka.Cluster State Gets Distributed: Routers
  11. 11. Other State Distribution Tools • Akka.Cluster.Tools – Distributed Publish-Subscribe – ClusterClient • Akka.Cluster.Sharding
  12. 12. Working with .NET Core, Akka.NET, and Docker
  13. 13. Docker Key Terms • “Image” – a compiled image containing all of the files needed to execute the process. • “Repository” – a collection of named and tagged images hosted at a specific URI. • “Container” – represents a running instance of a Docker image on a host machine. • “Host” – a machine running the Docker engine, capable of hosting 1 or more running containers.
  14. 14. DockerHub – Public Images
  15. 15. Docker Container Hosting
  16. 16. Bootstrapping Akka.Cluster • Need to program Akka.Remote to automatically listen to reachable host + port inside Docker vNet. • Need to program Akka.Cluster to contact seed nodes inside Docker vNet. • Need to program Akka.Cluster to leave cluster gracefully prior to / during container shutdown.
  17. 17. Akka.Bootstrap.Docker PackageCalls Akka.Bootstrap.Docker parser – injects runtime & environment networking values directly into HOCON prior to starting ActorSystem. 1. If CLUSTER_IP environment variable is set, that becomes netty.tcp.public-hostname. If not, then Dns.GetHostName() is used. 2. CLUSTER_PORT environment variable is used for dot-netty.tcp.port. 3. CLUSTER_SEEDS environment variable is a comma-delimited list of addresses.
  18. 18. Akka.NET Dockerfile FROM microsoft/dotnet:2.1-sdk AS base WORKDIR /app # should be a comma-delimited list ENV CLUSTER_SEEDS "[]" ENV CLUSTER_IP "" ENV CLUSTER_PORT "5213" #Akka.Remote inbound listening endpoint EXPOSE 5213 COPY ./bin/Release/netcoreapp2.1/publish/ /app # Install Petabridge.Cmd client RUN dotnet tool install --global pbm # Needed because dockerfile ENV PATH="${PATH}:/root/.dotnet/tools" # RUN pbm help CMD ["dotnet", "WebCrawler.CrawlService.dll"] Name of the base image we’re going to use. Taken from the public Microsoft .NET Core repository on DockerHub Set of environment variables expected by Akka.Bootstrap.Docker The container’s port expose to the Docker network Copy application files from host machine to container working directory Execute command inside container Container’s process entrypoint. If this process dies, the container dies.
  19. 19. Using Petabridge.Cmd Inside Docker • Provides instrumentation to managing, viewing cluster from inside Docker network. • Can be used to trigger graceful shutdowns of containers. • Secured inside container network – have to be able to access host machine to invoke pbm.
  20. 20. Docker Image Publish Process
  21. 21. Private Docker Registries • Don’t publish your company’s code onto DockerHub. • Use Azure Container Registry (ACR) or private hosts or services instead.
  22. 22. Kubernetes Core Concepts • K8s is an “orchestration” platform – networks multiple container hosts together into unified abstraction. • Applications are deployed to the K8s cluster – K8s then orchestrates the instantiation of containers across hosts. • Applications define via configuration: – Which parts can be exposed publicly and how. – How different parts of application can be deployed and managed.
  23. 23. Kubernetes Core Concepts
  24. 24. K8s Infrastructure on Azure AKS
  25. 25. K8s Key Terms (for Akka.Cluster) • “Pod” – represents a single application unit of execution. Consists of 1 or more Docker container. • “Stateful set” – a deployment group of identical pods working together as a stateful service. • “Service” – defines how a stateful set exposes itself to other services within K8s and Akka.NET cluster.
  26. 26. Akka.Cluster K8s Methodology • All applications are deployed as stateful sets – State is fundamental to how Akka.Cluster works • All internal Akka.Cluster functionality is exposed as “ClusterIp” services • External / public functionality can exposed as a “LoadBalancer” service or otherwise • Petabridge.Cmd used for node exits • Deployments / rollbacks performed by
  27. 27. K8s Stateful Set YAML File (pt1) apiVersion: apps/v1 kind: StatefulSet metadata: name: lighthouse labels: app: lighthouse spec: serviceName: lighthouse replicas: 3 selector: matchLabels: app: lighthouse template: metadata: labels: app: lighthouse spec: terminationGracePeriodSeconds: 35 containers: - name: lighthouse image: webcrawler.lighthouse:0.2.4 lifecycle: preStop: exec: command: ["/bin/sh", "-c", "pbm cluster leave"] Declares “lighthouse” stateful set Declares number of replicas in initial deployment Specifies the container name inside the pod and the Docker image used. Tells K8s to invoke this command prior to Terminating any pods in this stateful set.
  28. 28. K8s Stateful Set YAML File (pt2) env: - name: ACTORSYSTEM value: webcrawler - name: POD_NAME valueFrom: fieldRef: fieldPath: - name: CLUSTER_IP value: "$(POD_NAME).lighthouse" - name: CLUSTER_SEEDS value: akka.tcp://webcrawler@lighthouse-0.lighthouse:4053,akka.tcp://webcrawler@lighthouse- 1.lighthouse:4053,akka.tcp://webcrawler@lighthouse-2.lighthouse:4053 livenessProbe: tcpSocket: port: 4053 ports: - containerPort: 4053 protocol: TCP Populates the POD_NAME environment variable using K8s metadata at deployment time. Populates unique per-node hostname consumed by Akka.Bootstrap.Docker. Seed nodes Liveness probe. Terminates + restarts container if this check fails. Using Akka.Remote inbound port. Container port – exposed to internal K8s network.
  29. 29. K8s ClusterIP Service YAML apiVersion: v1 kind: Service metadata: name: lighthouse labels: app: lighthouse spec: clusterIP: None ports: - port: 4053 selector: app: lighthouse Exposes Lighthouse services across-hosts on their container port (4053) and host IP addresses. Not accessible outside of K8s cluster. Tells K8s that this service points to the “lighthouse” stateful set we deployed earlier.
  30. 30. Creating the Initial K8s Cluster kubectl apply –f k8s-lighthouse-service.yaml kubectl apply –f k8s-crawler-service.yaml kubectl apply –f k8s-web-service.yaml Etc…
  31. 31. Azure Kubernetes Service (AKS) • Managed K8s on top of Azure virtual machines and other resources. • Easy to setup and instrument – Azure CLI makes it easy to communicate with AKS via kubectl. – Works well with Azure DevOps. – Dev Spaces make it easy to work across multiple people & teams. • Great environment for learning K8s.
  32. 32. Akka.Cluster Continuous Deployment Process
  33. 33. Links and Further Reading • Source: • Petabridge.Cmd: • Akka.Bootstrap.Docker: • Akka.HealthCheck.Cluster: healthcheck • AKS Quickstart Tutorial: kubernetes-prepare-app • AKS + kubectl CLI Tutorial: us/azure/aks/kubernetes-walkthrough • Akka.Cluster, Docker, K8s Training Tour: