As modern software development shifts towards cloud-native architectures, service pipelines have become key to deploying, managing, and scaling microservices independently. In this post, we’ll explore the fundamentals of Tekton, a Kubernetes-native framework, is built to automate CI/CD processes for services and the power to build complex workflows.
We'll also discuss why you might want to use Tekton over traditional CI/CD tools like GitLab CI or GitHub Actions.
What is Tekton?
Tekton is a Kubernetes-based framework for defining, running, and managing CI/CD pipelines. Unlike traditional CI/CD systems that typically handle the deployment of entire applications, Tekton excels at managing service pipelines, which allow individual microservices to be built, tested, and deployed independently. This gives you the ability to release services faster and with more flexibility.
Why Use Tekton for Service Pipelines?
1. Kubernetes-Native and Cloud-Native Integration
Tekton is designed specifically for Kubernetes environments, making it a perfect fit for organizations running microservices or cloud-native applications. Unlike GitLab CI or GitHub Actions, which require some integration overhead, Tekton runs directly within Kubernetes clusters, taking full advantage of Kubernetes’ orchestration, scaling, and security features.
2. Fine-Grained Control and Flexibility
Tekton provides more control over task execution, pipeline structure, and parameterization compared to traditional CI/CD tools. This flexibility allows you to build complex, customized workflows for each microservice, ensuring that each service pipeline can run independently and with the exact configuration you need.
3. Vendor-Neutral, Open-Source Solution
Tekton is completely open-source and vendor-neutral, meaning you’re not locked into a specific CI/CD ecosystem like GitLab or GitHub. This gives you the freedom to use Tekton in any Kubernetes environment, whether it’s self-hosted, on-prem, or in the cloud, without being tied to a specific platform.
Key Concepts
- Tasks: Individual units of work, such as running a build or test.
- Pipelines: Collections of tasks that run in sequence or parallel.
- TaskRuns and PipelineRuns: Runtime instances of tasks and pipelines, allowing you to pass parameters dynamically.
Tekton Service Pipeline Example
Let’s walk through building a service pipeline that retrieves content from a URL, displays it, and then uses that content to generate a personalized message.
Tekton Task
A Task is the basic building block of a Tekton service pipeline. Below is a task that greets a user based on an input parameter.
cat <<EOF | kubectl apply --validate=false -f -
apiVersion: tekton.dev/v1
kind: Task
metadata:
name: greet-task
spec:
params:
- name: person
type: string
description: Who should we greet?
default: world
steps:
- name: greet
image: alpine
command:
- echo
args:
- "Hello \$(params.person)!"
EOF
This task uses the Alpine image to echo a personalized greeting, which can be customized by passing a value for the person
parameter.
TaskRun Definition
The TaskRun below executes the task, allowing us to pass a specific value to the person
parameter.
cat <<EOF | kubectl apply --validate=false -f -
apiVersion: tekton.dev/v1
kind: TaskRun
metadata:
name: greet-task-run-1
spec:
params:
- name: person
value: "future engineers"
taskRef:
name: greet-task
EOF
Applying this task, we can see the output in pod log:
$ kubectl get pod | grep greet-task-run-1
greet-task-run-1-pod 0/1 Completed 0 34s
$ kubectl logs greet-task-run-1-pod
Defaulted container "step-greet" out of: step-greet, prepare (init)
Hello future engineers!
There are a Tekton hub containing Tasks which has been written by community.
We will examine the community curl
Task in next section
Tekton Pipeline and PipelineRun
Now, let’s define a service pipeline that uses multiple tasks. We’ll use the Curl task to fetch content from the internet and then pass that content into our greeting task.
Install the Curl Task
First, install the curl
community task from Tekton Hub:
kubectl apply -f https://api.hub.tekton.dev/v1/resource/tekton/task/curl/0.1/raw
Verify with kubectl get task
we'll see the new curl Task.
Pipeline Definition
The following pipeline defines a sequence of tasks: fetching content from a URL, displaying that content, and greeting the user with the content as a message.
cat <<EOF | kubectl apply --validate=false -f -
apiVersion: tekton.dev/v1
kind: Pipeline
metadata:
name: greet-service-pipeline
annotations:
description: |
Fetch content using curl, display it, and greet the user.
spec:
params:
- name: sourceUrl
description: The URL to fetch the content from
type: string
default: ""
workspaces:
- name: storage
tasks:
- name: fetch-content
taskRef:
name: curl
params:
- name: url
value: "$(params.sourceUrl)"
- name: output
value: "/workspace/storage/content.txt"
workspaces:
- name: output
workspace: storage
- name: display-content
runAfter: [fetch-content]
workspaces:
- name: output
workspace: storage
taskSpec:
workspaces:
- name: output
steps:
- name: cat-content
image: busybox
script: |
#!/bin/sh
cat /workspace/output/content.txt | tee /tekton/results/fetchedContent
results:
- name: fetchedContent
description: The content fetched from the URL
- name: greet-with-content
runAfter: [display-content]
taskRef:
name: greet-task
params:
- name: person
value: "$(tasks.display-content.results.fetchedContent)"
EOF
In this pipeline:
- Fetch Content: Uses
curl
to download content from a URL and store it in a workspace.
- Display Content: Reads the content and outputs it as a pipeline result.
- Greet with Content: Passes the fetched content as the greeting message in the final task.
PipelineRun Definition
Here’s how you run the pipeline using a PipelineRun, specifying a URL to fetch content from:
cat <<EOF | kubectl apply --validate=false -f -
apiVersion: tekton.dev/v1
kind: PipelineRun
metadata:
name: greet-service-pipeline-run-1
spec:
workspaces:
- name: storage
volumeClaimTemplate:
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Mi
params:
- name: sourceUrl
value: "https://raw.githubusercontent.com/nhatsangvn/nhatsangvn/refs/heads/main/README.md"
pipelineRef:
name: greet-service-pipeline
EOF
Applying this pipeline will fetch the content from the specified URL, display it, and greet the user with it.
kubectl apply -f greet-service-pipeline.yaml
kubectl apply -f greet-service-pipeline-run.yaml
Conclusion
In this blog post, we’ve covered the basics of Tekton and how it can be used to build service pipelines tailored for microservices and cloud-native architectures. By leveraging Tekton, you gain the flexibility, control, and scalability needed to manage independent service deployments, allowing for faster and more frequent updates. Whether you're building for Kubernetes, looking to decouple CI/CD processes, or need a vendor-agnostic solution, Tekton's service pipeline approach is a strong candidate for modern DevOps workflows.
Stay tuned for more advanced topics on Tekton in future posts!