From 7801f7300d0c66a5e2a41ac4466ce36c5fcafe9f Mon Sep 17 00:00:00 2001 From: salaboy Date: Fri, 9 Aug 2024 20:55:41 +0100 Subject: [PATCH] Initial Dapr integration (#26) Signed-off-by: salaboy --- README.md | 1 + dapr-integration/README.md | 66 +++++++++++++++++++ dapr-integration/dapr-components.yaml | 22 +++++++ dapr-integration/dapr-components/pubsub.yaml | 21 ++++++ .../dapr-components/statestore.yaml | 16 +++++ dapr-integration/dapr.yaml | 26 ++++++++ dapr-integration/redis.yaml | 28 ++++++++ 7 files changed, 180 insertions(+) create mode 100644 dapr-integration/README.md create mode 100644 dapr-integration/dapr-components.yaml create mode 100644 dapr-integration/dapr-components/pubsub.yaml create mode 100644 dapr-integration/dapr-components/statestore.yaml create mode 100644 dapr-integration/dapr.yaml create mode 100644 dapr-integration/redis.yaml diff --git a/README.md b/README.md index b537028..15f02f1 100644 --- a/README.md +++ b/README.md @@ -16,3 +16,4 @@ See [the instructions](https://github.com/cnoe-io/idpbuilder?tab=readme-ov-file# - **[Local Backup](./local-backup)**. How do I make sure my work is backed up? - **[Localstack](./localstack-integration)**. Use [LocalStack](https://github.com/localstack/localstack) to test out cloud integrations. - **[Terraform Integrations](./terraform-integrations)**. Integrating Terraform with Reference Implementation. +- **[Dapr Integration](./dapr-integrations)**. Integrating the Dapr APIs for Building Secure and Reliable Microservices . diff --git a/dapr-integration/README.md b/dapr-integration/README.md new file mode 100644 index 0000000..f74e559 --- /dev/null +++ b/dapr-integration/README.md @@ -0,0 +1,66 @@ +# Dapr Integrations + +`idpBuilder` is extensible to launch custom Dapr patterns using package extensions. + +Please use the following command to deploy Dapr using `idpbuilder`: + +```bash +idpbuilder create \ + --use-path-routing \ + --p https://github.com/cnoe-io/stacks//dapr-integrations +``` + +Notice that you can add Dapr to the reference implementation: + +```bash +idpbuilder create \ + --use-path-routing \ + --p https://github.com/cnoe-io/stacks//ref-implementation + --p https://github.com/cnoe-io/stacks//dapr-integrations +``` + +## What is installed? + +1. Dapr Control Plane +1. Dapr Statestore and PubSub components +2. Redis instance to support Statestore and Pubsub components + +Once installed, you can enable your workloads (Deployments) to use the Dapr APIs by using the Dapr annotations: + +``` +apiVersion: apps/v1 +kind: Deployment +metadata: + name: nodeapp + labels: + app: node +spec: + replicas: 1 + selector: + matchLabels: + app: node + template: + metadata: + labels: + app: node + annotations: + dapr.io/enabled: "true" + dapr.io/app-id: "nodeapp" + dapr.io/app-port: "3000" + dapr.io/enable-api-logging: "true" + spec: + containers: + - name: node + image: ghcr.io/dapr/samples/hello-k8s-node:latest + env: + - name: APP_PORT + value: "3000" + ports: + - containerPort: 3000 + imagePullPolicy: Always +``` +This example creates a Dapr-enabled Kubernetes Deployment (setting the `dapr.io/*` annotations). This application can now use the Dapr APIs to interact with the Statestore and PubSub components provided by the default installation. Applications can be written in any programming language, check the [Dapr SDKs here](https://docs.dapr.io/developing-applications/sdks/). + +For more information, check the Hello Kubernetes Dapr tutorial [here](https://github.com/dapr/quickstarts/tree/master/tutorials/hello-kubernetes) + + diff --git a/dapr-integration/dapr-components.yaml b/dapr-integration/dapr-components.yaml new file mode 100644 index 0000000..dad0965 --- /dev/null +++ b/dapr-integration/dapr-components.yaml @@ -0,0 +1,22 @@ +apiVersion: argoproj.io/v1alpha1 +kind: Application +metadata: + name: dapr-components + namespace: argocd + labels: + env: dev + finalizers: + - resources-finalizer.argocd.argoproj.io +spec: + project: default + source: + repoURL: cnoe://dapr-components + targetRevision: HEAD + path: "." + directory: + recurse: true + destination: + server: "https://kubernetes.default.svc" + namespace: default + syncPolicy: + automated: {} diff --git a/dapr-integration/dapr-components/pubsub.yaml b/dapr-integration/dapr-components/pubsub.yaml new file mode 100644 index 0000000..15372ee --- /dev/null +++ b/dapr-integration/dapr-components/pubsub.yaml @@ -0,0 +1,21 @@ +apiVersion: dapr.io/v1alpha1 +kind: Component +metadata: + name: pubsub +spec: + type: pubsub.redis + version: v1 + metadata: + # These settings will work out of the box if you use `helm install + # bitnami/redis`. If you have your own setup, replace + # `redis-master:6379` with your own Redis master address, and the + # Redis password with your own Secret's name. For more information, + # see https://docs.dapr.io/operations/components/component-secrets . + - name: redisHost + value: redis-master:6379 + - name: redisPassword + secretKeyRef: + name: redis + key: redis-password +auth: + secretStore: kubernetes \ No newline at end of file diff --git a/dapr-integration/dapr-components/statestore.yaml b/dapr-integration/dapr-components/statestore.yaml new file mode 100644 index 0000000..5e35ea3 --- /dev/null +++ b/dapr-integration/dapr-components/statestore.yaml @@ -0,0 +1,16 @@ +apiVersion: dapr.io/v1alpha1 +kind: Component +metadata: + name: statestore +spec: + type: state.redis + version: v1 + metadata: + - name: redisHost + value: redis-master:6379 + - name: redisPassword + secretKeyRef: + name: redis + key: redis-password +auth: + secretStore: kubernetes \ No newline at end of file diff --git a/dapr-integration/dapr.yaml b/dapr-integration/dapr.yaml new file mode 100644 index 0000000..3e81c4c --- /dev/null +++ b/dapr-integration/dapr.yaml @@ -0,0 +1,26 @@ +apiVersion: argoproj.io/v1alpha1 +kind: Application +metadata: + name: dapr + namespace: argocd + labels: + env: dev + finalizers: + - resources-finalizer.argocd.argoproj.io +spec: + project: default + source: + repoURL: 'https://dapr.github.io/helm-charts/' + targetRevision: 1.13.5 + helm: + releaseName: dapr + chart: dapr + destination: + server: 'https://kubernetes.default.svc' + namespace: dapr-system + syncPolicy: + automated: + prune: true + selfHeal: true + syncOptions: + - CreateNamespace=true diff --git a/dapr-integration/redis.yaml b/dapr-integration/redis.yaml new file mode 100644 index 0000000..b6eefb1 --- /dev/null +++ b/dapr-integration/redis.yaml @@ -0,0 +1,28 @@ +apiVersion: argoproj.io/v1alpha1 +kind: Application +metadata: + name: redis-dapr + namespace: argocd + labels: + env: dev + finalizers: + - resources-finalizer.argocd.argoproj.io +spec: + project: default + source: + repoURL: 'registry-1.docker.io/bitnamicharts' + targetRevision: 19.6.4 + helm: + valuesObject: + architecture: standalone + releaseName: redis + chart: redis + destination: + server: 'https://kubernetes.default.svc' + namespace: default + syncPolicy: + automated: + prune: true + selfHeal: true + syncOptions: + - CreateNamespace=true