Skip to content

Commit 8496253

Browse files
m3naxWhitWaldophilliphoffshivamkm07
authored
Samples - Add k8s deployment yaml to DemoActor sample (#1308)
* up Signed-off-by: Manuel Menegazzo <[email protected]> * Fixed build Signed-off-by: Manuel Menegazzo <[email protected]> * Added scripts for image build Signed-off-by: Manuel Menegazzo <[email protected]> * Added readme Build and push Docker image Signed-off-by: Manuel Menegazzo <[email protected]> * Added demo-actor.yaml Signed-off-by: Manuel Menegazzo <[email protected]> * Fixed typo Signed-off-by: Manuel Menegazzo <[email protected]> * Updated guide, fixed invocation throw curl Signed-off-by: Manuel Menegazzo <[email protected]> * Removed dockerfile, updated readme, removed ps1 and sh scripts Signed-off-by: Manuel Menegazzo <[email protected]> * Updated base image Signed-off-by: Manuel Menegazzo <[email protected]> Signed-off-by: Manuel Menegazzo <[email protected]> * Update demo-actor.yaml Signed-off-by: Manuel Menegazzo <[email protected]> Signed-off-by: Manuel Menegazzo <[email protected]> * Added overload for DaprClient DI registration (#1289) * Added overload for DaprClient DI registration allowing the consumer to easily use values from injected services (e.g. IConfiguration). Signed-off-by: Whit Waldo <[email protected]> * Added supporting unit test Signed-off-by: Whit Waldo <[email protected]> --------- Signed-off-by: Whit Waldo <[email protected]> Co-authored-by: Phillip Hoff <[email protected]> Signed-off-by: Manuel Menegazzo <[email protected]> * Merge `release-1.13` back into `master` (#1285) * Update protos and related use for Dapr 1.13. (#1236) * Update protos and related use. Signed-off-by: Phillip Hoff <[email protected]> * Update Dapr runtime version. Signed-off-by: Phillip Hoff <[email protected]> * Init properties. Signed-off-by: Phillip Hoff <[email protected]> --------- Signed-off-by: Phillip Hoff <[email protected]> * Update artifact action versions. (#1240) Signed-off-by: Phillip Hoff <[email protected]> * Make recursive true as default (#1243) Signed-off-by: Shivam Kumar <[email protected]> * Fix for secret key transformation in multi-value scenarios (#1274) * Add repro test. Signed-off-by: Phillip Hoff <[email protected]> * Fix for secret key transformation in multi-value scenarios. Signed-off-by: Phillip Hoff <[email protected]> --------- Signed-off-by: Phillip Hoff <[email protected]> * Update Dapr version numbers used during testing. Signed-off-by: Phillip Hoff <[email protected]> --------- Signed-off-by: Phillip Hoff <[email protected]> Signed-off-by: Shivam Kumar <[email protected]> Co-authored-by: Shivam Kumar <[email protected]> Signed-off-by: Manuel Menegazzo <[email protected]> --------- Signed-off-by: Manuel Menegazzo <[email protected]> Signed-off-by: Manuel Menegazzo <[email protected]> Signed-off-by: Whit Waldo <[email protected]> Signed-off-by: Phillip Hoff <[email protected]> Signed-off-by: Shivam Kumar <[email protected]> Co-authored-by: Whit Waldo <[email protected]> Co-authored-by: Phillip Hoff <[email protected]> Co-authored-by: Shivam Kumar <[email protected]>
1 parent 512c9ea commit 8496253

File tree

5 files changed

+166
-23
lines changed

5 files changed

+166
-23
lines changed

all.sln

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ EndProject
3232
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{1BD1276E-D28A-45EA-89B1-6AD48471500D}"
3333
ProjectSection(SolutionItems) = preProject
3434
.editorconfig = .editorconfig
35+
README.md = README.md
3536
EndProjectSection
3637
EndProject
3738
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dapr.Actors.AspNetCore.Test", "test\Dapr.Actors.AspNetCore.Test\Dapr.Actors.AspNetCore.Test.csproj", "{9C1D6ABA-5EDE-4FA0-A8A9-0AB98CB74737}"
@@ -347,16 +348,3 @@ Global
347348
SolutionGuid = {65220BF2-EAE1-4CB2-AA58-EBE80768CB40}
348349
EndGlobalSection
349350
EndGlobal
350-
8-446B-AECD-DCC2CC871F73}
351-
EndGlobalSection
352-
GlobalSection(ExtensibilityGlobals) = postSolution
353-
SolutionGuid = {65220BF2-EAE1-4CB2-AA58-EBE80768CB40}
354-
EndGlobalSection
355-
EndGlobal
356-
C991940} = {DD020B34-460F-455F-8D17-CF4A949F100B}
357-
{C74FBA78-13E8-407F-A173-4555AEE41FF3} = {A7F41094-8648-446B-AECD-DCC2CC871F73}
358-
EndGlobalSection
359-
GlobalSection(ExtensibilityGlobals) = postSolution
360-
SolutionGuid = {65220BF2-EAE1-4CB2-AA58-EBE80768CB40}
361-
EndGlobalSection
362-
EndGlobal
Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

