- Posted on
- • Scripting for DevOps
Using Tekton for Declarative CI/CD
- Author
-
-
- User
- Linux Bash
- Posts by this author
- Posts by this author
-
Streamlining CI/CD Workflows using Tekton on Linux Bash
In the rapidly evolving field of software development, Continuous Integration and Continuous Deployment (CI/CD) have become fundamental in facilitating frequent and reliable code changes. Tekton, an open-source project, leads the Kubernetes-native approach to setting up CI/CD systems. This article will explore how to use Tekton to create declarative CI/CD pipelines on Linux, leveraging Bash for scripting and execution.
What is Tekton?
Tekton is a powerful yet flexible Kubernetes-native open-source framework for creating CI/CD systems, allowing developers to build, test, and deploy across multiple environments or cloud platforms seamlessly. It operates under the Cloud Native Computing Foundation (CNCF) and is designed to fit into the Kubernetes ecosystem, which makes it incredibly scalable and adaptable to complex workflows.
Setting Up Tekton on a Linux System
Firstly, ensure that Kubernetes is set up on your Linux system. You can use Minikube for a local setup or connect to an existing Kubernetes cluster.
Install the Tekton Pipelines:
Use
kubectl
to install Tekton Pipelines:kubectl apply --filename https://storage.googleapis.com/tekton-releases/pipeline/latest/release.yaml
This command sets up all necessary components like TaskRuns, PipelineRuns, etc.
Verify the installation:
To confirm that everything is correctly set up, check the components:
kubectl get pods --namespace tekton-pipelines
Ensure all pods are in a
Running
state.
Configuring a Basic CI/CD Pipeline using Tekton
With Tekton, the pipeline definition and components are declarative and stored in standard YAML format. Here’s a simple guide on how to configure a basic pipeline.
Create a Task:
Tasks are the most fundamental building blocks in Tekton, representing a series of steps to perform a specific job. For example, here’s a simple Bash task to echo "Hello Tekton":
apiVersion: tekton.dev/v1beta1 kind: Task metadata: name: echo-hello-task spec: steps: - name: echo image: ubuntu script: | #!/usr/bin/env bash echo "Hello Tekton"
Save this as
echo-hello-task.yaml
and apply it using kubectl:kubectl apply -f echo-hello-task.yaml
Create a Pipeline:
Pipelines define a series of tasks that handle the execution of your workloads. Create a pipeline that uses the task defined above:
apiVersion: tekton.dev/v1beta1 kind: Pipeline metadata: name: echo-pipeline spec: tasks: - name: echo-hello taskRef: name: echo-hello-task
Save this as
echo-pipeline.yaml
and apply it using kubectl:kubectl apply -f echo-pipeline.yaml
Run the Pipeline:
You trigger a pipeline by creating a
PipelineRun
, which is an instantiation of the pipeline:apiVersion: tekton.dev/v1beta1 kind: PipelineRun metadata: name: echo-pipeline-run spec: pipelineRef: name: echo-pipeline
Save this as
echo-pipeline-run.yaml
and apply it:kubectl apply -f echo-pipeline-run.yaml
Use
kubectl get pipelinerun
to check the status of the run.
Debugging and Logs
Tekton also enables easy debugging. To view the logs:
tkn pipelinerun logs echo-pipeline-run -f
Conclusion
Using Tekton on Linux with Bash gives you a robust, Kubernetes-native toolset to automate and manage your CI/CD pipelines effectively. By leveraging declarative YAML configurations, Tekton pipelines are clear, easy to manage, and version control. As you dive deeper into more complex workflows, Tekton's extensive capabilities consistently make it easier to scale and deploy across different environments seamlessly.
With this foundation, you are ready to customise and extend your pipelines further. Whether integrating advanced testing frameworks, deployment strategies, or multi-cloud operations, Tekton provides the flexibility and power needed for modern DevOps practices.