From b93c0b3324d4cc257917bdd754cd1b39d3084b64 Mon Sep 17 00:00:00 2001 From: Matthew Fisher Date: Tue, 5 Mar 2024 14:42:24 -0800 Subject: [PATCH] WIP: use native dapr, then branch out to dapr shared Signed-off-by: Matthew Fisher --- .../tutorials/running-with-dapr.md | 137 +++++++----------- 1 file changed, 54 insertions(+), 83 deletions(-) diff --git a/content/en/docs/spin-operator/tutorials/running-with-dapr.md b/content/en/docs/spin-operator/tutorials/running-with-dapr.md index dd680f56..72004e90 100644 --- a/content/en/docs/spin-operator/tutorials/running-with-dapr.md +++ b/content/en/docs/spin-operator/tutorials/running-with-dapr.md @@ -7,115 +7,86 @@ tags: [Tutorials] weight: 100 --- -## How to Configure Dapr Shared With a SpinApp +## How to Configure Dapr With a Spin app on Kubernetes -In this tutorial we will configure Dapr Shared with a SpinApp. +Dapr is a portable, event-driven runtime that makes it easy for developers to build resilient +applications. It provides a set of building blocks for building applications, including state +management, pub/sub, and service invocation. Dapr applications can be written in any language and +run on any platform. -## Dapr Shared +In this tutorial, we will deploy a Spin app on Kubernetes and configure it to use Dapr for Pub/Sub +communication. -[Why Dapr Shared](https://github.com/dapr-sandbox/dapr-shared?tab=readme-ov-file#why-dapr-shared)? - -Dapr Shared is a framework designed to share Dapr sidecars across multiple applications. This approach optimizes resource utilization by allowing applications to share a common set of Dapr sidecars, reducing the overhead of deploying individual sidecars for each application. Dapr Shared extends the Dapr sidecar model with two new deployment strategies: the flexibility to create Dapr Applications using the `daprd` Sidecar either as a Kubernetes `DaemonSet` or a `Deployment`. +## Prerequisites -Opting for `daprd` as a Kubernetes `DaemonSet` ensures that the `daprd` container operates on every Kubernetes Node. This setup significantly minimizes the network distance between applications and Dapr, enhancing performance. +Follow the [guide to run spin-operator](running-locally.md) to install the Spin Operator. -Alternatively, deploying Dapr Shared as a Kubernetes `Deployment` allows the Kubernetes scheduler to determine the specific node where the Dapr Shared instance will operate. This method offers a balanced distribution of resources and workload management across the Kubernetes environment. +## Installing Dapr -## Prerequisites +In this post, we will use Dapr v1.13.0, which you should see as -Please see the [Go](./prerequisites.md#go), [Docker](./prerequisites.md#docker), [Kubectl](./prerequisites.md#kubectl), [k3d](./prerequisites.md#k3d) and [Helm](./prerequisites.md#helm) sections in the [Prerequisites](./prerequisites.md) page and fulfill those prerequisite requirements before continuing. +```sh +dapr --version +CLI version: 1.12.0 +Runtime version: n/a +``` -## Fetch Spin Operator (Source Code) +Initialize Dapr on your cluster with the following command: -Clone the Spin Operator repository: +```sh +⌛ Making the jump to hyperspace... +ℹ️ Note: To install Dapr using Helm, see here: https://docs.dapr.io/getting-started/install-dapr-kubernetes/#install-with-helm-advanced -```bash -git clone https://github.com/spinkube/spin-operator.git +ℹ️ Container images will be pulled from Docker Hub +✅ Deploying the Dapr control plane with latest version to your cluster... +✅ Deploying the Dapr dashboard with latest version 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 ``` -Change into the Spin Operator directory: +Check the status of Dapr with the following command: -```bash -cd spin-operator +```sh +dapr status -k + NAME NAMESPACE HEALTHY STATUS REPLICAS VERSION AGE CREATED + dapr-placement-server dapr-system True Running 1 1.12.5 15s 2024-03-05 14:21.49 + dapr-operator dapr-system True Running 1 1.12.5 15s 2024-03-05 14:21.49 + dapr-sentry dapr-system True Running 1 1.12.5 15s 2024-03-05 14:21.49 + dapr-dashboard dapr-system True Running 1 0.14.0 14s 2024-03-05 14:21.50 + dapr-sidecar-injector dapr-system True Running 1 1.12.5 15s 2024-03-05 14:21.49 ``` -## Setting Up Kubernetes Cluster -Run the following command to create a Kubernetes k3d cluster that has [the containerd-wasm-shims](https://github.com/deislabs/containerd-wasm-shims) pre-requisites installed: -```bash -k3d cluster create wasm-cluster --image ghcr.io/deislabs/containerd-wasm-shims/examples/k3d:v0.10.0 -p "8081:80@loadbalancer" --agents 2 -``` +## Running the Sample Application -Run the following command to create the Runtime Class: +Now we will run the sample application with Dapr Shared. To do this, we will need to create a +`SpinApp` resource that references the Dapr Shared instance. -```bash +```yaml kubectl apply -f - < \ - --set shared.remoteURL= \ - --set shared.remotePort= -``` - -For example: + ```bash -helm install my-shared-instance \ - oci://registry-1.docker.io/daprio/dapr-shared-chart \ - --set shared.appId=simple-spinapp \ - --set shared.remoteURL=simple-spinapp \ - --set shared.remotePort=8083 -``` - -The above helm command will return something similar to the following: - -```bash -Pulled: registry-1.docker.io/daprio/dapr-shared-chart:0.0.12 -Digest: sha256:f63a5936f43294aa1aacb8695c06d43efd5f1672a336a954b4a15990bcfb8112 -NAME: my-shared-instance -LAST DEPLOYED: Fri Jan 19 15:59:33 2024 -NAMESPACE: default -STATUS: deployed -REVISION: 1 -TEST SUITE: None +kubectl create -f ./config/samples/simple.yaml ``` - -> Note: You can [Customize Dapr Shared using Helm values](https://github.com/dapr-sandbox/dapr-shared?tab=readme-ov-file#customize-dapr-shared).