An overview of the
Tekton is a powerful and flexible open source framework for building CI/CD pipeline systems, allowing developers to build, test, and publish applications. Tekton is cloud native and allows users to quickly and flexibly define pipelines by defining CRD.
Benefits of using Tekton
- Customizable: Tekton entities are fully customizable, resulting in a high degree of flexibility. Platform engineers can define very detailed build base directories that developers can use in a variety of situations
- Reusable: Tekton entities are fully portable, so once defined, anyone within an organization can use a given pipe and reuse its building blocks. This allows developers to quickly build complex pipes without having to “reinvent the wheel.”
- Extensible: The Tekton Catalog is a Tekton community-driven repository. You can quickly create new and expand existing pipes using prefabricated components in the Tekton directory.
- Standardization: Tekton is installed and running as an extension on your Kubernetes cluster and uses the well-established Kubernetes resource model. The Tekton workload executes in a Kubernetes container.
- Scaling: To increase workload capacity, you can simply add nodes to the cluster. Tekton scales with your cluster without redefining your resource allocation or any other modifications to the pipeline
Components in Tekton
- Tekton Pipelines: The foundation of Tekton, defines a set of CRDS, used to define Pipelines
- Tekton Triggers: Allows pipeline instantiation based on events. For example, git pr requests
- Tekton Cli: provides command line tools to interact with Tekton
- Tekton Dashboard: Graphical interface to display pipeline information
- Tekton Catalog: A high-quality, community-contributed pipeline repository
- Tekton Hub: Graphical interface to access Tekton Catalog
- Tekton Operator: A project to install, remove, and update Tekton components on K8S
Tekton refers exclusively to Tekton Pipeline components unless otherwise noted
The basic concept
The five most important concepts of Tekton are Task, TaskRun, Pipeline, PipelineRun, PipelineResources
- Task: The smallest unit in Tekton that represents a Task template and consists of multiple steps. Each operation is defined as a step in the Task
- Pipeline: Directed acyclic graph composed of multiple tasks, defining the template of the Pipeline
- PipelineRun: When a Pipeline is actually executed, a PipelineRun is defined as an instance of the pipelining that generates a pipelining record
- TaskRun: indicates the actual execution instance of a Task, which records the Task status. A TaskRun creates a corresponding Pod, with each step corresponding to a Container within the Pod
- PipelineResource: Resource information required during pipelining execution
The installation
The image on GCR. IO will be used during installation, and the Docker agent needs to be configured. Centos7, for example
mkdir /etc/systemd/system/docker.service.d cat <<EOF > /etc/systemd/system/docker.service.d/http-proxy.conf [Service] [Service] The Environment = "HTTP_PROXY = http://192.168.0.119:3128" Environment = "HTTPS_PROXY = http://192.168.0.119:3128" Environment = "NO_PROXY = localhost, 127.0.0.1, localaddress, localdomain.com" EOF systemctl daemon-reload && systemctl restart docker Copy the code
Prerequisites:
- K8s cluster version >= 1.15
- Start the cluster RBAC
- Grant the cluster-admin role to the current user
Installing the Controller
kubectl apply --filename https://storage.googleapis.com/tekton-releases/pipeline/latest/release.yaml
Copy the code
The configuration
kubectl create configmap config-artifact-pvc \
--from-literal=size=10Gi \
--from-literal=storageClassName=rook-ceph-block \
-o yaml -n tekton-pipelines \
--dry-run=client | kubectl replace -f -
Copy the code
Install the dashboard
kubectl apply --filename https://github.com/tektoncd/dashboard/releases/latest/download/tekton-dashboard-release.yaml
Copy the code
Configuration ingress
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: tekton-dashboard
namespace: tekton-pipelines
spec:
rules:
- host: tekton.demo.com
http:
paths:
- backend:
serviceName: tekton-dashboard
servicePort: 9097
Copy the code
kubectl apply -f ingress.yaml -n tekton-pipelines
Copy the code
check
kubectl get pods --namespace tekton-pipelines
Copy the code
Dashboard page
HelloWorld
This example executes a command line output Hello World
Define the Task
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: hello
spec:
steps:
- name: hello
image: ubuntu
command:
- echo
args:
- "Hello World!"
Copy the code
To perform a task
# to perform
➜ helloworld sudo kubectl apply -f task.yaml
Password:
task.tekton.dev/hello created
# check
➜ helloworld sudo kubectl get task
NAME AGE
hello 65s
Copy the code
Define TaskRun
To run the previous Task in Tekton, you need to define a TaskRun
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
generateName: hello-run-
spec:
taskRef:
name: hello
Copy the code
The TaskRun metadata defines generateName, which means that a name prefixed with generateName is automatically generated each time a task is created.
This execution must use Kubectl create. Using Kubectl apply will cause an error
Use kubectl apply to get an error
➜ sudo kubectl apply -f taskrun.yaml
error: from hello-run-: cannot use generate name with apply
Execute using kubectl create
➜ sudo kubectl create -f taskrun.yaml
taskrun.tekton.dev/hello-run-8lkcl created
# see taskrun
➜ sudo kubectl get taskrun
NAME SUCCEEDED REASON STARTTIME COMPLETIONTIME
hello-run-8lkcl True Succeeded 2m25s 2m11s
Copy the code
Viewing the Execution Result
View the Pod of the task
TaskRun automatically pulled up a Pod and Completed successfully with the status being Completed
NAME READY STATUS RESTARTS AGE
ast-slave-test 1/1 Running 0 2d5h
hello-run-8lkcl-pod-pdrv9 0/1 Completed 0 5m38s
Copy the code
View the pod log file
➜ sudo kubectl logs hello-run-8lkcl-pod-pdrv9
Hello World!
Copy the code
Look at the pod choreography file: the command echo hello World is specified in the container defined in pod
# kubectl get pod hello-run-8lkcl-pod-pdrv9 -oyaml
apiVersion: v1
kind: Pod
metadata:
.
name: hello-run-8lkcl-pod-pdrv9
namespace: default
spec:
containers:
- args:
- -wait_file
- /tekton/downward/ready
- -wait_file_content
- -post_file
- /tekton/tools/0
- -termination_path
- /tekton/termination
- -entrypoint
- echo
- --
- Hello World!
command:
- /tekton/tools/entrypoint
env:
- name: HOME
value: /tekton/home
image: ubuntu
imagePullPolicy: Always
name: step-hello
.
initContainers:
- command:
- /ko-app/entrypoint
- cp
- /ko-app/entrypoint
- /tekton/tools/entrypoint
image: gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/entrypoint:v0.23.0@sha256:5489d6a444ff63b14d94dead8cc10b221ec147 cd817b18254dbf28f3d70f4fa5
imagePullPolicy: IfNotPresent
name: place-tools
.
Copy the code