mirror of https://github.com/dapr/samples.git
Argo CD Sample (#227)
* Argo CD Sample Signed-off-by: Fernando Rocha <fernando@diagrid.io> * Delete dapr-argocd/gitops/conductor directory Signed-off-by: Fernando Rocha <fernandorsl@gmail.com> * Update dapr-argocd/README.md Co-authored-by: Mark Fussell <markfussell@gmail.com> Signed-off-by: Fernando Rocha <fernandorsl@gmail.com> * Update dapr-argocd/README.md Co-authored-by: Mark Fussell <markfussell@gmail.com> Signed-off-by: Fernando Rocha <fernandorsl@gmail.com> * fixing module name Signed-off-by: Fernando Rocha <fernando@diagrid.io> * fixing module name Signed-off-by: Fernando Rocha <fernando@diagrid.io> * fixing module name Signed-off-by: Fernando Rocha <fernando@diagrid.io> --------- Signed-off-by: Fernando Rocha <fernando@diagrid.io> Signed-off-by: Fernando Rocha <fernandorsl@gmail.com> Co-authored-by: Mark Fussell <markfussell@gmail.com>
This commit is contained in:
parent
13dadda416
commit
1ee466d2b1
|
|
@ -8,4 +8,5 @@ hello-service-fabric/daprsfpkg/MyService/CodeDapr/daprd.exe
|
|||
hello-service-fabric/daprsfpkg/MyService/CodeDapr/components/pubsub.yaml
|
||||
hello-service-fabric/daprsfpkg/MyService/CodeDapr/components/statestore.yaml
|
||||
.venv/
|
||||
.dccache
|
||||
.dccache
|
||||
.DS_Store
|
||||
|
|
@ -37,6 +37,7 @@ If you are new to Dapr, you may want to review following resources first:
|
|||
| [Outbox in .NET](./outbox) | Demonstrates how to use the outbox transactions with Redis and MySql statestores and Redis as the message broker |
|
||||
| [Consuming Kafka messages without CloudEvents](./pubsub-raw-payload) | Demonstrates how to integrate a Kafka producer using the Confluent Kafka SDK with a Dapr-powered consumer in .NET applications |
|
||||
| [AWS EKS Pod Identity](./dapr-eks-podidentity) | Demonstrates how to set up Dapr with AWS EKS Pod Identity for accessing AWS Secrets Manager |
|
||||
| [GitOps with Argo CD and Dapr](./dapr-argocd) | Demonstrates how to install Dapr in a Kubenetes cluster using Argo CD |
|
||||
|
||||
## External samples
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,184 @@
|
|||
# Dapr + Argo CD Example
|
||||
|
||||
This repository demonstrates how to deploy Dapr and Redis using Argo CD, along with a sample application that uses Dapr's State Management building block with Redis.
|
||||
|
||||
## Repository Structure
|
||||
|
||||
- `/gitops`: Contains all Argo CD, Dapr, and Redis configuration files
|
||||
- `/app`: Contains the sample node and python applications
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- Kubernetes cluster (v1.21+ recommended)
|
||||
- kubectl configured to access your cluster
|
||||
- Helm v3
|
||||
- Git
|
||||
|
||||
## 1: Fork and clone this this repository
|
||||
|
||||
## 2: Install Argo CD
|
||||
|
||||
First, you need to install Argo CD on your Kubernetes cluster:
|
||||
|
||||
```bash
|
||||
# Create a namespace for Argo CD
|
||||
kubectl create namespace argocd
|
||||
|
||||
# Apply the Argo CD installation manifest
|
||||
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
|
||||
```
|
||||
|
||||
Then, install the Argo CD CLI:
|
||||
|
||||
```bash
|
||||
brew install argocd
|
||||
```
|
||||
|
||||
After installation, access the Argo CD UI:
|
||||
|
||||
```bash
|
||||
# Port-forward to the Argo CD server
|
||||
kubectl port-forward svc/argocd-server -n argocd 8080:443
|
||||
```
|
||||
|
||||
Get the initial admin password:
|
||||
|
||||
```bash
|
||||
argocd admin initial-password -n argocd
|
||||
```
|
||||
|
||||
Using the username `admin` and the password from above, login to Argo CD's IP or hostname (on our case, we are running it on `localhost:8080`):
|
||||
|
||||
```bash
|
||||
argocd login localhost:8080
|
||||
```
|
||||
|
||||
You can also access the UI by navigating to `https://localhost:8080` in your browser.
|
||||
|
||||
For a detailed step-by-step process on how to install Argo CD, follow the [official documentation](https://argo-cd.readthedocs.io/en/stable/getting_started/).
|
||||
|
||||
## 3: Install Dapr Using the Argo CD CLI
|
||||
|
||||
An Argo CD application is a custom Kubernetes resource that defines how an application should be deployed and managed using the GitOps methodology. It specifies the source configuration (usually a Git repository, Helm chart, or directory path), the destination cluster and namespace, sync policies for automation, and special synchronization options. This resource acts as the bridge connecting your desired state (defined in Git) with the actual state in your Kubernetes cluster.
|
||||
|
||||
When deployed, Argo CD continuously monitors both your Git repository and Kubernetes cluster to ensure they remain synchronized. Any deviation triggers either an alert or an automatic reconciliation based on your configuration. The application can be created and managed through Argo CD's web UI, CLI commands, YAML manifests, or API calls, making it a flexible foundation for implementing continuous delivery in Kubernetes environments.
|
||||
|
||||
Here, the Argo CD CLI is used to create the application for our Dapr deployment:
|
||||
|
||||
```bash
|
||||
argocd app create dapr \
|
||||
--repo https://github.com/<your-username>/dapr-argocd.git \
|
||||
--path gitops/dapr \
|
||||
--dest-server https://kubernetes.default.svc \
|
||||
--dest-namespace dapr-system
|
||||
```
|
||||
|
||||
Sync the application and verify the installation:
|
||||
|
||||
```bash
|
||||
argocd app sync dapr
|
||||
argocd app get dapr
|
||||
kubectl get pods -n dapr-system
|
||||
```
|
||||
|
||||
## 4: Install Redis Using Argo CD
|
||||
|
||||
Create an Argo CD application for Redis:
|
||||
|
||||
```bash
|
||||
argocd app create redis \
|
||||
--repo https://github.com/<your-username>/dapr-argocd.git \
|
||||
--path gitops/redis \
|
||||
--dest-server https://kubernetes.default.svc \
|
||||
--dest-namespace redis
|
||||
```
|
||||
|
||||
Sync the application and verify the installation:
|
||||
|
||||
```bash
|
||||
argocd app sync redis
|
||||
argocd app get redis
|
||||
kubectl get pods -n redis
|
||||
```
|
||||
|
||||
## 5: Configure Dapr Components
|
||||
|
||||
Create the namespace:
|
||||
|
||||
```bash
|
||||
kubectl create namespace argocd-demo
|
||||
```
|
||||
|
||||
Create the Dapr state store component application:
|
||||
|
||||
```bash
|
||||
argocd app create dapr-components \
|
||||
--repo https://github.com/<your-username>/dapr-argocd.git \
|
||||
--path gitops/dapr-components \
|
||||
--dest-server https://kubernetes.default.svc \
|
||||
--dest-namespace argocd-demo
|
||||
```
|
||||
|
||||
Sync the application:
|
||||
|
||||
```bash
|
||||
argocd app sync dapr-components
|
||||
argocd app get dapr-components
|
||||
```
|
||||
|
||||
## 6: Deploy the Sample Application
|
||||
|
||||
Deploy the `node` and `python` applications:
|
||||
|
||||
```bash
|
||||
# Node app
|
||||
argocd app create node \
|
||||
--repo https://github.com/<your-username>/dapr-argocd.git \
|
||||
--path app/node \
|
||||
--dest-server https://kubernetes.default.svc \
|
||||
--dest-namespace argocd-demo
|
||||
|
||||
# Python app
|
||||
argocd app create python \
|
||||
--repo https://github.com/<your-username>/dapr-argocd.git \
|
||||
--path app/python \
|
||||
--dest-server https://kubernetes.default.svc \
|
||||
--dest-namespace argocd-demo
|
||||
```
|
||||
|
||||
This will deploy both the node and python services in the `argocd-demo` namespace.
|
||||
|
||||
Verify the deployments:
|
||||
|
||||
```bash
|
||||
kubectl get pods -n argocd-demo
|
||||
```
|
||||
|
||||
You should see both pods running with their Dapr sidecars.
|
||||
|
||||
```bash
|
||||
nodeapp-7578bfc4dd-chs7x 2/2 Running 0 29m
|
||||
pythonapp-587fb8f7db-s55k6 2/2 Running 0 22m
|
||||
```
|
||||
|
||||
## 7: Verify the Communication
|
||||
|
||||
First, run port-forward to access the node service:
|
||||
|
||||
```bash
|
||||
kubectl port-forward service/nodeapp 8081:80 -n argocd-demo
|
||||
```
|
||||
|
||||
This will make your service available on `http://localhost:8081`.
|
||||
|
||||
In a new terminal run:
|
||||
|
||||
```bash
|
||||
curl -d '{"data":{"orderId":"42"}}' -H "Content-Type:application/json" -X POST http://localhost:8081/neworder
|
||||
```
|
||||
|
||||
Expected output:
|
||||
|
||||
```bash
|
||||
{ "orderId": "42" }
|
||||
```
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
kind: Service
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: nodeapp
|
||||
namespace: argocd-demo
|
||||
labels:
|
||||
app: node
|
||||
spec:
|
||||
selector:
|
||||
app: node
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 80
|
||||
targetPort: 3000
|
||||
type: LoadBalancer
|
||||
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: nodeapp
|
||||
namespace: argocd-demo
|
||||
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
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: pythonapp
|
||||
namespace: argocd-demo
|
||||
labels:
|
||||
app: python
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: python
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: python
|
||||
annotations:
|
||||
dapr.io/enabled: "true"
|
||||
dapr.io/app-id: "pythonapp"
|
||||
dapr.io/enable-api-logging: "true"
|
||||
spec:
|
||||
containers:
|
||||
- name: python
|
||||
image: ghcr.io/dapr/samples/hello-k8s-python:latest
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
apiVersion: argoproj.io/v1alpha1
|
||||
kind: Application
|
||||
metadata:
|
||||
name: dapr-components
|
||||
namespace: argocd
|
||||
spec:
|
||||
project: default
|
||||
source:
|
||||
repoURL: https://github.com/<your-username>/dapr-argocd.git
|
||||
path: gitops/dapr-components
|
||||
targetRevision: main
|
||||
directory:
|
||||
recurse: true
|
||||
exclude: '*.yaml'
|
||||
include: 'redis.yaml'
|
||||
destination:
|
||||
server: https://kubernetes.default.svc
|
||||
namespace: argocd-demo
|
||||
syncPolicy:
|
||||
automated:
|
||||
prune: false
|
||||
selfHeal: true
|
||||
syncOptions:
|
||||
- CreateNamespace=true
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
apiVersion: dapr.io/v1alpha1
|
||||
kind: Component
|
||||
metadata:
|
||||
name: statestore
|
||||
namespace: argocd-demo
|
||||
spec:
|
||||
type: state.redis
|
||||
version: v1
|
||||
metadata:
|
||||
- name: redisHost
|
||||
value: redis-master.redis.svc.cluster.local:6379
|
||||
- name: redisPassword
|
||||
value: ""
|
||||
- name: enableTLS
|
||||
value: "false"
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
apiVersion: argoproj.io/v1alpha1
|
||||
kind: Application
|
||||
metadata:
|
||||
name: dapr
|
||||
namespace: argocd
|
||||
finalizers:
|
||||
- resources-finalizer.argocd.argoproj.io
|
||||
spec:
|
||||
project: default
|
||||
source:
|
||||
chart: dapr
|
||||
repoURL: https://dapr.github.io/helm-charts/
|
||||
targetRevision: 1.15.3
|
||||
helm:
|
||||
releaseName: dapr
|
||||
values: |
|
||||
global:
|
||||
ha:
|
||||
enabled: true
|
||||
dapr_dashboard:
|
||||
enabled: true
|
||||
destination:
|
||||
server: https://kubernetes.default.svc
|
||||
namespace: dapr-system
|
||||
syncPolicy:
|
||||
automated:
|
||||
prune: false
|
||||
selfHeal: true
|
||||
syncOptions:
|
||||
- CreateNamespace=true
|
||||
# This configuration tells Argo CD to ignore changes to specific paths in the subscriptions.dapr.io CRD. As a result, Argo CD won’t flag the app as out-of-sync
|
||||
ignoreDifferences:
|
||||
- group: apiextensions.k8s.io
|
||||
kind: CustomResourceDefinition
|
||||
name: subscriptions.dapr.io
|
||||
jsonPointers:
|
||||
- /spec/conversion/webhook/clientConfig/service/namespace
|
||||
- /spec/conversion/webhook/clientConfig/caBundle
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
apiVersion: argoproj.io/v1alpha1
|
||||
kind: Application
|
||||
metadata:
|
||||
name: redis
|
||||
namespace: argocd
|
||||
finalizers:
|
||||
- resources-finalizer.argocd.argoproj.io
|
||||
spec:
|
||||
project: default
|
||||
source:
|
||||
chart: redis
|
||||
repoURL: https://charts.bitnami.com/bitnami
|
||||
targetRevision: 17.11.6 # Check for the latest version
|
||||
helm:
|
||||
releaseName: redis
|
||||
values: |
|
||||
auth:
|
||||
enabled: false
|
||||
master:
|
||||
persistence:
|
||||
enabled: true
|
||||
size: 1Gi
|
||||
replica:
|
||||
replicaCount: 1
|
||||
persistence:
|
||||
enabled: true
|
||||
size: 1Gi
|
||||
destination:
|
||||
server: https://kubernetes.default.svc
|
||||
namespace: redis
|
||||
syncPolicy:
|
||||
automated:
|
||||
prune: false
|
||||
selfHeal: true
|
||||
syncOptions:
|
||||
- CreateNamespace=true
|
||||
|
|
@ -1,3 +1,3 @@
|
|||
module github.com/rochabr/dapr-eks-podidentity
|
||||
module github.com/dapr/samples/dapr-eks-podidentity
|
||||
|
||||
go 1.22.5
|
||||
|
|
|
|||
Loading…
Reference in New Issue