Using CI/CD Pipelines
CI/CD is "Continuous Integration and Continuous Delivery," an integral element of the DevOps world. Many projects provide CI/CD features in the Cloud Native world today, such as Flux, Argo CD, Jenkins, and Tekton.
OpenShift includes the Tekton open-source project of the Continuous Delivery Foundation to provide a complete CI/CD environment ready to use.
Install Tekton
To use CI/CD pipelines in OpenShift, your administrator must install the "Red Hat OpenShift Pipelines" operator and make it available to all namespaces. The operator appears in the "Operators" menu entry, and the kubeadmin user can install it on CRC using the default options by clicking on the Install button with default values. The installation of this operator can take a few minutes to complete, depending on the speed of your machine.
When the operator is ready, a "Pipelines" item appears in both the Developer and the Administrator perspectives of the OpenShift web console.
Tekton provides its command-line tool called "tkn." OpenShift users can download tkn directly from the "Command Line Tools" screen of the help menu.
Tekton is a complete CI/CD system, including the following concepts:
-
Tasks are individual operations, such as cloning source code repositories or building container images.
-
Pipelines are sets of tasks executed in sequence or parallel.
-
Workspaces are abstracted storage elements where tasks in a pipeline can share state.
Developers can create Tekton objects such as Tasks, Pipelines, and Workspaces using either YAML or the visual editor provided by the OpenShift web console.
Example
Once your administrator has enabled the Red Hat OpenShift Pipelines operator on your cluster, the developer user can use the same "Import from Git" option we used in the previous section.
This time, after entering the URL of the Git project you would like to deploy in the cluster, you will see a new section called "Pipelines," with a checkbox labeled "Add pipeline."
Check the checkbox and click the "Hide pipeline visualization" link to display the suggested pipeline structure.
The pipeline will first fetch the application’s source code; then, it will build it, generating a container image to be stored locally on your project. And finally, it will deploy it.
Leave all other options intact and click the Create button at the bottom of the screen.
After a few minutes, the "Topology" screen will display two icons; the first is your application, built and running; the second is an "Event Listener Sink" or "Pipeline Trigger," offering a publicly available URL. You can use this URL in the configuration of your project (for example, in GitHub or GitLab) to trigger the rebuild and redeployment of the project as soon as your code changes.
Tekton offers EventListener
and Trigger
objects that can be called from outside the cluster, for example, from GitHub or GitLab, so that each time your source code changes, a new PipelineRun starts, and you could even request a redeployment of your code in production.
However, if you use CRC, the trigger URL is a subdomain of the "apps-crc.testing" domain, only accessible from your local machine. There are ways to expose this URL using a reverse proxy such as ngrok, but such a task is outside of the scope of this course.
Also of interest, Tekton offers a Visual Studio Code extension to help developers create the YAML representations of Workspaces, Tasks, Pipelines, and other objects.
Inspecting the Pipeline
Click on the "Pipelines" entry on the left-hand side menu of the OpenShift web console. This screen displays the list of Tekton pipelines defined in the cluster at any time. It also conveniently shows the status of the pipeline; a full green bar means, of course, that the last execution of the pipeline was a success.
Select the item on the list with the same name as the application created previously. The "Pipeline details" screen shows the pipeline structure, which is precisely the same as seen once during the deployment creation.
The tab "PipelineRuns" contains the history of all the times when the pipeline was executed, including its status and result. Select the last item on that list and click on any pipeline steps. A new pane will show the logs of the execution of the pipeline, including all the operational records.
The branch 02_06 of the GitHub repository for this course contains an example of a CI/CD pipeline built with YAML files.
|