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.
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. Why .NET Core?
• Cross-platform
• Extremely fast
• Lightweight
• Future of .NET
• Plays well with
Docker
4. Why Docker?
• Ubiquitous – runs
everywhere, used
everywhere.
• Easy, reproducible
configuration format –
Dockerfiles.
• Composable.
• Easy to share output
via compiled Docker
images.
5. Why Kubernetes?
• Ubiquitous – runs on-
premise, on the cloud,
etc…
• Robust deployment
models – including
handling for stateful
apps.
• Rich ecosystem.
6. Why Azure Kubernetes
Service?
• Takes only a few
minutes to setup.
• Integrates well with
Azure DevOps.
• Great environment for
learning K8s.
20. 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.
23. 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.
24. 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 akka.remote.dot-
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.
25. 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 https://stackoverflow.com/questions/51977474/install-dotnet-core-tool-
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.
26. 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.
28. Private Docker Registries
• Don’t publish your company’s code onto
DockerHub.
• Use Azure Container Registry (ACR) or
private hosts or services instead.
29. 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.
32. 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.
33.
34. 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
35. 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 127.0.0.1:9110 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.
36. K8s Stateful Set YAML File (pt2)
env:
- name: ACTORSYSTEM
value: webcrawler
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- 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.
37. 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.
39. 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.