Skip to content

zvigrinberg/Tekton-pipelines

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 

Repository files navigation

Tekton-pipelines

  • This repo will contain both tekton tasks and pipelines

  • This repo will contain also Triggers, TriggerBindings, TriggerTemplates and EventListeners.

Prerequisites:

You'll need an openshift or k8 cluster, if you don't have access to such, you can create a 1 node local kubernetes cluster using minikube or kubernetes cluster in a container using kind

Install Tekton Pipelines

  • To install Tekton after connecting to the cluster, run the following:
kubectl apply --filename \
https://storage.googleapis.com/tekton-releases/pipeline/latest/release.yaml
  • See progression of installation
kubectl get pods -n tekton-pipelines -w

Create a sample task and taskRun

cat > task-example.yaml << EOF
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
  name: hello
spec:
  steps:
    - name: echo
      image: alpine
      script: |
        #!/bin/sh
        echo "Hello World"
EOF

kubectl apply -f task-example.yaml 
cat > taskRun-example.yaml << EOF
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
  name: hello-task-run
spec:
  taskRef:
    name: hello
EOF
kubectl apply -f taskRun-example.yaml 
  • See a status of the taskRun object:
kubectl get taskrun hello-task-run
  • See logs of the taskRun
kubectl logs --selector=tekton.dev/taskRun=hello-task-run

Create a sample pipeline and pipelineRun

  • Create a goodbye task
cat > goodbye-world.yaml << EOF
   apiVersion: tekton.dev/v1beta1
   kind: Task
   metadata:
   name: goodbye
   spec:
   params:
   - name: username
   type: string
   steps:
   - name: goodbye
   image: ubuntu
   script: |
   #!/bin/bash
   echo "Goodbye \$(params.username)!"
   EOF
  • Apply it to the cluster
kubectl apply -f goodbye-world.yaml
  • Create a pipeline resource, and apply it to the cluster
cat > hello-goodbye-pipeline.yaml << EOF
   apiVersion: tekton.dev/v1beta1
   kind: Pipeline
   metadata:
   name: hello-goodbye
   spec:
   params:
   - name: username
   type: string
   tasks:
   - name: hello
   taskRef:
   name: hello
   - name: goodbye
   runAfter:
   - hello
   taskRef:
   name: goodbye
   params:
   - name: username
   value: \$(params.username)
   EOF

   kubectl apply --filename hello-goodbye-pipeline.yaml
  • Create a pipelineRun resource to run pipeline:
cat > hello-goodbye-pipeline-run.yaml << EOF
   apiVersion: tekton.dev/v1beta1
   kind: PipelineRun
   metadata:
   name: hello-goodbye-run
   spec:
   pipelineRef:
   name: hello-goodbye
   params:
   - name: username
   value: "Tekton"
   EOF
   
   kubectl apply --filename hello-goodbye-pipeline-run.yaml
  • Follow logs of pipelineRun by entering the following command:
tkn pipelinerun logs hello-goodbye-run -f -n default

Create a sample EventListener , TriggerTemplate and TriggerBinding

  • First, if not installed, install Tekton Triggers:
kubectl apply --filename https://storage.googleapis.com/tekton-releases/triggers/latest/release.yaml
kubectl apply --filename https://storage.googleapis.com/tekton-releases/triggers/latest/interceptors.yaml

# Watch the progress of installation, until everything is finished.
kubectl get pods --namespace tekton-pipelines --watch
  • Create A TriggerTemplate instance to connect Pipeline to the Trigger emitted by EventListener
cat > trigger-template.yaml << EOF
   apiVersion: triggers.tekton.dev/v1beta1
   kind: TriggerTemplate
   metadata:
   name: hello-template
   spec:
   params:
   - name: username
   default: "Kubernetes"
   resourcetemplates:
   - apiVersion: tekton.dev/v1beta1
   kind: PipelineRun
   metadata:
   generateName: hello-goodbye-run-
   spec:
   pipelineRef:
   name: hello-goodbye
   params:
   - name: username
   value: \$(tt.params.username)
   EOF
   kubectl apply -f trigger-template.yaml
   
  • Create A TriggerBinding that will parse the parameters from the event payload and assign them to the TriggerTemplate's parameters:
cat > trigger-binding.yaml << EOF
apiVersion: triggers.tekton.dev/v1beta1
kind: TriggerBinding
metadata:
  name: hello-binding
spec: 
  params:
  - name: username
    value: \$(body.username)
EOF

kubectl apply -f trigger-template.yaml
  • Create an EventListener that will Listen to request using webhooks , and will create events/triggers, and will connect them to the created TriggerTemplate and TriggerBinding resources just created:
kubectl apply -f trigger-binding.yaml
   cat > event-listener.yaml << EOF
   apiVersion: triggers.tekton.dev/v1beta1
   kind: EventListener
   metadata:
   name: hello-listener
   spec:
   serviceAccountName: tekton-robot
   triggers:
   - name: hello-trigger
   bindings:
   - ref: hello-binding
   template:
   ref: hello-template
   EOF
   
  • Create RBAC permissions for all operations:
cat > rbac.yaml << EOF
   apiVersion: v1
   kind: ServiceAccount
   metadata:
   name: tekton-robot
   ---
   apiVersion: rbac.authorization.k8s.io/v1
   kind: RoleBinding
   metadata:
   name: triggers-example-eventlistener-binding
   subjects:
   - kind: ServiceAccount
   name: tekton-robot
   roleRef:
   apiGroup: rbac.authorization.k8s.io
   kind: ClusterRole
   name: tekton-triggers-eventlistener-roles
   ---
   apiVersion: rbac.authorization.k8s.io/v1
   kind: ClusterRoleBinding
   metadata:
   name: triggers-example-eventlistener-clusterbinding
   subjects:
   - kind: ServiceAccount
   name: tekton-robot
   namespace: default
   roleRef:
   apiGroup: rbac.authorization.k8s.io
   kind: ClusterRole
   name: tekton-triggers-eventlistener-clusterroles
   EOF
   
    kubectl apply -f rbac.yaml
  • Only In case Istio is enabled in the cluster, you need to disable automatic sidecar injection to default namespace:
kubectl label namespace default istio-injection=disabled --overwrite
  • Create The EventListener in the cluster:
kubectl apply -f event-listener.yaml
  • In a new window, Expose and forward port 8080 of service el-hello-listener to client' host
kubectl port-forward svc/el-hello-listener 8080
  • Invoke the webhook endpoint(listened by EventListener' pod):
curl -v -H 'content-Type: application/json' -d '{"username": "Tekton"}' http://localhost:8080
  • See logs of pipelines that was activated:
   kubectl get pipelineruns -w
   kubectl logs hello-goodbye-run-bb6gs
   kubectl describe pipelinerun hello-goodbye-run-bb6gs
   tkn pipelinerun logs hello-goodbye-run-bb6gs -f

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published