Tekton — Build a pipeline on Kubernetes cloud native CI/CD tools

Tony Fu
7 min readNov 3, 2023

Tekton as a Kubernetes cloud native CI/CD tools is seamlessly integrates with Kubernetes, offering enhanced scalability, portability, and automation. It leverages Kubernetes’ orchestration capabilities to efficiently manage CI/CD pipelines, making it a powerful choice for cloud-native application development and deployment.

To gain a better understanding of the CI/CD pipeline workflow, practical experience is useful and good to understand how the step it goes.

Let’s get start at Environment setup

The blog here we are following the Tekton website instruction to setup a Tekton environment and builds a pipeline.

Installation minikube by Local Kubernetes, minikube facilitates local Kubernetes cluster development and testing. Follow these steps for installation:

First of all, install the docker. the error could come like below if no docker pre-install on the machine.

Docker Permission

  1. Modify the premission of the docker file path, sudo chmod 666 /var/run/docker.sock. The docker.sock is the file interact the Docker daemon connection.
  2. create a docker group by “sudo groupadd docker”, Add your user to the docker group “sudo usermod -aG docker ${USER}

Testing with the “minikube start” command, the Minikube service has been successfully initiated.

Let’s take a look how we could Interact with kubenetes cluster.

  • kubectl get po -A, list the requested object(s) across all namespaces of pods
  • minikube delete, could use after the pipeline have finished.
  • minikube dashboard, provide visibility of Kubernetes dashboard running within the minikube cluster

At the lab time using the minikube version: v1.31.2 and the list of the commands as below.

tektonuser@Tekton202310:~$ minikube --help
minikube provisions and manages local Kubernetes clusters optimized for development workflows.

Basic Commands:
start Starts a local Kubernetes cluster
status Gets the status of a local Kubernetes cluster
stop Stops a running local Kubernetes cluster
delete Deletes a local Kubernetes cluster
dashboard Access the Kubernetes dashboard running within the minikube cluster
pause pause Kubernetes
unpause unpause Kubernetes

Images Commands:
docker-env Provides instructions to point your terminal's docker-cli to the Docker Engine inside minikube.
(Useful for building docker images directly inside minikube)
podman-env Configure environment to use minikube's Podman service
cache Manage cache for images
image Manage images

Configuration and Management Commands:
addons Enable or disable a minikube addon
config Modify persistent configuration values
profile Get or list the current profiles (clusters)
update-context Update kubeconfig in case of an IP or port change

Networking and Connectivity Commands:
service Returns a URL to connect to a service
tunnel Connect to LoadBalancer services

Advanced Commands:
mount Mounts the specified directory into minikube
ssh Log into the minikube environment (for debugging)
kubectl Run a kubectl binary matching the cluster version
node Add, remove, or list additional nodes
cp Copy the specified file into minikube

Troubleshooting Commands:
ssh-key Retrieve the ssh identity key path of the specified node
ssh-host Retrieve the ssh host key of the specified node
ip Retrieves the IP address of the specified node
logs Returns logs to debug a local Kubernetes cluster
update-check Print current and latest version number
version Print the version of minikube
options Show a list of global command-line options (applies to all commands).

Other Commands:
completion Generate command completion for a shell
license Outputs the licenses of dependencies to a directory

Use "minikube <command> --help" for more information about a given command.

Start service with Minikube

  1. Interact with local Kubernetes cluster using kubectl, create a deployment by running “kubectl create deployment hello-minikube --image=kicbase/echo-server:1.0
  2. Exposing a service using “kubectl expose deployment hello-minikube --type=NodePort --port=8080
  3. Open the exposed endpoint use the following command “minikube service hello-minikube

As the browser will pop up and display the service, it appears to be working, and the service is up and running.

Install Tekton Pipelines

  1. Install Tekon Pipelines on a Kubernetes cluster as latest official release “kubectl apply --filename https://storage.googleapis.com/tekton-releases/pipeline/latest/release.yaml”.
  2. Monitor the installation by using “kubectl get pods --namespace tekton-pipelines --watch

Once tekton-pipelines-controller and tekton-pipelines-webhook show 1/1 under the READY column. The Tekton pipeline is ready, then move forward to create task.

Tekton pipelines have many entity, one of the need-to-know entity is task. Task defines a series of steps, related ingest specific inputs and produce specific outputs.

Let’s follow step by step to run the task, create a task named hello-world.yaml and taskrun hello-world-run.yaml as follow.

apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: hello
spec:
steps:
- name: echo
image: alpine
script: |
#!/bin/sh
echo "Hello World"
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
name: hello-task-run
spec:
taskRef:
name: hello
  1. Apply the changes your cluster by using “kubectl apply --filename hello-world.yaml”.
  2. Apply the changes to your cluster to launch the task “kubectl apply --filename hello-world-run.yaml”.
  3. Verify the taskrun success by using “kubectl get taskrun hello-task-run
  4. Verify the Hello world could display by look at the logs “
    kubectl logs --selector=tekton.dev/taskRun=hello-task-run