3-
<PropertyGroup>
4-
<TargetFramework>net6</TargetFramework>
5-
</PropertyGroup>
6-
7-
<ItemGroup>
8-
<ProjectReference Include="..\..\..\src\Dapr.Actors.AspNetCore\Dapr.Actors.AspNetCore.csproj" />
9-
<ProjectReference Include="..\..\..\src\Dapr.Actors\Dapr.Actors.csproj" />
10-
<ProjectReference Include="..\IDemoActor\IDemoActor.csproj" />
11-
</ItemGroup>
3+
<PropertyGroup>
4+
<TargetFramework>net6</TargetFramework>
5+
</PropertyGroup>
6+
7+
<PropertyGroup>
8+
<IsPublishable>true</IsPublishable>
9+
<EnableSdkContainerSupport>true</EnableSdkContainerSupport>
10+
<ContainerRepository>demo-actor</ContainerRepository>
11+
</PropertyGroup>
12+
13+
<ItemGroup>
14+
<ContainerEnvironmentVariable Include="ASPNETCORE_URLS" Value="http://+:8080" />
15+
<ContainerPort Include="8080" Type="tcp" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<ProjectReference Include="..\..\..\src\Dapr.Actors.AspNetCore\Dapr.Actors.AspNetCore.csproj" />
20+
<ProjectReference Include="..\..\..\src\Dapr.Actors\Dapr.Actors.csproj" />
21+
<ProjectReference Include="..\IDemoActor\IDemoActor.csproj" />
22+
</ItemGroup>
1223

1324
</Project>

examples/Actor/DemoActor/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// ------------------------------------------------------------------------
1+
// ------------------------------------------------------------------------
22
// Copyright 2021 The Dapr Authors
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
apiVersion: dapr.io/v1alpha1
2+
kind: Component
3+
metadata:
4+
name: statestore
5+
spec:
6+
type: state.in-memory
7+
version: v1
8+
metadata:
9+
- name: actorStateStore
10+
value: "true"
11+
---
12+
kind: Service
13+
apiVersion: v1
14+
metadata:
15+
name: demoactor
16+
labels:
17+
app: demoactor
18+
spec:
19+
selector:
20+
app: demoactor
21+
ports:
22+
- name: app-port
23+
protocol: TCP
24+
port: 5010
25+
targetPort: app-port
26+
- name: dapr-http
27+
protocol: TCP
28+
port: 3500
29+
targetPort: 3500
30+
type: LoadBalancer
31+
---
32+
apiVersion: apps/v1
33+
kind: Deployment
34+
metadata:
35+
name: demoactor
36+
labels:
37+
app: demoactor
38+
spec:
39+
replicas: 1
40+
selector:
41+
matchLabels:
42+
app: demoactor
43+
template:
44+
metadata:
45+
labels:
46+
app: demoactor
47+
annotations:
48+
dapr.io/enabled: "true"
49+
dapr.io/app-id: "demoactor"
50+
dapr.io/app-port: "5010"
51+
dapr.io/enable-api-logging: "true"
52+
dapr.io/sidecar-listen-addresses: "0.0.0.0"
53+
spec:
54+
containers:
55+
- name: demoactor
56+
# image: <your-docker-registry>/demo-actor:latest
57+
image: demo-actor:latest
58+
# if you are using docker desktop, you can use imagePullPolicy: Never to use local image
59+
imagePullPolicy: Never
60+
env:
61+
- name: APP_PORT
62+
value: "5010"
63+
- name: ASPNETCORE_URLS
64+
value: "http://+:5010"
65+
ports:
66+
- name: app-port
67+
containerPort: 5010

