This is the multi-page printable view of this section. Click here to print.
Multi-App Run
1 - Multi-App Run overview
Note
Multi-App Run for Kubernetes is currently a preview feature.Let’s say you want to run several applications locally to test them together, similar to a production scenario. Multi-App Run allows you to start and stop a set of applications simultaneously, either:
- Locally/self-hosted with processes, or
- By building container images and deploying to a Kubernetes cluster
- You can use a local Kubernetes cluster (KiND) or one deploy to a Cloud (AKS, EKS, and GKE).
The Multi-App Run template file describes how to start multiple applications as if you had run many separate CLI run
commands. By default, this template file is called dapr.yaml
.
Multi-App Run template file
When you execute dapr run -f .
, it starts the multi-app template file (named dapr.yaml
) present in the current directory to run all the applications.
You can name template file with preferred name other than the default. For example dapr run -f ./<your-preferred-file-name>.yaml
.
The following example includes some of the template properties you can customize for your applications. In the example, you can simultaneously launch 2 applications with app IDs of processor
and emit-metrics
.
version: 1
apps:
- appID: processor
appDirPath: ../apps/processor/
appPort: 9081
daprHTTPPort: 3510
command: ["go","run", "app.go"]
- appID: emit-metrics
appDirPath: ../apps/emit-metrics/
daprHTTPPort: 3511
env:
DAPR_HOST_ADD: localhost
command: ["go","run", "app.go"]
For a more in-depth example and explanation of the template properties, see Multi-app template.
Locations for resources and configuration files
You have options on where to place your applications’ resources and configuration files when using Multi-App Run.
Point to one file location (with convention)
You can set all of your applications resources and configurations at the ~/.dapr
root. This is helpful when all applications share the same resources path, like when testing on a local machine.
Separate file locations for each application (with convention)
When using Multi-App Run, each application directory can have a .dapr
folder, which contains a config.yaml
file and a resources
directory. Otherwise, if the .dapr
directory is not present within the app directory, the default ~/.dapr/resources/
and ~/.dapr/config.yaml
locations are used.
If you decide to add a .dapr
directory in each application directory, with a /resources
directory and config.yaml
file, you can specify different resources paths for each application. This approach remains within convention by using the default ~/.dapr
.
Point to separate locations (custom)
You can also name each app directory’s .dapr
directory something other than .dapr
, such as, webapp
, or backend
. This helps if you’d like to be explicit about resource or application directory paths.
Logs
The run template provides two log destination fields for each application and its associated daprd process:
appLogDestination
: This field configures the log destination for the application. The possible values areconsole
,file
andfileAndConsole
. The default value isfileAndConsole
where application logs are written to both console and to a file by default.daprdLogDestination
: This field configures the log destination for thedaprd
process. The possible values areconsole
,file
andfileAndConsole
. The default value isfile
where thedaprd
logs are written to a file by default.
Log file format
Logs for application and daprd
are captured in separate files. These log files are created automatically under .dapr/logs
directory under each application directory (appDirPath
in the template). These log file names follow the pattern seen below:
<appID>_app_<timestamp>.log
(file name format forapp
log)<appID>_daprd_<timestamp>.log
(file name format fordaprd
log)
Even if you’ve decided to rename your resources folder to something other than .dapr
, the log files are written only to the .dapr/logs
folder (created in the application directory).
Watch the demo
Multi-App Run template file
When you execute dapr run -k -f .
or dapr run -k -f dapr.yaml
, the applications defined in the dapr.yaml
Multi-App Run template file starts in Kubernetes default namespace.
Note: Currently, the Multi-App Run template can only start applications in the default Kubernetes namespace.
The necessary default service and deployment definitions for Kubernetes are generated within the .dapr/deploy
folder for each app in the dapr.yaml
template.
If the createService
field is set to true
in the dapr.yaml
template for an app, then the service.yaml
file is generated in the .dapr/deploy
folder of the app.
Otherwise, only the deployment.yaml
file is generated for each app that has the containerImage
field set.
The files service.yaml
and deployment.yaml
are used to deploy the applications in default
namespace in Kubernetes. This feature is specifically targeted only for running multiple apps in a dev/test environment in Kubernetes.
You can name the template file with any preferred name other than the default. For example:
dapr run -k -f ./<your-preferred-file-name>.yaml
The following example includes some of the template properties you can customize for your applications. In the example, you can simultaneously launch 2 applications with app IDs of nodeapp
and pythonapp
.
version: 1
common:
apps:
- appID: nodeapp
appDirPath: ./nodeapp/
appPort: 3000
containerImage: ghcr.io/dapr/samples/hello-k8s-node:latest
containerImagePullPolicy: Always
createService: true
env:
APP_PORT: 3000
- appID: pythonapp
appDirPath: ./pythonapp/
containerImage: ghcr.io/dapr/samples/hello-k8s-python:latest
Note:
- If the
containerImage
field is not specified,dapr run -k -f
produces an error.- The containerImagePullPolicy indicates that a new container image is always downloaded for this app.
- The
createService
field defines a basic service in Kubernetes (ClusterIP or LoadBalancer) that targets the--app-port
specified in the template. IfcreateService
isn’t specified, the application is not accessible from outside the cluster.
For a more in-depth example and explanation of the template properties, see Multi-app template.
Logs
The run template provides two log destination fields for each application and its associated daprd process:
appLogDestination
: This field configures the log destination for the application. The possible values areconsole
,file
andfileAndConsole
. The default value isfileAndConsole
where application logs are written to both console and to a file by default.daprdLogDestination
: This field configures the log destination for thedaprd
process. The possible values areconsole
,file
andfileAndConsole
. The default value isfile
where thedaprd
logs are written to a file by default.
Log file format
Logs for application and daprd
are captured in separate files. These log files are created automatically under .dapr/logs
directory under each application directory (appDirPath
in the template). These log file names follow the pattern seen below:
<appID>_app_<timestamp>.log
(file name format forapp
log)<appID>_daprd_<timestamp>.log
(file name format fordaprd
log)
Even if you’ve decided to rename your resources folder to something other than .dapr
, the log files are written only to the .dapr/logs
folder (created in the application directory).
Watch the demo
Watch this video for an overview on Multi-App Run in Kubernetes:
Next steps
2 - How to: Use the Multi-App Run template file
Note
Multi-App Run for Kubernetes is currently a preview feature.The Multi-App Run template file is a YAML file that you can use to run multiple applications at once. In this guide, you’ll learn how to:
- Use the multi-app template
- View started applications
- Stop the multi-app template
- Structure the multi-app template file
Use the multi-app template
You can use the multi-app template file in one of the following two ways:
Execute by providing a directory path
When you provide a directory path, the CLI will try to locate the Multi-App Run template file, named dapr.yaml
by default in the directory. If the file is not found, the CLI will return an error.
Execute the following CLI command to read the Multi-App Run template file, named dapr.yaml
by default:
# the template file needs to be called `dapr.yaml` by default if a directory path is given
dapr run -f <dir_path>
dapr run -f <dir_path> -k
Execute by providing a file path
If the Multi-App Run template file is named something other than dapr.yaml
, then you can provide the relative or absolute file path to the command:
dapr run -f ./path/to/<your-preferred-file-name>.yaml
dapr run -f ./path/to/<your-preferred-file-name>.yaml -k
View the started applications
Once the multi-app template is running, you can view the started applications with the following command:
dapr list
dapr list -k
Stop the multi-app template
Stop the multi-app run template anytime with either of the following commands:
# the template file needs to be called `dapr.yaml` by default if a directory path is given
dapr stop -f <dir_path>
or:
dapr stop -f ./path/to/<your-preferred-file-name>.yaml
# the template file needs to be called `dapr.yaml` by default if a directory path is given
dapr stop -f <dir_path> -k
or:
dapr stop -f ./path/to/<your-preferred-file-name>.yaml -k
Template file structure
The Multi-App Run template file can include the following properties. Below is an example template showing two applications that are configured with some of the properties.
version: 1
common: # optional section for variables shared across apps
resourcesPath: ./app/components # any dapr resources to be shared across apps
env: # any environment variable shared across apps
DEBUG: true
apps:
- appID: webapp # optional
appDirPath: .dapr/webapp/ # REQUIRED
resourcesPath: .dapr/resources # deprecated
resourcesPaths: .dapr/resources # comma separated resources paths. (optional) can be left to default value by convention.
appChannelAddress: 127.0.0.1 # network address where the app listens on. (optional) can be left to default value by convention.
configFilePath: .dapr/config.yaml # (optional) can be default by convention too, ignore if file is not found.
appProtocol: http
appPort: 8080
appHealthCheckPath: "/healthz"
command: ["python3", "app.py"]
appLogDestination: file # (optional), can be file, console or fileAndConsole. default is fileAndConsole.
daprdLogDestination: file # (optional), can be file, console or fileAndConsole. default is file.
- appID: backend # optional
appDirPath: .dapr/backend/ # REQUIRED
appProtocol: grpc
appPort: 3000
unixDomainSocket: "/tmp/test-socket"
env:
DEBUG: false
command: ["./backend"]
The following rules apply for all the paths present in the template file:
- If the path is absolute, it is used as is.
- All relative paths under common section should be provided relative to the template file path.
appDirPath
under apps section should be provided relative to the template file path.- All other relative paths under apps section should be provided relative to the
appDirPath
.
version: 1
common: # optional section for variables shared across apps
env: # any environment variable shared across apps
DEBUG: true
apps:
- appID: webapp # optional
appDirPath: .dapr/webapp/ # REQUIRED
appChannelAddress: 127.0.0.1 # network address where the app listens on. (optional) can be left to default value by convention.
appProtocol: http
appPort: 8080
appHealthCheckPath: "/healthz"
appLogDestination: file # (optional), can be file, console or fileAndConsole. default is fileAndConsole.
daprdLogDestination: file # (optional), can be file, console or fileAndConsole. default is file.
containerImage: ghcr.io/dapr/samples/hello-k8s-node:latest # (optional) URI of the container image to be used when deploying to Kubernetes dev/test environment.
containerImagePullPolicy: IfNotPresent # (optional), the container image is downloaded if one is not present locally, otherwise the local one is used.
createService: true # (optional) Create a Kubernetes service for the application when deploying to dev/test environment.
- appID: backend # optional
appDirPath: .dapr/backend/ # REQUIRED
appProtocol: grpc
appPort: 3000
unixDomainSocket: "/tmp/test-socket"
env:
DEBUG: false
The following rules apply for all the paths present in the template file:
- If the path is absolute, it is used as is.
appDirPath
under apps section should be provided relative to the template file path.- All relative paths under app section should be provided relative to the
appDirPath
.
Template properties
The properties for the Multi-App Run template align with the dapr run
CLI flags, listed in the CLI reference documentation.
Properties | Required | Details | Example |
---|---|---|---|
appDirPath | Y | Path to the your application code | ./webapp/ , ./backend/ |
appID | N | Application’s app ID. If not provided, will be derived from appDirPath | webapp , backend |
resourcesPath | N | Deprecated. Path to your Dapr resources. Can be default value by convention | ./app/components , ./webapp/components |
resourcesPaths | N | Comma separated paths to your Dapr resources. Can be default value by convention | ./app/components , ./webapp/components |
appChannelAddress | N | The network address the application listens on. Can be left to the default value by convention. | 127.0.0.1 |
configFilePath | N | Path to your application’s configuration file | ./webapp/config.yaml |
appProtocol | N | The protocol Dapr uses to talk to the application. | http , grpc |
appPort | N | The port your application is listening on | 8080 , 3000 |
daprHTTPPort | N | Dapr HTTP port | |
daprGRPCPort | N | Dapr GRPC port | |
daprInternalGRPCPort | N | gRPC port for the Dapr Internal API to listen on; used when parsing the value from a local DNS component | |
metricsPort | N | The port that Dapr sends its metrics information to | |
unixDomainSocket | N | Path to a unix domain socket dir mount. If specified, communication with the Dapr sidecar uses unix domain sockets for lower latency and greater throughput when compared to using TCP ports. Not available on Windows. | /tmp/test-socket |
profilePort | N | The port for the profile server to listen on | |
enableProfiling | N | Enable profiling via an HTTP endpoint | |
apiListenAddresses | N | Dapr API listen addresses | |
logLevel | N | The log verbosity. | |
appMaxConcurrency | N | The concurrency level of the application; default is unlimited | |
placementHostAddress | N | Comma separated list of addresses for Dapr placement servers | 127.0.0.1:50057,127.0.0.1:50058 |
schedulerHostAddress | N | Dapr Scheduler Service host address | localhost:50006 |
appSSL | N | Enable https when Dapr invokes the application | |
maxBodySize | N | Max size of the request body in MB. Set the value using size units (e.g., 16Mi for 16MB). The default is 4Mi | |
readBufferSize | N | Max size of the HTTP read buffer in KB. This also limits the maximum size of HTTP headers. Set the value using size units, for example 32Ki will support headers up to 32KB . Default is 4Ki for 4KB | |
enableAppHealthCheck | N | Enable the app health check on the application | true , false |
appHealthCheckPath | N | Path to the health check file | /healthz |
appHealthProbeInterval | N | Interval to probe for the health of the app in seconds | |
appHealthProbeTimeout | N | Timeout for app health probes in milliseconds | |
appHealthThreshold | N | Number of consecutive failures for the app to be considered unhealthy | |
enableApiLogging | N | Enable the logging of all API calls from application to Dapr | |
runtimePath | N | Dapr runtime install path | |
env | N | Map to environment variable; environment variables applied per application will overwrite environment variables shared across applications | DEBUG , DAPR_HOST_ADD |
appLogDestination | N | Log destination for outputting app logs; Its value can be file, console or fileAndConsole. Default is fileAndConsole | file , console , fileAndConsole |
daprdLogDestination | N | Log destination for outputting daprd logs; Its value can be file, console or fileAndConsole. Default is file | file , console , fileAndConsole |
Next steps
The properties for the Multi-App Run template align with the dapr run -k
CLI flags, listed in the CLI reference documentation.
Properties | Required | Details | Example |
---|---|---|---|
appDirPath | Y | Path to the your application code | ./webapp/ , ./backend/ |
appID | N | Application’s app ID. If not provided, will be derived from appDirPath | webapp , backend |
appChannelAddress | N | The network address the application listens on. Can be left to the default value by convention. | 127.0.0 , localhost |
appProtocol | N | The protocol Dapr uses to talk to the application. | http , grpc |
appPort | N | The port your application is listening on | 8080 , 3000 |
daprHTTPPort | N | Dapr HTTP port | |
daprGRPCPort | N | Dapr GRPC port | |
daprInternalGRPCPort | N | gRPC port for the Dapr Internal API to listen on; used when parsing the value from a local DNS component | |
metricsPort | N | The port that Dapr sends its metrics information to | |
unixDomainSocket | N | Path to a unix domain socket dir mount. If specified, communication with the Dapr sidecar uses unix domain sockets for lower latency and greater throughput when compared to using TCP ports. Not available on Windows. | /tmp/test-socket |
profilePort | N | The port for the profile server to listen on | |
enableProfiling | N | Enable profiling via an HTTP endpoint | |
apiListenAddresses | N | Dapr API listen addresses | |
logLevel | N | The log verbosity. | |
appMaxConcurrency | N | The concurrency level of the application; default is unlimited | |
placementHostAddress | N | Comma separated list of addresses for Dapr placement servers | 127.0.0.1:50057,127.0.0.1:50058 |
schedulerHostAddress | N | Dapr Scheduler Service host address | 127.0.0.1:50006 |
appSSL | N | Enable HTTPS when Dapr invokes the application | |
maxBodySize | N | Max size of the request body in MB. Set the value using size units (e.g., 16Mi for 16MB). The default is 4Mi | 16Mi |
readBufferSize | N | Max size of the HTTP read buffer in KB. This also limits the maximum size of HTTP headers. Set the value using size units, for example 32Ki will support headers up to 32KB . Default is 4Ki for 4KB | 32Ki |
enableAppHealthCheck | N | Enable the app health check on the application | true , false |
appHealthCheckPath | N | Path to the health check file | /healthz |
appHealthProbeInterval | N | Interval to probe for the health of the app in seconds | |
appHealthProbeTimeout | N | Timeout for app health probes in milliseconds | |
appHealthThreshold | N | Number of consecutive failures for the app to be considered unhealthy | |
enableApiLogging | N | Enable the logging of all API calls from application to Dapr | |
env | N | Map to environment variable; environment variables applied per application will overwrite environment variables shared across applications | DEBUG , DAPR_HOST_ADD |
appLogDestination | N | Log destination for outputting app logs; Its value can be file, console or fileAndConsole. Default is fileAndConsole | file , console , fileAndConsole |
daprdLogDestination | N | Log destination for outputting daprd logs; Its value can be file, console or fileAndConsole. Default is file | file , console , fileAndConsole |
containerImage | N | URI of the container image to be used when deploying to Kubernetes dev/test environment. | ghcr.io/dapr/samples/hello-k8s-python:latest |
containerImagePullPolicy | N | The container image pull policy (default to Always ). | Always , IfNotPresent , Never |
createService | N | Create a Kubernetes service for the application when deploying to dev/test environment. | true , false |
Next steps
Watch this video for an overview on Multi-App Run in Kubernetes: