Earlier, we introduced how to install and trigger tasks in Argo Workflow. This article mainly introduces a new tool:

What is ArgoEvents?

Argo Events is an event-driven Kubernetes workflow automation framework. It supports more than 20 different events (such as webhooks, S3 drops, cronjobs, message queues - such as Kafka, GCP PubSub, SNS, SQS, etc.)

Features:

  • Supports events from 20+ event sources and more than 10 triggers.

  • Ability to customize business-level constraint logic for workflow automation.

  • Manage everything from simple, linear, real-time to complex, multi-source events.

  • Compliant with CloudEvents.

Components:

  • EventSource (similar to Gateway, sends messages to eventbus)
  • EventBus (event message queue, based on high-performance distributed message middleware NATS, but according to the NATS official website, it will no longer be maintained after 2023, and it is estimated that the architecture will be adjusted later)
  • EventSensor (subscribe to message queue, parameterize events and filter events)

ArgoEvents deployment and installation

argo-events deployment:

1
2
kubectl create ns argo-events
kubectl apply -n argo-events -f https://raw.githubusercontent.com/argoproj/argo-events/v1.2.3/manifests/install.yaml

argo-eventbus deployment:

1
kubectl apply -n argo-events -f https://raw.githubusercontent.com/argoproj/argo-events/stable/examples/eventbus/native.yaml

RBAC account authorization

Create an operate-workflow-sa account

Authorize operate-workflow-sa to create argo workflow tasks under the argo-events namespace, which will be used for EventSensor to automatically create workflows later.

1
namespace: argo-events

Create a workflow-pods-sa account

Authorize workflow-pods-sa to automatically create pods through workflow under argo-events

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
apiVersion: v1
kind: ServiceAccount
metadata:
namespace: argo-events
name: workflow-pods-sa
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: workflow-pods-role
rules:
- apiGroups:
- ""
verbs:
- "*"
resources:
- pods
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: workflow-pods-role-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: workflow-pods-role
subjects:
- kind: ServiceAccount
name: workflow-pods-sa
namespace: argo-events

ArgoEvents automated triggering tasks

Start an event-sources to accept requests:

1
kubectl apply -n argo-events -f https://raw.githubusercontent.com/argoproj/argo-events/stable/examples/event-sources/webhook.yaml

Note: Here, the name in event-sources is example. For the actual production environment, you need to specify the name here to create a sensor

Create a webhook sensor consumption request:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
apiVersion: argoproj.io/v1alpha1
kind: Sensor
metadata:
name: webhook
spec:
template: serviceAccountName: operate-workflow-sa dependencies: - name: test-dep eventSourceName: webhook eventName: example triggers: - template: name: webhook-workflow-trigger k8s: group: argoproj.io version: v1alpha1 resource: workflows operation: create source: resource: apiVersion: argoproj.io/v1alpha1 kind: Workflow metadata: generateName: webhook- spec: serviceAccountName: workflow- pods-sa entrypoint: whalesay arguments: parameters: - name: message # the value will get overridden by event payload from test-dep value: hello world templates: - name: whalesay inputs: parameters: - name: message container: image: docker/whalesay:latest command: [cowsay] args: ["{{inputs.parameters.message}}"]
parameters:
- src:
dependencyName: test-dep
dest: spec.arguments.parameters.0.value

Reference: https://raw.githubusercontent.com/argoproj/argo-events/stable/examples/sensors/webhook.yaml

forward local request to remote:

1
kubectl -n argo-events port-forward <name-of-event-source-pod> <local port>:12000

filter data to event-sources:

1
curl -d '{"message":"ok"}' -H "Content-Type: application/json" -X POST http://localhost:12000/example

At this point, ArgoEvents can be used to automatically create workflow tasks.