examples/Actor/README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,80 @@ On Windows:
8080
```sh
8181
curl -X POST http://127.0.0.1:3500/v1.0/actors/DemoActor/abc/method/GetData
8282
```
83+
84+
### Build and push Docker image
85+
You can build the docker image of `DemoActor` service by running the following commands in the `DemoActor` project directory:
86+
87+
``` Bash
88+
dotnet publish --os linux --arch x64 /t:PublishContainer -p ContainerImageTags='"latest"' --self-contained
89+
```
90+
91+
The build produce and image with tag `demo-actor:latest` and load it in the local registry.
92+
Now the image can be pushed to your remote Docker registry by running the following commands:
93+
94+
``` Bash
95+
# Replace <your-docker-registry> with your Docker registry
96+
docker tag demo-actor:latest <your-docker-registry>/demo-actor:latest
97+
98+
# Push the image to your Docker registry
99+
docker push <your-docker-registry>/demo-actor:latest
100+
```
101+
102+
### Deploy the Actor service to Kubernetes
103+
#### Prerequisites
104+
- A Kubernetes cluster with `kubectl` configured to access it.
105+
- Dapr v1.13+ installed on the Kubernetes cluster. Follow the instructions [here](https://docs.dapr.io/getting-started/install-dapr-kubernetes/).
106+
- A Docker registry where you pushed the `DemoActor` image.
107+
108+
#### Deploy the Actor service
109+
For quick deployment you can install dapr in dev mode using the following command:
110+
111+
``` Bash
112+
dapr init -k --dev
113+
```
114+
115+
To deploy the `DemoActor` service to Kubernetes, you can use the provided Kubernetes manifest file `demo-actor.yaml` in the `DemoActor` project directory.
116+
Before applying the manifest file, replace the image name in the manifest file with the image name you pushed to your Docker registry.
117+
118+
Part to update in `demo-actor.yaml`:
119+
``` YAML
120+
image: <your-docker-registry>/demoactor:latest
121+
```
122+
123+
To install the application in `default` namespace, run the following command:
124+
125+
``` Bash
126+
kubectl apply -f demo-actor.yaml
127+
```
128+
129+
This will deploy the `DemoActor` service to Kubernetes. You can check the status of the deployment by running:
130+
131+
``` Bash
132+
kubectl get pods -n default --watch
133+
```
134+
135+
The manifest create 2 services:
136+
137+
- `demoactor` service: The service that hosts the `DemoActor` actor.
138+
- `demoactor-dapr` service: The service that hosts the Dapr sidecar for the `DemoActor` actor.
139+
140+
### Make client calls to the deployed Actor service
141+
To make client calls to the deployed `DemoActor` service, you can use the `ActorClient` project.
142+
Before running the client, update the `DAPR_HTTP_PORT` environment variable in the `ActorClient` project directory to the port on which Dapr is running in the Kubernetes cluster.
143+
144+
On Linux, MacOS:
145+
``` Bash
146+
export DAPR_HTTP_PORT=3500
147+
```
148+
149+
Than port-forward the `DemoActor` service to your local machine:
150+
151+
``` Bash
152+
kubectl port-forward svc/demoactor 3500:3500
153+
```
154+
155+
Now you can run the client project from the `ActorClient` directory:
156+
157+
``` Bash
158+
dotnet run
159+
```

0 commit comments

Comments
 (0)