Getting started with Tekton

Blogpost #1

In this blog post, I’ll take you through the implementation of an automated process using Tekton. In collaboration with Sim Zacks 

What is Tekton? Tetkon is a cloud-native solution for building CI/CD pipelines. A standard CI/CD flow enables us to build, test, and deploy our applications, but it can also enable executing a number of tasks/steps for any application workflow, as I will describe in this post.

The goals This project has several goals 1: Automate dividing the team for coffee-break meetings 2: To understand if Tekton will work as a Jenkins alternative 3: To become familiar with the OpenShift environment

The process The first step - write a Python script We developed a Python script that takes a list of the names of the participants and randomly mixes them into groups, ensuring that people aren’t meeting with the same people two weeks in a row. It then writes the groups into a new text file. The final result is a set of groups that contain 3 - 4 participants each.

Second step - Gitlab Using Gitlab repository to store our files and clone to the repo and commit changes.

Third step-Tekton & OpenShift Using Tekton to build a pipeline that runs our application inside the Openshift environment.

How Tekton works A Task is a series of Steps that define what you want to do. Each step is executed in its own container.

apiVersion: tekton.dev/v1beta

kind: Task

metadata:

  name: Task_exmple

...

steps:

  - name: dump-directory

    image: alpine

    command:

      - /bin/sh

    args:

      - '-c'

      - |

        set -ex

        find /workspace

    resources: {}
        

And a Pipeline is a collection of Tasks, which can be executed in a specific order and can pass parameters between them.

apiVersion: tekton.dev/v1beta

kind: Pipeline

metadata:

  name:pipeline_example 

...

spec:

  params:

    - name: api-url

    - name: cloud-region

  tasks:

    - name: clone

       taskRef:

         name: git-clone

    - name: build

       taskRef:

         name: build        

Workflow In order to accomplish our mission we need to:

  • Download the coffee break repo from GitLab
  • Execute the python script
  • Send the results to the team via SMTP
  • Push the file we edited with the set of groups back to the repo

Tasks  Tekton hub is a site that contains numerous built-in tasks which are available to any user. This enables users, like us, to retrieve ready-made generic tasks that don't have to be developed or maintained.  In Tekton, tasks can be configured and available either for a specific project or available to anyone using the cluster as a “Cluster Task”.  For our project, we used both project tasks as well as cluster tasks.

Git Clone:  The purpose of this “Cluster Task” is to clone a repo and store the files on a PVC. Other Tasks can access and use the files 

PVC - It allows us shared storage that any Tasks can access and use the content

Execute- Coffee-Break:  This Task accesses the python script downloaded by the git clone task and runs it automatically. 

The results are stored in  a variable called “print-python-result”

spec

  results:

    - description: The groups

      name: print-python-result

  steps:

    - image: /python-36

      name: coffee

      resources: {}

      script: >

        #!/usr/bin/env bash




        python /workspace/output/coffee-break/breaks.py | tee

        $(results.print-python-result.path)

  workspaces:

    - name: output        

Then we can access it in the next task

Sendmail:  This task takes the variable "print-python-result" and sends it by email to all of our team from inside the task. We can also add parameters.

      params

        - name: subject

          value: D&O Coffee Breaks

        - name: body

          value: $(tasks.execute-coffee-break.results.print-python-result)

        - name: sender

          value:some@redhat.com

        - name: recipients

          value:someother@gmail.com:        

and we use SMTP to send to a mailing list that contains all of our team members.  SMTP  is an Internet network protocol that we use to send emails.

Git-Cli :  In the end, we use the Git-Cli Cluster Task to commit our changes back to the repo 

All of these tasks work well independently. We need to connect them with a pipeline to execute as a single flow.

The Pipeline  After we finish the creation of our tasks, we need to arrange them inside the Pipeline. This was a challenge.

Pipeline git clone PVC At the beginning, the other tasks did not see the git repo that the first task was cloned. After working on it for a while, we realized that we needed a common storage. We defined a PVC to solve this problem.

We then defined a common workspace in all the tasks, so they could access the PVC and the repo.

git-cli Finally, the push to the repo didn’t work because the git clone was unauthenticated. In order to get this to work, we had to create a secret with the team's username and password, and assign it to the gitlab server.

We then needed to create a Service Account that was connected to the secret. However, when we tried to run the pipeline in the GUI, we couldn’t find anywhere to choose a Service Account. We ended up using the tkn command line tool, in which you can assign a service account as the executor. After that, it all worked smoothly.

Summary 

In the end Tekton is a great tool for building a CI / CD pipeline  It very flexible and reusable and native for Kubernetes  Tekton hub has a bigger catalog of tasks that everyone can use  Even though documentation is well written, the lack of case studies, experiences, Q&As on forums, etc. makes it hard for new users There are also some problems with design.

Thank you for taking the time to read my blog. Be prepared for future and numerous blog posts. :) 

Comments are welcome.

To view or add a comment, sign in

Others also viewed

Explore content categories