Skip to content

Commit

Permalink
Adding K8s service definition for the other parts of WebCrawler (#12)
Browse files Browse the repository at this point in the history
* implementing TrackerService K8s

* came up with a better way to encode CLUSTER_IP into Lighthouse and Tracker

* Added K8s YAML file for WebCrawler

* fixed issue with lighthouse YAML

* cluster fully forms on K8s
  • Loading branch information
Aaronontheweb authored Feb 7, 2019
1 parent 556e123 commit f2b419a
Show file tree
Hide file tree
Showing 18 changed files with 239 additions and 18 deletions.
3 changes: 3 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#### 0.2.1 Feb 07 2019 ####
* Made it possible to invoke `CoordinatedShutdown` automatically via the `AppDomain.CurrentDomain.ProcessExit` event in .NET Core on `TrackerService`, `Lighthouse`, `CrawlerService`, and the `Web` application.

#### 0.2.0 Feb 06 2019 ####
Upgraded to .NET Core 2.1 for all services.

Expand Down
7 changes: 7 additions & 0 deletions src/Lighthouse/Program.NetCore.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;

namespace Lighthouse
{
Expand All @@ -9,6 +10,12 @@ public static void Main(string[] args)
var lighthouseService = new LighthouseService();
lighthouseService.Start();
Console.WriteLine("Press Control + C to terminate.");

AppDomain.CurrentDomain.ProcessExit += async (sender, eventArgs) =>
{
await lighthouseService.StopAsync();
};

Console.CancelKeyPress += async (sender, eventArgs) =>
{
await lighthouseService.StopAsync();
Expand Down
1 change: 1 addition & 0 deletions src/Lighthouse/akka.hocon
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ petabridge.cmd{
}

akka {
coordinated-shutdown.exit-clr = on
actor {
provider = cluster
}
Expand Down
4 changes: 2 additions & 2 deletions src/WebCrawler.CrawlService/CrawlerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public bool Start()
return true;
}

public Task Stop()
public async Task Stop()
{
return CoordinatedShutdown.Get(ClusterSystem).Run(CoordinatedShutdown.ClrExitReason.Instance);
await CoordinatedShutdown.Get(ClusterSystem).Run(CoordinatedShutdown.ClrExitReason.Instance);
}
}
}
9 changes: 8 additions & 1 deletion src/WebCrawler.CrawlService/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM microsoft/dotnet:2.1-runtime AS base
FROM microsoft/dotnet:2.1-sdk AS base
WORKDIR /app

# should be a comma-delimited list
Expand All @@ -11,5 +11,12 @@ 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"]
9 changes: 7 additions & 2 deletions src/WebCrawler.CrawlService/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ static void Main(string[] args)
var crawlerService = new CrawlerService();
crawlerService.Start();

Console.CancelKeyPress += (sender, eventArgs) =>
AppDomain.CurrentDomain.ProcessExit += (sender, eventArgs) =>
{
crawlerService.Stop();
crawlerService.Stop().Wait(TimeSpan.FromSeconds(30));
};

Console.CancelKeyPress += async (sender, eventArgs) =>
{
await crawlerService.Stop();
eventArgs.Cancel = true;
};

Expand Down
1 change: 1 addition & 0 deletions src/WebCrawler.CrawlService/WebCrawler.CrawlService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<PackageReference Include="Akka.Bootstrap.Docker" Version="$(AkkaBootstrapVersion)" />
<PackageReference Include="Akka.Cluster" Version="$(AkkaVersion)" />
<PackageReference Include="Akka.Cluster.HealthCheck" Version="$(AkkaHealthCheckVersion)" />
<PackageReference Include="Petabridge.Cmd.Cluster" Version="$(PetabridgeCmdVersion)" />
</ItemGroup>

<ItemGroup>
Expand Down
10 changes: 9 additions & 1 deletion src/WebCrawler.TrackerService/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM microsoft/dotnet:2.1-runtime AS base
FROM microsoft/dotnet:2.1-sdk AS base
WORKDIR /app

# should be a comma-delimited list
Expand All @@ -11,4 +11,12 @@ EXPOSE 5212

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.TrackerService.dll"]
9 changes: 7 additions & 2 deletions src/WebCrawler.TrackerService/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ private static void Main(string[] args)
var trackingService = new TrackerService();
trackingService.Start();

Console.CancelKeyPress += (sender, eventArgs) =>
AppDomain.CurrentDomain.ProcessExit += (sender, eventArgs) =>
{
trackingService.Stop();
trackingService.Stop().Wait(TimeSpan.FromSeconds(30));
};

Console.CancelKeyPress += async (sender, eventArgs) =>
{
await trackingService.Stop();
eventArgs.Cancel = true;
};

Expand Down
4 changes: 2 additions & 2 deletions src/WebCrawler.TrackerService/TrackerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public bool Start()
return true;
}

public Task Stop()
public async Task Stop()
{
return CoordinatedShutdown.Get(ClusterSystem).Run();
await CoordinatedShutdown.Get(ClusterSystem).Run(CoordinatedShutdown.ClrExitReason.Instance);
}
}
}
2 changes: 1 addition & 1 deletion src/WebCrawler.Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static void Main(string[] args)

