Deploy Dapr on a Kubernetes cluster

Follow these steps to deploy Dapr on Kubernetes.

When setting up Dapr on Kubernetes, you can use either the Dapr CLI or Helm.

Hybrid clusters

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 if your application requires it. For more information, see Deploying to a hybrid Linux/Windows Kubernetes cluster.

Install with Dapr CLI

You can install Dapr on a Kubernetes cluster using the Dapr CLI.

Prerequisites

Installation options

You can install Dapr from an official Helm chart or a private chart, using a custom namespace, etc.

Install Dapr from an official Dapr Helm chart

The -k flag initializes Dapr on the Kubernetes cluster in your current context.

  1. Verify the correct “target” cluster is set by checking kubectl context (kubectl config get-contexts).

    • You can set a different context using kubectl config use-context <CONTEXT>.
  2. Initialize Dapr on your cluster with the following command:

    1. dapr init -k

    Expected output

    1. Making the jump to hyperspace...
    2. Deploying the Dapr control plane to your cluster...
    3. 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
  3. Run the dashboard:

    1. dapr dashboard -k

    If you installed Dapr in a non-default namespace, run:

    1. dapr dashboard -k -n <your-namespace>

Install Dapr from a private Dapr Helm chart

Installing Dapr from a private Helm chart can be helpful for when you:

  • Need more granular control of the Dapr Helm chart
  • Have a custom Dapr deployment
  • Pull Helm charts from trusted registries that are managed and maintained by your organization

Set the following parameters to allow dapr init -k to install Dapr images from the configured Helm repository.

  1. export DAPR_HELM_REPO_URL="https://helm.custom-domain.com/dapr/dapr"
  2. export DAPR_HELM_REPO_USERNAME="username_xxx"
  3. export DAPR_HELM_REPO_PASSWORD="passwd_xxx"

Install in high availability mode

You can run Dapr with three replicas of each control plane pod in the dapr-system namespace for production scenarios.

  1. dapr init -k --enable-ha=true

Install in custom namespace

The default namespace when initializing Dapr is dapr-system. You can override this with the -n flag.

  1. dapr init -k -n mynamespace

Disable mTLS

Dapr is initialized by default with mTLS. You can disable it with:

  1. dapr init -k --enable-mtls=false

Wait for the installation to complete

You can wait for the installation to complete its deployment with the --wait flag. The default timeout is 300s (5 min), but can be customized with the --timeout flag.

  1. dapr init -k --wait --timeout 600

Uninstall Dapr on Kubernetes with CLI

Run the following command on your local machine to uninstall Dapr on your cluster:

  1. dapr uninstall -k

Install with Helm

You can install Dapr on Kubernetes using a Helm v3 chart.

Important: The latest Dapr Helm chart no longer supports Helm v2. Migrate from Helm v2 to Helm v3.

Prerequisites

Add and install Dapr Helm chart

  1. Add the Helm repo and update:

    1. // Add the official Dapr Helm chart.
    2. helm repo add dapr https://dapr.github.io/helm-charts/
    3. // Or also add a private Dapr Helm chart.
    4. helm repo add dapr http://helm.custom-domain.com/dapr/dapr/ \
    5. --username=xxx --password=xxx
    6. helm repo update
    7. // See which chart versions are available
    8. helm search repo dapr --devel --versions
  2. Install the Dapr chart on your cluster in the dapr-system namespace.

    1. helm upgrade --install dapr dapr/dapr \
    2. --version=1.12 \
    3. --namespace dapr-system \
    4. --create-namespace \
    5. --wait

    To install in high availability mode:

    1. helm upgrade --install dapr dapr/dapr \
    2. --version=1.12 \
    3. --namespace dapr-system \
    4. --create-namespace \
    5. --set global.ha.enabled=true \
    6. --wait

See Guidelines for production ready deployments on Kubernetes for more information on installing and upgrading Dapr using Helm.

(optional) Install the Dapr dashboard as part of the control plane

If you want to install the Dapr dashboard, use this Helm chart with the additional settings of your choice:

helm install dapr dapr/dapr-dashboard --namespace dapr-system

For example:

  1. helm repo add dapr https://dapr.github.io/helm-charts/
  2. helm repo update
  3. kubectl create namespace dapr-system
  4. # Install the Dapr dashboard
  5. helm install dapr-dashboard dapr/dapr-dashboard --namespace dapr-system

Verify installation

Once the installation is complete, verify that the dapr-operator, dapr-placement, dapr-sidecar-injector, and dapr-sentry pods are running in the dapr-system namespace:

  1. kubectl get pods --namespace dapr-system
  1. NAME READY STATUS RESTARTS AGE
  2. dapr-dashboard-7bd6cbf5bf-xglsr 1/1 Running 0 40s
  3. dapr-operator-7bd6cbf5bf-xglsr 1/1 Running 0 40s
  4. dapr-placement-7f8f76778f-6vhl2 1/1 Running 0 40s
  5. dapr-sidecar-injector-8555576b6f-29cqm 1/1 Running 0 40s
  6. dapr-sentry-9435776c7f-8f7yd 1/1 Running 0 40s

Uninstall Dapr on Kubernetes

  1. helm uninstall dapr --namespace dapr-system

More information

Use Mariner-based images

The default container images pulled on Kubernetes are based on distroless.

Alternatively, you can use Dapr container images based on Mariner 2 (minimal distroless). Mariner, officially known as CBL-Mariner, is a free and open-source Linux distribution and container base image maintained by Microsoft. For some Dapr users, leveraging container images based on Mariner can help you meet compliance requirements.

To use Mariner-based images for Dapr, you need to add -mariner to your Docker tags. For example, while ghcr.io/dapr/dapr:latest is the Docker image based on distroless, ghcr.io/dapr/dapr:latest-mariner is based on Mariner. Tags pinned to a specific version are also available, such as 1.12-mariner.

In the Dapr CLI, you can switch to using Mariner-based images with the --image-variant flag.

  1. dapr init --image-variant mariner

With Kubernetes and Helm, you can use Mariner-based images by setting the global.tag option and adding -mariner. For example:

  1. helm upgrade --install dapr dapr/dapr \
  2. --version=1.12 \
  3. --namespace dapr-system \
  4. --create-namespace \
  5. --set global.tag=1.12.0-mariner \
  6. --wait

Last modified October 12, 2023: Update config.toml (#3826) (0ffc2e7)