liveBook · Manning

Tekton

As explained in Platform Engineering on Kubernetes

Tekton is an open-source Kubernetes-native framework for defining and executing continuous integration and delivery tasks and pipelines.

Tekton is a Kubernetes-native pipeline engine for defining and running service pipelines. A service pipeline takes software from source code through build and packaging steps toward artifacts ready to run. Tekton provides a way to define that delivery process for services such as those in a distributed Conference application; the walkthrough below uses a smaller Hello World pipeline rather than building a Conference service. section 3.0 section 3.5.1

Installing Tekton adds Kubernetes custom resource definitions for Tasks and Pipelines, plus a controller that executes them. A Task defines steps; a TaskRun executes a task. A Pipeline arranges tasks in a sequence; each execution needs a PipelineRun. Because these are Kubernetes resources, familiar tools such as kubectl can inspect their runs and pods. The Dashboard and tkn command-line tool are optional additions. section 3.5.1 section 3.5.2

Listing 3.1 Simple Tekton task definition
apiVersion: tekton.dev/v1
kind: Task
metadata:
 name: hello-world-task                     #1
spec:
  params:
   - name: name                             #2
     type: string
     description: who do you want to welcome?
     default: tekton user
 steps:
   - name: echo
     image: ubuntu                          #3
     command:
       - echo                               #4
     args:
       - "Hello World: $(params.name)"      #5

The Task manifest shows the basic shape: a tekton.dev/v1 resource with a string parameter and a step that runs echo in an Ubuntu image. The step substitutes the supplied name into its message. section 3.5.1

Run one task

Create a TaskRun that supplies a name and references hello-world-task. After applying it to the cluster, use kubectl get taskrun to check SUCCEEDED, kubectl get pods to find its pod, and kubectl logs -f <pod-name> to read the greeting. A Task definition alone does not start an execution. section 3.5.1

Listing 3.6 Pipeline definition
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
  name: hello-world-pipeline
  annotations:
    description: |
      Fetch resource from internet, cat content and then say hello
spec:
  results:                                            #1
  - name: message
    type: string
    value: $(tasks.cat.results.messageFromFile)
  params:                                             #2
  - name: url
    description: resource that we want to fetch
    type: string
    default: ""
  workspaces:                                         #3
  - name: files
  tasks:
  - name: wget
    taskRef:                                          #4
      name: wget
    params:
    - name: url
      value: "$(params.url)"
    - name: diroptions
      value:
        - "-P"  
    workspaces:
    - name: wget-workspace
      workspace: files
  - name: cat
    runAfter: [wget]
    workspaces:
    - name: wget-workspace
      workspace: files
    taskSpec:                                         #5
      workspaces:
      - name: wget-workspace
      results: 
        - name: messageFromFile
          description: the message obtained from the file
      steps:
      - name: cat
        image: bash:latest
        script: |
          #!/usr/bin/env bash
          cat $(workspaces.wget-workspace.path)/welcome.md | 
> kubectl get pods
NAME                                     READY   STATUS   AGE
tee /tekton/results/messageFromFile
  - name: hello-world
    runAfter: [cat]
    taskRef:
      name: hello-world-task                           #6
    params:
      - name: name
        value: "$(tasks.cat.results.messageFromFile)"  #7

The Pipeline manifest combines a referenced wget task from the Tekton catalog, an inline cat task, and the previously defined Hello World task. Its parameters, workspace, results, and task ordering show how a sequence can fetch a file and pass its content to the final greeting. section 3.5.2

Execute the pipeline

Install the community wget task before applying hello-world-pipeline.yaml with kubectl apply -f hello-world-pipeline.yaml. Then apply a PipelineRun that references the pipeline, supplies the file URL, and provides the files workspace through a volume claim. Use kubectl get taskrun and kubectl get pods to check the three tasks; inspect the last pod’s logs for the greeting containing the fetched text. The Dashboard can also display the PipelineRun. section 3.5.2

Tekton also supports mappings between task inputs and outputs, event triggers, terminal access, and dashboard monitoring. Its flexibility comes with configuration work: teams must define tasks, data mappings, event listeners, and step images. Tekton Hub and the catalog help by supplying reusable task definitions. Choose its Kubernetes resource model when integration with Kubernetes management and monitoring matters; Dagger instead emphasizes pipelines written in programming languages and run across environments, while GitHub Actions offers a managed option. section 3.5.3 section 3.5.5

How Platform Engineering on Kubernetes covers it

How deep it goes
Works through Task, TaskRun, Pipeline, and PipelineRun manifests, execution checks, and logs; leaves production service-pipeline configuration to the implementer.
Examples
Uses a parameterized greeting task and a three-task pipeline that fetches a file, reads it, and prints its contents.
What it assumes
Assumes access to a Kubernetes cluster and familiarity with applying and inspecting resources; introduces Tekton’s task and pipeline resources from their basic definitions.
What you can do after
Operate/configure it by installing Tekton, applying task and pipeline resources, creating runs, and checking status and logs with kubectl.
How it connects
Links Kubernetes custom resources, service pipelines, task catalogs, event triggers, Dagger, and GitHub Actions.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Platform Engineering on Kubernetes. The section links point to the parts of the book it draws on.