Adopting Tekton — Cloud Native CI Solution
By: Nancy Chauhan
Tags: Continous Integration, DevOps, Kubernetes, Tekton, Infrastructure

Tekton

Tekton provides us with composable, declarative, reproducible, and Cloud-Native tools to easily build the pipelines. Tekton adds a few CRDs and custom resources to your Kubernetes cluster which can be used to make CI/CD pipelines.

Tekton Building Blocks

Step, Task, Pipeline

Step: Step is a container spec (k8s type), the most fundamental building block in Tekton. For instance, running unit tests of application would be a step.

Task: Task is a sequence of steps, runs in sequential order, and most importantly, it runs on the same K8s node, which allows you to have the same environment. For instance, if you mount a volume in a task, it would be shared across each step.

Pipeline: Pipeline is a collection of Tasks that can be run in different ways ( sequentially, concurrently, or a DAG). You can also provide the output of one task to another task even if it runs on a different K8s node.

To invoke these we have :

PipelineRun and TaskRun

Instances of Pipeline/Task:

PipelineRun: It is a specific execution of a pipeline that contains runtime data such as parameters and results. TaskRun: It is a specific execution of a task with runtime data.

PipelineRun and TaskRun bind together your tasks and pipelines with the parameter values and data. They can be triggered manually or on-demand using Tekton triggers.

In this blog, we will see how to trigger a pipeline manually. Later in the next blog, I will give an example to trigger pipeline automatically with webhook configuration. Let’s get started!

How to get started?

Prerequisites :

Kubernetes cluster to test out the changes. Install Kind to create a cluster locally. Install Tekton on the cluster :

This will Install Tekton in a new namespace called tekton-pipelines :

kubectl apply --filename https://storage.googleapis.com/tekton-releases/pipeline/latest/release.yaml

To switch to tekton-pipelines namespace where Tekton components are installed use this :

kubectl config set-context --current --namespace=tekton-pipelines

3. Install Tekton Dashboard .

4. After installation, set up port forwarding with Tekton Dashboard:

kubectl --namespace tekton-pipelines port-forward svc/tekton-dashboard 9097:9097

5. Set up a container registry. If you do not have one, you can set up a Github container registry by referring to https://nancychauhan.in/github-container-registry

Setting up

Install tasks from Tekton Hub

Install tasks on your Kubernetes namespace. We will use them to build the pipeline later.

2. kaniko

Create a secret for the service account

It will provide the credentials for pushing the docker image we build in the pipeline later.

➜ kubectl create secret docker-registry ghcr --docker-username=$USERNAME --docker-password=$TOKEN --docker-server=" https://ghcr.io/v1/

Apply Tekton manifests

We will set up CI for a sample project: https://github.com/Nancy-Chauhan/keystore

This pipeline will run the tests, build a docker image, and push it to the registry we configured.

Create a service account that allows access to the secrets we just created:

2. Create a pipeline to run tests and build & push a docker image:

Run the pipeline

Create a PipelineRun to trigger the pipeline, and you can pass information about the build.

Use the below example to create a PipelineRun. Replace the value of the image to refer to your registry and other parameters as necessary.

kubectl create -f keystore-ci.yaml

You can see the status of the pipeline in the Tekton Dashboard:

Tekton Dashboard

When the pipeline completes successfully, it posts success status for the commit.

Limitations:

We currently only update the success status as Tekton does not provide completion status to tasks yet. There are workarounds like writing status to a file and using it to send status to Github, but it is a story for another time. If you are interested in tracking the progress, check this:

Advantages of using Tekton:

Tekton is cloud-native, runs on an existing Kubernetes cluster. Tekton provides an out-of-the-box solution for monitoring. Easy to build pipeline using reusable tasks and steps.

Disadvantages :

No out-of-the-box support for authentication. Pipeline configuration is stored separately from code. To change the pipeline configuration, developers need to apply Kubernetes manifests manually.

Tekton community is quite helpful and quite prompt to reply to all your queries. Check it here: https://github.com/tektoncd/community/blob/master/contact.md

References: https://www.youtube.com/watch?v=sUkvpzr9du8

In the next blog, I will discuss setting up a webhook to automatically trigger the pipeline and monitor Tekton.

Nancy Chauhan is Software Engineer at Grofers. Follow her on LinkedIn and Twitter.