Apply task change to cluster
Apply runtask change to cluster
Verify the status and output

Hello World is running well as expected.

Clone a public git repository with Tekton

Request for Installation: kubectl, Tekton Pipelines, and Tekton CLI

Install the Tekton CLI “tkn”, on your machine. tkn is available on Linux as a .deb package. curl to download the deb package and dpkg install the package.

root@Tekton202310:/home/tektonuser# curl -LO https://github.com/tektoncd/cli/releases/download/v0.32.2/tektoncd-cli-0.32.2_Linux-64bit.deb
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0
100 28.5M 100 28.5M 0 0 2986k 0 0:00:09 0:00:09 --:--:-- 6488k
root@Tekton202310:/home/tektonuser# sudo dpkg -i ./tektoncd-cli-0.32.2_Linux-64bit.deb
Selecting previously unselected package cli.
(Reading database ... 208803 files and directories currently installed.)
Preparing to unpack .../tektoncd-cli-0.32.2_Linux-64bit.deb ...
Unpacking cli (0.32.2) ...
Setting up cli (0.32.2) ...

List of tkn pipelinerun commands reference as below:

tektonuser@Tekton202310:~/example1$ tkn pipelinerun
Manage PipelineRuns

Usage:
tkn pipelinerun [flags]
tkn pipelinerun [command]

Aliases:
pipelinerun, pr, pipelineruns

Available Commands:
cancel Cancel a PipelineRun in a namespace
delete Delete PipelineRuns in a namespace
describe Describe a PipelineRun in a namespace
export Export PipelineRun
list Lists PipelineRuns in a namespace
logs Show the logs of a PipelineRun

Flags:
-c, --context string name of the kubeconfig context to use (default: kubectl config current-context)
-h, --help help for pipelinerun
-k, --kubeconfig string kubectl config file (default: $HOME/.kube/config)
-n, --namespace string namespace to use (default: from $KUBECONFIG)
-C, --no-color disable coloring (default: false)

Use "tkn pipelinerun [command] --help" for more information about a command.

Following the previous session, let’s continue by setting up and executing tasks step by step. Create three YAML files: Pipeline.yaml, PipelineRun.yaml, and show-readme.yaml, as outlined below.

apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: clone-read
spec:
description: |
This pipeline clones a git repo, then echoes the README file to the stout.
params:
- name: repo-url
type: string
description: The git repo URL to clone from.
workspaces:
- name: shared-data
description: |
This workspace contains the cloned repo files, so they can be read by the
next task.
- name: git-credentials
description: My ssh credentials
tasks:
- name: fetch-source
taskRef:
name: git-clone
workspaces:
- name: output
workspace: shared-data
- name: ssh-directory
workspace: git-credentials
params:
- name: url
value: $(params.repo-url)
- name: show-readme
runAfter: ["fetch-source"]
taskRef:
name: show-readme
workspaces:
- name: source
workspace: shared-data
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
generateName: clone-read-run-
spec:
pipelineRef:
name: clone-read
podTemplate:
securityContext:
fsGroup: 65532
workspaces:
- name: shared-data
volumeClaimTemplate:
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
- name: git-credentials
secret:
secretName: git-credentials
params:
- name: repo-url
value: git@github.com:tektoncd/website.git
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: show-readme
spec:
description: Read and display README file.
workspaces:
- name: source
steps:
- name: read
image: alpine:latest
script: |
#!/usr/bin/env sh
cat $(workspaces.source.path)/README.md

Before go to next step, it could verify if the client version and pipeline version have installed by using “tkn version”. Then install a git clone task from tekton hub by using “tkn hub install task git-clone” or “kubectl apply -f https://raw.githubusercontent.com/tektoncd/catalog/main/task/git-clone/0.6/git-clone.yaml”.

tkn install
kubectl install
  1. Apply the readme by “kubectl apply -f show-readme.yaml
  2. Apply the readme by “kubectl apply -f pipeline.yaml
  3. Create the pipelinerun by “kubectl create -f pipelinerun.yaml
  4. Use the PipelineRun name from the output of the previous step to monitor the Pipeline execution “tkn pipelinerun logs clone-read-run-76mfq -f

Clone a git repository with Tekton success!! It can refer to the documentation available on the Tekton website and it is nice to have a try. Now, one more another CI/CD tool for enhance pipeline.

--

--

Tony Fu

Extensive experience as network engineer and cybersecurity engineer, interest in automation, simplifying architecture, and innovating with new technologies.