github.com/argoproj/argo-events@v1.9.1/docs/tutorials/04-standard-k8s-resources.md (about)

     1  # Trigger Standard K8s Resources
     2  
     3  In the previous sections, you saw how to trigger the Argo workflows. In this
     4  tutorial, you will see how to trigger Pod and Deployment.
     5  
     6  **Note:** You can trigger any standard Kubernetes object.
     7  
     8  Having the ability to trigger standard Kubernetes resources is quite powerful as
     9  provides an avenue to set up pipelines for existing workloads.
    10  
    11  ## Prerequisites
    12  
    13  1. Make sure that the service account used by the Sensor has necessary
    14      permissions to create the Kubernetes resource of your choice. We use
    15      `k8s-resource-sa` for below examples, it should be bound to a Role like
    16      following.
    17  
    18          apiVersion: rbac.authorization.k8s.io/v1
    19          kind: Role
    20          metadata:
    21            name: create-deploy-pod-role
    22          rules:
    23            - apiGroups:
    24                - ""
    25              resources:
    26                - pods
    27              verbs:
    28                - create
    29            - apiGroups:
    30                - apps
    31              resources:
    32                - deployments
    33              verbs:
    34                - create
    35  
    36  2. The `Webhook` event-source is already set up.
    37  
    38  ## Pod
    39  
    40  1. Create a sensor with K8s trigger.
    41  
    42           kubectl -n argo-events apply -f https://raw.githubusercontent.com/argoproj/argo-events/stable/examples/tutorials/04-standard-k8s-resources/sensor-pod.yaml
    43  
    44  2. Use either Curl or Postman to send a post request to the
    45      `http://localhost:12000/example`.
    46  
    47          curl -d '{"message":"ok"}' -H "Content-Type: application/json" -X POST http://localhost:12000/example
    48  
    49  3. Now, you should see a pod being created.
    50  
    51          kubectl -n argo-events get po
    52  
    53  4. After the pod was completed, inspect the logs of the pod, you will something similar as below.
    54  
    55          _________________________________________
    56          / {"context":{"type":"webhook","specVersi \
    57          | on":"0.3","source":"webhook","e |
    58          | ventID":"30306463666539362d346666642d34 |
    59          | 3336332d383861312d336538363333613564313 |
    60          | 932","time":"2020-01-11T21:23:07.682961 |
    61          | Z","dataContentType":"application/json" |
    62          | ,"subject":"example"},"data":"eyJoZWFkZ |
    63          | XIiOnsiQWNjZXB0IjpbIiovKiJdLCJDb250ZW50 |
    64          | LUxlbmd0aCI6WyIxOSJdLCJDb250ZW50LVR5cGU |
    65          | iOlsiYXBwbGljYXRpb24vanNvbiJdLCJVc2VyLU |
    66          | FnZW50IjpbImN1cmwvNy41NC4wIl19LCJib2R5I |
    67          \ jp7Im1lc3NhZ2UiOiJoZXkhISJ9fQ=="}       /
    68          -----------------------------------------
    69            \
    70             \
    71              \
    72                            ##        .
    73                      ## ## ##       ==
    74                   ## ## ## ##      ===
    75               /""""""""""""""""___/ ===
    76          ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ /  ===- ~~~
    77               \______ o          __/
    78                \    \        __/
    79                  \____\______/
    80  
    81  ## Deployment
    82  
    83  1. Lets create a sensor with a K8s deployment as trigger.
    84  
    85          kubectl -n argo-events apply -f https://raw.githubusercontent.com/argoproj/argo-events/stable/examples/tutorials/04-standard-k8s-resources/sensor-deployment.yaml
    86  
    87  2. Use either Curl or Postman to send a post request to the
    88      `http://localhost:12000/example`.
    89  
    90          curl -d '{"message":"ok"}' -H "Content-Type: application/json" -X POST http://localhost:12000/example
    91  
    92  3. Now, you should see a deployment being created. Get the corresponding pod.
    93  
    94          kubectl -n argo-events get deployments
    95  
    96  4. After the pod was completed, inspect the logs of the pod, you will see something similar as below.
    97  
    98          _________________________________________
    99          / {"context":{"type":"webhook","specVersi \
   100          | on":"0.3","source":"webhook","e |
   101          | ventID":"30306463666539362d346666642d34 |
   102          | 3336332d383861312d336538363333613564313 |
   103          | 932","time":"2020-01-11T21:23:07.682961 |
   104          | Z","dataContentType":"application/json" |
   105          | ,"subject":"example"},"data":"eyJoZWFkZ |
   106          | XIiOnsiQWNjZXB0IjpbIiovKiJdLCJDb250ZW50 |
   107          | LUxlbmd0aCI6WyIxOSJdLCJDb250ZW50LVR5cGU |
   108          | iOlsiYXBwbGljYXRpb24vanNvbiJdLCJVc2VyLU |
   109          | FnZW50IjpbImN1cmwvNy41NC4wIl19LCJib2R5I |
   110          \ jp7Im1lc3NhZ2UiOiJoZXkhISJ9fQ=="}       /
   111          -----------------------------------------
   112            \
   113             \
   114              \
   115                            ##        .
   116                      ## ## ##       ==
   117                   ## ## ## ##      ===
   118               /""""""""""""""""___/ ===
   119          ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ /  ===- ~~~
   120               \______ o          __/
   121                \    \        __/
   122                  \____\______/