Reader small image

You're reading from  Building CI/CD Systems Using Tekton

Product typeBook
Published inSep 2021
PublisherPackt
ISBN-139781801078214
Edition1st Edition
Right arrow
Author (1)
Joel Lord
Joel Lord
author image
Joel Lord

Joel Lord (joel__lord on Twitter) is passionate about the web and technology in general. He likes to learn new things, but most of all, he wants to share his discoveries. He does so by traveling to various conferences all across the globe. He graduated from college with a degree in computer programming in the last millennium. Apart from a little break to get his BSc in computational astrophysics, he has always worked in the industry. In his daily job, Joel is a developer advocate with MongoDB, where he connects with software engineers to help them make the web better by using best practices around JavaScript. In his free time, he can be found stargazing on a campground somewhere or brewing a fresh batch of beer in his garage.
Read more about Joel Lord

Right arrow

Chapter 10: Getting Started with Triggers

So far, you've learned how to create flexible and powerful pipelines using Tekton. Each time you wanted to start one of those pipelines, you had to use the tkn CLI tool to generate the pipeline run. If you remember from Chapter 1, A Brief History of CI/CD, the ultimate goal of CI/CD is to automate these processes.

In this chapter, you will learn about Tekton Triggers. Triggers is a sister project of Tekton Pipelines that introduces new custom resources to automate your CI/CD pipelines further. Using Triggers, you will learn how to start your pipelines using webhooks automatically. Since Tekton Triggers is an independent project, you will need to start by installing those new objects and configure your cluster to accept incoming requests. Once your cluster is ready to accept incoming webhooks, you will learn about the basic objects that will enable you to create Tekton Triggers to automate your CI/CD pipelines.

In this chapter, we...

Technical requirements

Check out the following link to see the Code in Action video: https://bit.ly/3ya1v3I

Introducing Tekton Triggers

In Chapter 1, A Brief History of CI/CD, you saw how continuous deployment refers to automatically deploying an application when changes are made to the code. So far, in all the Tekton examples you've seen, you had to trigger the pipeline for it to start manually. It is now time to bring the automation processes one step further and automatically start those pipelines as soon as some changes are pushed to your code repository.

To do so, you will use another tool called Tekton Triggers. Triggers enables you to accept incoming webhooks to your cluster and take appropriate action based on the content of these requests.

Using trigger templates, trigger bindings, and event listeners, three new objects in your Kubernetes cluster, you will be able to manipulate incoming HTTP requests, map the data into parameters, and then pass those values to your pipelines.

This process will trigger your pipeline, which would ultimately automatically deploy your...

Installing Tekton Triggers

Installing Tekton Triggers is very similar to Tekton Pipelines installation. You can use the kubectl command to apply the YAML files that are provided in the GitHub repository. You can find the most recent details of the installation, along with the URLs to the latest files on the Tekton website at https://tekton.dev/docs/triggers/install/.

The installation is in two steps. First, install the trigger custom resource definitions (CRDs) by running the following command:

$ kubectl apply -f https://storage.googleapis.com/tekton-releases/triggers/latest/release.yaml  

Next, you will need to install the interceptors. An interceptor is an object that contains the logic necessary to validate and filter webhooks coming from various sources. The Tekton Triggers team provides you with four basic interceptors (GitHub, Gitlab, Bitbucket, and Common Expression Language (CEL)). To install them, you can use the following command:

$ kubectl apply ...

Configuring your cluster

In order for external services, such as GitHub, to connect to your triggers, you will need to expose a service to the outside world. This process varies a lot depending on the type of cluster that you are using. Should you be using minikube, the process will be relatively simple. For cloud-based solutions, the setup might vary from one cloud provider to another, and you might need to read up the documentation from your specific supplier.

Using a local cluster

If you are using a local version on your computer, such as minikube, you will need additional software to help you expose your event listeners.

Right now, there is no way for GitHub to find your personal computer when it triggers a webhook. To do so, you will need a tool called ngrok to create a tunnel between your laptop and the outside world.

To install ngrok, go to https://ngrok.com/download. From there, follow the instructions on the page to install it on your computer, as shown in the...

Defining new objects

Once you install Tekton Triggers into your cluster, you will have access to three new objects. These objects will then be used to create your triggers and automate your pipeline's final part. The following figure describes the flow that happens when a trigger is started:

Figure 10.2 – Tekton trigger flow

In this section, you will learn more about each of these components.

Trigger templates

A TriggerTemplate is a new primitive that will be available to you once you've installed Tekton Triggers. The main goal of the trigger template is to be a template for the resources that the trigger will create.

Trigger templates are to Tekton triggers what pipelines are to pipeline runs. While the templates don't do any work, they describe what pipeline should be triggered and the parameters to pass to that pipeline.

Parameters for the trigger templates are similarly passed to the object, as is the case with pipelines...

Summary

In this chapter, you have learned about Tekton Triggers and what it can do to help you automate your CD pipeline. You've also learned about the new objects that Triggers will add to your Kubernetes cluster.

Then, you proceeded to install those CRDs in your cluster and added the necessary tooling for you to expose some new routes that will listen for GitHub webhooks.

In the next chapter, you will see how to use those objects to create your event listeners and connect them to your GitHub repository to automate your pipelines.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Building CI/CD Systems Using Tekton
Published in: Sep 2021Publisher: PacktISBN-13: 9781801078214
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Author (1)

author image
Joel Lord

Joel Lord (joel__lord on Twitter) is passionate about the web and technology in general. He likes to learn new things, but most of all, he wants to share his discoveries. He does so by traveling to various conferences all across the globe. He graduated from college with a degree in computer programming in the last millennium. Apart from a little break to get his BSc in computational astrophysics, he has always worked in the industry. In his daily job, Joel is a developer advocate with MongoDB, where he connects with software engineers to help them make the web better by using best practices around JavaScript. In his free time, he can be found stargazing on a campground somewhere or brewing a fresh batch of beer in his garage.
Read more about Joel Lord