9.1 KiB
type | title | linkTitle | weight | description | type |
---|---|---|---|---|---|
docs | How-To: Setup Dapr environment | How-To: Setup environment | 20 | Setup Dapr in a local environment or in a Kubernetes cluster | docs |
Dapr can be run in either self hosted or Kubernetes modes. Running Dapr runtime in self hosted mode enables you to develop Dapr applications in your local development environment and then deploy and run them in other Dapr supported environments. For example, you can develop Dapr applications in self hosted mode and then deploy them to any Kubernetes cluster.
Prerequisites
On default Dapr will install with a developer environment using Docker containers to get you started easily. However, Dapr does not depend on Docker to run (see here for instructions on installing Dapr locally without Docker using slim init). This getting started guide assumes Dapr is installed along with this developer environment.
- Install Docker
For Windows user, ensure that
Docker Desktop For Windows
uses Linux containers.
Install the Dapr CLI
{{< tabs Windows Linux MacOS Binaries>}}
{{% codetab %}}
This command will install the latest windows Dapr cli to c:\dapr
and add this directory to User PATH environment variable:
powershell -Command "iwr -useb https://raw.githubusercontent.com/dapr/cli/master/install/install.ps1 | iex"
{{% /codetab %}}
{{% codetab %}}
This command will install the latest linux Dapr CLI to /usr/local/bin
:
wget -q https://raw.githubusercontent.com/dapr/cli/master/install/install.sh -O - | /bin/bash
{{% /codetab %}}
{{% codetab %}}
This command will install the latest darwin Dapr CLI to /usr/local/bin
:
curl -fsSL https://raw.githubusercontent.com/dapr/cli/master/install/install.sh | /bin/bash
Or you can install via Homebrew:
brew install dapr/tap/dapr-cli
{{% /codetab %}}
{{% codetab %}} Each release of Dapr CLI includes various OSes and architectures. These binary versions can be manually downloaded and installed.
- Download the desired Dapr CLI from the latest Dapr Release
- Unpack it (e.g. dapr_linux_amd64.tar.gz, dapr_windows_amd64.zip)
- Move it to your desired location.
- For Linux/MacOS -
/usr/local/bin
- For Windows, create a directory and add this to your System PATH. For example create a directory called
c:\dapr
and add this directory to your path, by editing your system environment variable. {{% /codetab %}} {{< /tabs >}}
- For Linux/MacOS -
Installing Dapr in self hosted mode
Initialize Dapr using the CLI
On default, during initialization the Dapr CLI will install the Dapr binaries as well as setup a developer environment to help you get started easily with Dapr. This environment uses Docker containers, therefore Docker is listed as a prerequisite.
If you prefer to run Dapr without this environment and no dependency on Docker, see the CLI documentation for usage of the
--slim
flag with the init CLI command here. Note, if you are a new user, it is strongly recommended to intall Docker and use the regular init command.
For Linux users, if you run your docker cmds with sudo or the install path is
/usr/local/bin
(default install path), you need to use "sudo dapr init" For Windows users, make sure that you run the cmd terminal in administrator mode Note: See Dapr CLI for details on the usage of Dapr CLI
$ dapr init
⌛ Making the jump to hyperspace...
Downloading binaries and setting up components
✅ Success! Dapr is up and running. To get started, go here: https://aka.ms/dapr-getting-started
To see that Dapr has been installed successfully, from a command prompt run the docker ps
command and check that the daprio/dapr:latest
and redis
container images are both running.
Install a specific runtime version
You can install or upgrade to a specific version of the Dapr runtime using dapr init --runtime-version
. You can find the list of versions in Dapr Release.
# Install v0.1.0 runtime
$ dapr init --runtime-version 0.1.0
# Check the versions of cli and runtime
$ dapr --version
cli version: v0.1.0
runtime version: v0.1.0
Uninstall Dapr in a self hosted mode
Uninstalling removes the Placement service container or the Placement service binary.
$ dapr uninstall
For Linux users, if you run your docker cmds with sudo or the install path is
/usr/local/bin
(default install path), you need to use "sudo dapr uninstall" to remove dapr binaries and/or the containers.
It won't remove the Redis or Zipkin containers by default in case you were using them for other purposes. To remove Redis, Zipkin and actor Placement container as well as remove the default Dapr dir located at $HOME/.dapr
or %USERPROFILE%\.dapr\
run:
$ dapr uninstall --all
You should always run dapr uninstall
before running another dapr init
.
Installing Dapr on a Kubernetes cluster
When setting up Kubernetes, you can do this either via the Dapr CLI or Helm.
Dapr installs the following pods:
- dapr-operator: Manages component updates and kubernetes services endpoints for Dapr (state stores, pub-subs, etc.)
- dapr-sidecar-injector: Injects Dapr into annotated deployment pods
- dapr-placement: Used for actors only. Creates mapping tables that map actor instances to pods
- dapr-sentry: Manages mTLS between services and acts as a certificate authority
Setup Cluster
You can install Dapr on any Kubernetes cluster. Here are some helpful links:
- [Setup Minikube Cluster]({{< ref setup-minikube.md >}})
- [Setup Azure Kubernetes Service Cluster]({{< ref setup-aks.md >}})
- Setup Google Cloud Kubernetes Engine
- Setup Amazon Elastic Kubernetes Service
Note: Both the Dapr CLI, and the Dapr Helm chart automatically deploy with affinity for nodes with the label
kubernetes.io/os=linux
. You can deploy Dapr to Windows nodes, but most users should not need to. For more information see [Deploying to a Hybrid Linux/Windows K8s Cluster]({{< ref kubernetes-hybrid-clusters >}})
Using the Dapr CLI
You can install Dapr to a Kubernetes cluster using CLI.
Install Dapr to Kubernetes
Note: The default namespace is dapr-system
$ dapr init -k
⌛ Making the jump to hyperspace...
ℹ️ Note: To install Dapr using Helm, see here: https://github.com/dapr/docs/blob/master/getting-started/environment-setup.md#using-helm-advanced
✅ Deploying the Dapr control plane to your cluster...
✅ Success! Dapr has been installed to namespace dapr-system. To verify, run "dapr status -k" in your terminal. To get started, go here: https://aka.ms/dapr-getting-started
Install to a custom namespace:
dapr init -k -n mynamespace
Installing in highly available mode:
dapr init -k --enable-ha=true
Disable mTLS:
dapr init -k --enable-mtls=false
Uninstall Dapr on Kubernetes
$ dapr uninstall --kubernetes
Using Helm (Advanced)
You can install Dapr to Kubernetes cluster using a Helm 3 chart.
Note: The latest Dapr helm chart no longer supports Helm v2. Please migrate from helm v2 to helm v3 by following this guide.
Install Dapr to Kubernetes
-
Make sure Helm 3 is installed on your machine
-
Add Azure Container Registry as a Helm repo
helm repo add dapr https://dapr.github.io/helm-charts/
helm repo update
- Create
dapr-system
namespace on your kubernetes cluster
kubectl create namespace dapr-system
- Install the Dapr chart on your cluster in the
dapr-system
namespace.
helm install dapr dapr/dapr --namespace dapr-system
Verify installation
Once the chart installation is complete, verify the dapr-operator, dapr-placement, dapr-sidecar-injector and dapr-sentry pods are running in the dapr-system
namespace:
$ kubectl get pods -n dapr-system -w
NAME READY STATUS RESTARTS AGE
dapr-operator-7bd6cbf5bf-xglsr 1/1 Running 0 40s
dapr-placement-7f8f76778f-6vhl2 1/1 Running 0 40s
dapr-sidecar-injector-8555576b6f-29cqm 1/1 Running 0 40s
dapr-sentry-9435776c7f-8f7yd 1/1 Running 0 40s
Sidecar annotations
To see all the supported annotations for the Dapr sidecar on Kubernetes, visit [this]({{< ref kubernetes >}}) guide.
Uninstall Dapr on Kubernetes
Helm 3
helm uninstall dapr -n dapr-system
Note: See here for details on Dapr helm charts.
Installing Redis on Kubernetes
To install Redis as a state store or as a pub/sub message bus into your Kubernetes cluster. See [Configure Redis for state management or pub/sub]({{< ref setup-redis-pubsub.md >}})