Skip to content

Commit

Permalink
Samples - Add k8s deployment yaml to DemoActor sample (#1308)
Browse files Browse the repository at this point in the history
* up

Signed-off-by: Manuel Menegazzo <manuel.menegazzo@outlook.com>

* Fixed build

Signed-off-by: Manuel Menegazzo <manuel.menegazzo@outlook.com>

* Added scripts for image build

Signed-off-by: Manuel Menegazzo <manuel.menegazzo@outlook.com>

* Added readme Build and push Docker image

Signed-off-by: Manuel Menegazzo <manuel.menegazzo@outlook.com>

* Added demo-actor.yaml

Signed-off-by: Manuel Menegazzo <manuel.menegazzo@outlook.com>

* Fixed typo

Signed-off-by: Manuel Menegazzo <manuel.menegazzo@outlook.com>

* Updated guide, fixed invocation throw curl

Signed-off-by: Manuel Menegazzo <manuel.menegazzo@outlook.com>

* Removed dockerfile, updated readme, removed ps1 and sh scripts

Signed-off-by: Manuel Menegazzo <manuel.menegazzo@outlook.com>

* Updated base image

Signed-off-by: Manuel Menegazzo <65919883+m3nax@users.noreply.github.com>
Signed-off-by: Manuel Menegazzo <manuel.menegazzo@outlook.com>

* Update demo-actor.yaml

Signed-off-by: Manuel Menegazzo <65919883+m3nax@users.noreply.github.com>
Signed-off-by: Manuel Menegazzo <manuel.menegazzo@outlook.com>

* 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 <whit.waldo@innovian.net>

* Added supporting unit test

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>

---------

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>
Co-authored-by: Phillip Hoff <phillip@orst.edu>
Signed-off-by: Manuel Menegazzo <manuel.menegazzo@outlook.com>

* 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 <phillip@orst.edu>

* Update Dapr runtime version.

Signed-off-by: Phillip Hoff <phillip@orst.edu>

* Init properties.

Signed-off-by: Phillip Hoff <phillip@orst.edu>

---------

Signed-off-by: Phillip Hoff <phillip@orst.edu>

* Update artifact action versions. (#1240)

Signed-off-by: Phillip Hoff <phillip@orst.edu>

* Make recursive true as default (#1243)

Signed-off-by: Shivam Kumar <shivamkm07@gmail.com>

* Fix for secret key transformation in multi-value scenarios (#1274)

* Add repro test.

Signed-off-by: Phillip Hoff <phillip@orst.edu>

* Fix for secret key transformation in multi-value scenarios.

Signed-off-by: Phillip Hoff <phillip@orst.edu>

---------

Signed-off-by: Phillip Hoff <phillip@orst.edu>

* Update Dapr version numbers used during testing.

Signed-off-by: Phillip Hoff <phillip@orst.edu>

---------

Signed-off-by: Phillip Hoff <phillip@orst.edu>
Signed-off-by: Shivam Kumar <shivamkm07@gmail.com>
Co-authored-by: Shivam Kumar <shivamkm07@gmail.com>
Signed-off-by: Manuel Menegazzo <manuel.menegazzo@outlook.com>

---------

Signed-off-by: Manuel Menegazzo <manuel.menegazzo@outlook.com>
Signed-off-by: Manuel Menegazzo <65919883+m3nax@users.noreply.github.com>
Signed-off-by: Whit Waldo <whit.waldo@innovian.net>
Signed-off-by: Phillip Hoff <phillip@orst.edu>
Signed-off-by: Shivam Kumar <shivamkm07@gmail.com>
Co-authored-by: Whit Waldo <whit.waldo@innovian.net>
Co-authored-by: Phillip Hoff <phillip@orst.edu>
Co-authored-by: Shivam Kumar <shivamkm07@gmail.com>
  • Loading branch information
4 people committed Jun 26, 2024
1 parent 512c9ea commit 8496253
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 23 deletions.
14 changes: 1 addition & 13 deletions all.sln
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{1BD1276E-D28A-45EA-89B1-6AD48471500D}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
README.md = README.md
EndProjectSection
EndProject
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}"
Expand Down Expand Up @@ -347,16 +348,3 @@ Global
SolutionGuid = {65220BF2-EAE1-4CB2-AA58-EBE80768CB40}
EndGlobalSection
EndGlobal
8-446B-AECD-DCC2CC871F73}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {65220BF2-EAE1-4CB2-AA58-EBE80768CB40}
EndGlobalSection
EndGlobal
C991940} = {DD020B34-460F-455F-8D17-CF4A949F100B}
{C74FBA78-13E8-407F-A173-4555AEE41FF3} = {A7F41094-8648-446B-AECD-DCC2CC871F73}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {65220BF2-EAE1-4CB2-AA58-EBE80768CB40}
EndGlobalSection
EndGlobal
29 changes: 20 additions & 9 deletions examples/Actor/DemoActor/DemoActor.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\Dapr.Actors.AspNetCore\Dapr.Actors.AspNetCore.csproj" />
<ProjectReference Include="..\..\..\src\Dapr.Actors\Dapr.Actors.csproj" />
<ProjectReference Include="..\IDemoActor\IDemoActor.csproj" />
</ItemGroup>
<PropertyGroup>
<TargetFramework>net6</TargetFramework>
</PropertyGroup>

<PropertyGroup>
<IsPublishable>true</IsPublishable>
<EnableSdkContainerSupport>true</EnableSdkContainerSupport>
<ContainerRepository>demo-actor</ContainerRepository>
</PropertyGroup>

<ItemGroup>
<ContainerEnvironmentVariable Include="ASPNETCORE_URLS" Value="http://+:8080" />
<ContainerPort Include="8080" Type="tcp" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\Dapr.Actors.AspNetCore\Dapr.Actors.AspNetCore.csproj" />
<ProjectReference Include="..\..\..\src\Dapr.Actors\Dapr.Actors.csproj" />
<ProjectReference Include="..\IDemoActor\IDemoActor.csproj" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion examples/Actor/DemoActor/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// Copyright 2021 The Dapr Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
67 changes: 67 additions & 0 deletions examples/Actor/DemoActor/demo-actor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: statestore
spec:
type: state.in-memory
version: v1
metadata:
- name: actorStateStore
value: "true"
---
kind: Service
apiVersion: v1
metadata:
name: demoactor
labels:
app: demoactor
spec:
selector:
app: demoactor
ports:
- name: app-port
protocol: TCP
port: 5010
targetPort: app-port
- name: dapr-http
protocol: TCP
port: 3500
targetPort: 3500
type: LoadBalancer
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: demoactor
labels:
app: demoactor
spec:
replicas: 1
selector:
matchLabels:
app: demoactor
template:
metadata:
labels:
app: demoactor
annotations:
dapr.io/enabled: "true"
dapr.io/app-id: "demoactor"
dapr.io/app-port: "5010"
dapr.io/enable-api-logging: "true"
dapr.io/sidecar-listen-addresses: "0.0.0.0"
spec:
containers:
- name: demoactor
# image: <your-docker-registry>/demo-actor:latest
image: demo-actor:latest
# if you are using docker desktop, you can use imagePullPolicy: Never to use local image
imagePullPolicy: Never
env:
- name: APP_PORT
value: "5010"
- name: ASPNETCORE_URLS
value: "http://+:5010"
ports:
- name: app-port
containerPort: 5010
77 changes: 77 additions & 0 deletions examples/Actor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,80 @@ On Windows:
```sh
curl -X POST http://127.0.0.1:3500/v1.0/actors/DemoActor/abc/method/GetData
```

### Build and push Docker image
You can build the docker image of `DemoActor` service by running the following commands in the `DemoActor` project directory:

``` Bash
dotnet publish --os linux --arch x64 /t:PublishContainer -p ContainerImageTags='"latest"' --self-contained
```

The build produce and image with tag `demo-actor:latest` and load it in the local registry.
Now the image can be pushed to your remote Docker registry by running the following commands:

``` Bash
# Replace <your-docker-registry> with your Docker registry
docker tag demo-actor:latest <your-docker-registry>/demo-actor:latest
# Push the image to your Docker registry
docker push <your-docker-registry>/demo-actor:latest
```

### Deploy the Actor service to Kubernetes
#### Prerequisites
- A Kubernetes cluster with `kubectl` configured to access it.
- Dapr v1.13+ installed on the Kubernetes cluster. Follow the instructions [here](https://docs.dapr.io/getting-started/install-dapr-kubernetes/).
- A Docker registry where you pushed the `DemoActor` image.

#### Deploy the Actor service
For quick deployment you can install dapr in dev mode using the following command:

``` Bash
dapr init -k --dev
```

To deploy the `DemoActor` service to Kubernetes, you can use the provided Kubernetes manifest file `demo-actor.yaml` in the `DemoActor` project directory.
Before applying the manifest file, replace the image name in the manifest file with the image name you pushed to your Docker registry.

Part to update in `demo-actor.yaml`:
``` YAML
image: <your-docker-registry>/demoactor:latest
```

To install the application in `default` namespace, run the following command:

``` Bash
kubectl apply -f demo-actor.yaml
```

This will deploy the `DemoActor` service to Kubernetes. You can check the status of the deployment by running:

``` Bash
kubectl get pods -n default --watch
```

The manifest create 2 services:

- `demoactor` service: The service that hosts the `DemoActor` actor.
- `demoactor-dapr` service: The service that hosts the Dapr sidecar for the `DemoActor` actor.

### Make client calls to the deployed Actor service
To make client calls to the deployed `DemoActor` service, you can use the `ActorClient` project.
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.

On Linux, MacOS:
``` Bash
export DAPR_HTTP_PORT=3500
```

Than port-forward the `DemoActor` service to your local machine:

``` Bash
kubectl port-forward svc/demoactor 3500:3500
```

Now you can run the client project from the `ActorClient` directory:

``` Bash
dotnet run
```

0 comments on commit 8496253

Please sign in to comment.