Console.CancelKeyPress += async (sender, eventArgs) =>
{
var wait = CoordinatedShutdown.Get(SystemActors.ActorSystem).Run();
var wait = CoordinatedShutdown.Get(SystemActors.ActorSystem).Run(CoordinatedShutdown.ClrExitReason.Instance);
await host.StopAsync(TimeSpan.FromSeconds(10));
await wait;
};
Expand Down
4 changes: 2 additions & 2 deletions src/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<PropertyGroup>
<Copyright>Copyright © 2015-2019 Petabridge, LLC</Copyright>
<Authors>Petabridge</Authors>
<VersionPrefix>0.2.0</VersionPrefix>
<PackageReleaseNotes>Upgraded to .NET Core 2.1 for all services.</PackageReleaseNotes>
<VersionPrefix>0.2.1</VersionPrefix>
<PackageReleaseNotes>Made it possible to invoke `CoordinatedShutdown` automatically via the `AppDomain.CurrentDomain.ProcessExit` event in .NET Core on `TrackerService`, `Lighthouse`, `CrawlerService`, and the `Web` application.</PackageReleaseNotes>
<PackageIconUrl>
</PackageIconUrl>
<PackageProjectUrl>
Expand Down
14 changes: 14 additions & 0 deletions yaml/k8s-aws-web-loadbalancer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: Service
metadata:
name: web-cluster-http
labels:
app: web-cluster
spec:
type: LoadBalancer
ports:
- protocol: TCP
port: 80
targetPort: 9376
selector:
app: web-cluster
49 changes: 49 additions & 0 deletions yaml/k8s-crawler-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
apiVersion: v1
kind: Service
metadata:
name: crawler
labels:
app: crawler
spec:
clusterIP: None
ports:
- port: 5213
selector:
app: crawler
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: crawler
labels:
app: crawler
spec:
serviceName: crawler
replicas: 3
selector:
matchLabels:
app: crawler
template:
metadata:
labels:
app: crawler
spec:
terminationGracePeriodSeconds: 35
containers:
- name: crawler
image: webcrawler.crawlservice:0.2.1
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: CLUSTER_IP
value: "$(POD_NAME).crawler"
- 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: 5213
ports:
- containerPort: 5213
protocol: TCP
12 changes: 7 additions & 5 deletions yaml/k8s-lighthouse-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,22 @@ spec:
terminationGracePeriodSeconds: 35
containers:
- name: lighthouse
image: webcrawler.lighthouse:0.2.0
preStop:
exec:
command: ["/bin/sh", "-c", "pbm 127.0.0.1:9110 cluster leave"]
image: webcrawler.lighthouse:0.2.1
lifecycle:
preStop:
exec:
command: ["/bin/sh", "-c", "pbm 127.0.0.1:9110 cluster leave"]
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
command: [ "/bin/sh", "-c", "CLUSTER_IP=${POD_NAME}.lighthouse dotnet Lighthouse.dll"]
livenessProbe:
tcpSocket:
port: 4053
Expand Down
16 changes: 16 additions & 0 deletions yaml/k8s-local-web-nodeport.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: Service
metadata:
name: web-cluster-http
labels:
app: web-cluster
tier: frontend
spec:
type: LoadBalancer
ports:
- nodePort: 31231
protocol: TCP
port: 80
targetPort: 80
selector:
app: web-cluster
49 changes: 49 additions & 0 deletions yaml/k8s-tracker-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
apiVersion: v1
kind: Service
metadata:
name: tracker
labels:
app: tracker
spec:
clusterIP: None
ports:
- port: 5212
selector:
app: tracker
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: tracker
labels:
app: tracker
spec:
serviceName: tracker
replicas: 3
selector:
matchLabels:
app: tracker
template:
metadata:
labels:
app: tracker
spec:
terminationGracePeriodSeconds: 35
containers:
- name: tracker
image: webcrawler.trackerservice:0.2.1
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: CLUSTER_IP
value: "$(POD_NAME).tracker"
- 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: 5212
ports:
- containerPort: 5212
protocol: TCP
54 changes: 54 additions & 0 deletions yaml/k8s-web-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
apiVersion: v1
kind: Service
metadata:
name: web-cluster
labels:
app: web-cluster
spec:
clusterIP: None
ports:
- port: 16666
selector:
app: web-cluster
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: web-cluster
labels:
app: web-cluster
spec:
serviceName: web-cluster
replicas: 3
selector:
matchLabels:
app: web-cluster
template:
metadata:
labels:
app: web-cluster
spec:
terminationGracePeriodSeconds: 35
containers:
- name: web-cluster
image: webcrawler.web:0.2.1
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: CLUSTER_IP
value: "$(POD_NAME).web-cluster"
- 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: 16666
readinessProbe:
tcpSocket:
port: 80
ports:
- containerPort: 16666
protocol: TCP
- containerPort: 80
protocol: TCP

0 comments on commit f2b419a

Please sign in to comment.