Getting started with Tekton on Red Hat OpenShift
I recently heard about Tekton as an alternative for Jenkins on Red Hat OpenShift. What got my attention was that Tekton uses Operators as building blocks, and Operators are something I am also interested in. I don’t want to get ahead of myself, though; so we’ll start with installing Tekton on Red Hat OpenShift. Installing on Kubernetes is also possible, but for now the focus is on OpenShift.
Everything you need to grow your career.
With your free Red Hat Developer program membership, unlock our library of cheat sheets and ebooks on next-generation application development.SIGN UP
To install Tekton, you need to be cluster-admin on a Red Hat OpenShift cluster. The reason for that is that the Controller must run with
anyuid. Just have an OpenShift or Minishift cluster at your fingertips on which you can be cluster-admin.
We are going to use a dedicated project to install the Tekton Operators in:
oc new-project tekton-pipelines --display-name='Tekton Pipelines' oc adm policy add-scc-to-user anyuid -z tekton-pipelines-controller oc apply --filename https://storage.googleapis.com/tekton-releases/latest/release.yaml
This creates two deployments in the tekton-pipelines project, named
tekton-pipelines-webhook. It is fast to start up, but to see if the pods are running, use the following
oc command and wait for the ‘Running’ status:
oc get pods --namespace tekton-pipelines --watch
Use CTRL + C to exit watch mode.
Now that Tekton is running, we need to define a Task with steps saying what to do. We also need a TaskRun definition saying which Task to run. We need two yaml files for that. How the files are named does not really matter, but I am using the convention to end them with
A Task definition file named
apiVersion: tekton.dev/v1alpha1 kind: Task metadata: name: echo-hello-world-task spec: steps: - name: echo image: ubuntu command: - echo args: - "hello world"
And a TaskRun definition file named
apiVersion: tekton.dev/v1alpha1 kind: TaskRun metadata: name: echo-hello-world-task-run spec: taskRef: name: echo-hello-world-task
We will apply the two files with the following commands:
oc apply -f echo-hello-world-task.yaml oc apply -f echo-hello-world-task-run.yaml
As soon as both files are applied they will get directly executed. To follow the output of the TaskRun, use the command:
oc get taskruns/echo-hello-world-task-run -o yaml
Look through the output and search for:
status: conditions: - lastTransitionTime: 2019-07-08T18:48:15Z status: "True" type: Succeeded
If it looks almost the same as above, you have executed the first part of what will become a complete Tekton pipeline.