Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

🏠 Back to Blog

Lab 1: Installation and Basics

Install Argo Events, create an EventBus, a webhook EventSource and a Sensor that creates a Workflow.

curl -> webhook EventSource -> EventBus (JetStream) -> Sensor -> Workflow

Install

kubectl create namespace argo-events
kubectl apply -n argo-events -f https://github.com/argoproj/argo-events/releases/latest/download/install.yaml
# optional, validates EventSource/Sensor specs on apply
kubectl apply -n argo-events -f https://github.com/argoproj/argo-events/releases/latest/download/install-validating-webhook.yaml
kubectl get pods -n argo-events
kubectl get crd | grep argoproj.io
  • One controller-manager pod handles EventBus, EventSource and Sensor resources (older versions had separate controllers)
  • Argo Events CRDs: eventbus, eventsources, sensors
  • Pin a version instead of latest if you care about repeatability

EventBus

  • Transport between EventSources (publishers) and Sensors (subscribers)
  • Implementations: JetStream (current), Kafka, NATS streaming (deprecated)
  • Must be named default for EventSources/Sensors to find it automatically
apiVersion: argoproj.io/v1alpha1
kind: EventBus
metadata:
  name: default
  namespace: argo-events
spec:
  jetstream:
    version: latest
    replicas: 3
kubectl apply -f eventbus.yaml
kubectl get eventbus -n argo-events
kubectl get pods -n argo-events -l eventbus-name=default
  • JetStream needs 3 replicas for HA, 1 is fine on a small kind cluster

Webhook EventSource

apiVersion: argoproj.io/v1alpha1
kind: EventSource
metadata:
  name: webhook
  namespace: argo-events
spec:
  service:
    ports:
      - port: 12000
        targetPort: 12000
  webhook:
    example:          # event name, referenced by the sensor
      port: "12000"
      endpoint: /example
      method: POST
kubectl get eventsource,pods -n argo-events
kubectl port-forward -n argo-events svc/webhook-eventsource-svc 12000:12000
  • service creates the Service <name>-eventsource-svc, here webhook-eventsource-svc
  • One EventSource can hold multiple named events
  • Event payload is {"header": {...}, "body": {...}}, the request body is under body

RBAC for the Sensor

The sensor’s service account creates the Workflow. The workflow pods themselves need to write results back (workflowtaskresults).

apiVersion: v1
kind: ServiceAccount
metadata:
  name: operate-workflow-sa
  namespace: argo-events
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: operate-workflow-role
  namespace: argo-events
rules:
  - apiGroups: [argoproj.io]
    resources: [workflows, workflowtemplates, cronworkflows, clusterworkflowtemplates, workflowtaskresults]
    verbs: [create, get, list, watch, update, patch, delete]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: operate-workflow-rolebinding
  namespace: argo-events
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: operate-workflow-role
subjects:
  - kind: ServiceAccount
    name: operate-workflow-sa
    namespace: argo-events
  - kind: ServiceAccount
    name: default
    namespace: argo-events
  • Binding default too is lazy, lets the workflow pods (which run as default) work. Fine for a lab
  • Workflows created in argo-events only run if the workflow controller watches that namespace (cluster-wide install, not the namespaced quick-start)

Sensor

  • dependencies = events to wait for, triggers = what to do
  • A dependency refs the EventSource name + event name
  • parameters copy event data into the trigger resource: src picks the data, dest is the path in the resource
apiVersion: argoproj.io/v1alpha1
kind: Sensor
metadata:
  name: webhook
  namespace: argo-events
spec:
  template:
    serviceAccountName: operate-workflow-sa
  dependencies:
    - name: test-dep
      eventSourceName: webhook
      eventName: example
  triggers:
    - template:
        name: webhook-workflow
        k8s:
          operation: create
          source:
            resource:
              apiVersion: argoproj.io/v1alpha1
              kind: Workflow
              metadata:
                generateName: webhook-
              spec:
                entrypoint: main
                arguments:
                  parameters:
                    - name: message
                      value: placeholder
                templates:
                  - name: main
                    container:
                      image: alpine:3
                      command: [echo, "{{workflow.parameters.message}}"]
          parameters:
            - src:
                dependencyName: test-dep
                dataKey: body.message
                value: no message       # default if the key is missing
              dest: spec.arguments.parameters.0.value
kubectl get sensor,pods -n argo-events
kubectl logs -n argo-events -l sensor-name=webhook
  • {{workflow.parameters.message}} is Argo Workflows syntax, resolved by the workflow controller, not the sensor
  • k8s trigger with operation: create can create any resource. The argoWorkflow trigger (lab 3) is the workflow-specific one
  • {{.Input.body.x}} Go templates do NOT work inside the resource, use parameters (or dataTemplate, see lab 3)

Test

curl -X POST -H "Content-Type: application/json" \
  -d '{"message": "hello from webhook"}' \
  http://localhost:12000/example

kubectl get workflows -n argo-events
argo logs -n argo-events @latest

Debug path: EventSource logs (event published?) -> sensor logs (dependency met? trigger fired?) -> kubectl get wf

kubectl logs -n argo-events -l eventsource-name=webhook
kubectl logs -n argo-events -l sensor-name=webhook
  • Sensor not triggering is usually: EventBus not ready, wrong eventSourceName/eventName, or missing RBAC

Cleanup

Keep the EventBus, SA and RBAC for the next labs.

# stop the port-forward (Ctrl-C), then
kubectl delete sensor,eventsource --all -n argo-events
kubectl delete workflows --all -n argo-events