What is Tekton?
Tekton is an open-source framework for creating CI/CD systems, running natively in kubernetes.
Developers looking to set up a CI/CD system today have an abundance of tools to choose from. The options range from traditional, self-hosted solutions – such as an on-premise Jenkins instance – to managed services such as CircleCI or GitHub Actions.
In recent years, many tools have come to embrace the use of containers, and for good reason. CI/CD services are most valuable when they consistently deliver reliable results. Containers allow build jobs or individual steps to be run in an isolated and controlled environment, reducing the number of hiccups experienced by, say, a software patch to the build server.
Among the tools available, Tekton is relatively new, but unique in that it is the first kubernetes native pipeline engine. Whereas other tools must adapt to the use of containers, and to kubernetes as an execution environment, Tekton is designed and developed specifically for kubernetes. The Tekton framework is made up of a number of sub-projects that can be used separately or in tandem:
- Tekton Pipelines
- Tekton Triggers
- Tekton Dashboard
- Tekton CLI
- Tekton Operator
- Tekton Catalog
Tekton Pipelines is the backbone of the project, and the first component to have been released.
At its core, Tekton Pipelines is made up of a set of Custom Resource Definitions (CRDs) and a kubernetes controller in charge of pipeline execution based on said resources. The CRDs map to foundational kubernetes concepts such as containers and pods:
A step is equivalently a kubernetes container spec, with a set of attributes that is familiar to anyone knowledgeable in kubernetes: a container is run from a specified image subject to optional environment variables or volume mounts. A single step, or a sequence of them, is what makes up a Task, the first CRD introduced by Tekton. An instance of a running Task is represented by the TaskRun CRD, much in the same way that a container is a running instance of the template that is a container image.
While Tasks can be executed individually, they are commonly tied together in a Pipeline, the next CRD. Whereas steps in a Task run sequentially in the order they are declared, Task execution order within a Pipeline can be structured much more freely, with some Tasks running sequentially and others in parallel, or not at all, based on the results from previous tasks. Just like Tasks, Pipeline instances are represented by the PipelineRun CRD.
To see Tekton in action, let’s run a Hello World! demonstration.
In hello-task.yaml, we define a Task with a single step and a single (optional) parameter, name. The step is a container spec, running the echo command in an ubuntu container. When supplying arguments for the command, we make use of the $(variable) syntax in order to substitute the value of the name parameter.
# hello-task.yaml apiVersion: tekton.dev/v1beta1 kind: Task metadata: name: hello spec: params: - name: name description: Whom to greet default: World steps: - name: hello image: ubuntu command: - echo args: - "Hello $(params.name)!"
To execute the Task, we can use the tekton CLI (tkn) or create the TaskRun resource directly. We reference the Task to be executed by name and supply a value for its name parameter.
# hello-taskrun.yaml apiVersion: tekton.dev/v1beta1 kind: TaskRun metadata: generateName: hello-run- spec: taskRef: name: hello params: - name: name value: Internet
After making sure the Task definition is applied cleanly to our cluster, we can create the TaskRun resource and use the tkn CLI to read its logs:
$ kubectl apply -f hello-task.yaml task.tekton.dev/hello configured $ kubectl create -f hello-taskrun.yaml taskrun.tekton.dev/hello-run-5wckx created $ tkn taskrun logs --last [hello] Hello Internet!
This trivial example barely scratches the surface of what is possible with Tekton. The interested reader can browse the Tekton Catalog for more Task examples.