Reader small image

You're reading from  Building CI/CD Systems Using Tekton

Product typeBook
Published inSep 2021
PublisherPackt
ISBN-139781801078214
Edition1st Edition
Right arrow
Author (1)
Joel Lord
Joel Lord
author image
Joel Lord

Joel Lord (joel__lord on Twitter) is passionate about the web and technology in general. He likes to learn new things, but most of all, he wants to share his discoveries. He does so by traveling to various conferences all across the globe. He graduated from college with a degree in computer programming in the last millennium. Apart from a little break to get his BSc in computational astrophysics, he has always worked in the industry. In his daily job, Joel is a developer advocate with MongoDB, where he connects with software engineers to help them make the web better by using best practices around JavaScript. In his free time, he can be found stargazing on a campground somewhere or brewing a fresh batch of beer in his garage.
Read more about Joel Lord

Right arrow

Chapter 12: Preparing for a New Pipeline

You've learned everything you need to start building your cloud-native CI/CD pipelines using Tekton. You even know how to automate this process using Tekton Triggers. Up to this point, all the examples were simple. Most of your tasks simply output to the console, and your pipelines didn't have actual use cases.

The time has finally come to start putting everything together and build a real pipeline that you could use in the real world. First, you will start with a clean slate. You will delete everything you have done so far and start with a fresh minikube installation. From there, you will install all the required libraries and get ready to start fresh.

Once your environment is ready, you will clone a code repository and explore the source of an application that is to be deployed in your local cluster. You will then go through the steps of making a change in your code base and deploy the application to your cluster manually...

Technical requirements

Check out the following link to see the Code in Action video: https://bit.ly/3eUvkgM

Cleaning up your cluster

Assuming you are not starting the book at this chapter, your cluster probably has many tasks, pipelines, runs, and other Tekton-related objects in it. To reproduce an authentic environment where you would deploy your pipeline, you will need to start from a clean slate. In this section, you will remove everything you've created so far. In fact, you will go as far as completely deleting your cluster and creating a fresh new one. To do so, from your terminal, stop minikube:

$ minikube stop 
 Stopping node "minikube" ... 
 1 nodes stopped. 

Once minikube is stopped, you can delete the virtual machine used by minikube to store your Kubernetes cluster. This will ensure that you start from a brand new cluster the next time you start this tool:

$ minikube delete 
🔥 Deleting "minikube" in kvm2 ... 
💀 Removed all traces of the "minikube" cluster. 

Your cluster has officially been destroyed. You can now restart...

Installing the necessary tooling

Your cluster is now ready to use, but you should get an error message if you run the tkn version command. This error is due to the fact that by deleting everything in your cluster, you also deleted all the CRDs necessary for Tekton.

For this reason, you need to reinstall Tekton, Tekton Triggers, and make some adjustments to your cluster to ensure that you will be able to run those tools.

First, start by installing Tekton by applying the appropriate file to your cluster with kubectl:

 $ kubectl apply --filename https://storage.googleapis.com/tekton-releases/pipeline/latest/release.yaml 

Next, install the necessary CRDs for Tekton Triggers using kubectl:

$ kubectl apply -f https://storage.googleapis.com/tekton-releases/triggers/latest/release.yaml 
$ kubectl apply -f https://storage.googleapis.com/tekton-releases/triggers/latest/interceptors.yaml 

To build your triggers, you will need to create a service account, just like you did...

Exploring the source code

You are now ready to deploy your application, but you should know a little bit more about the code you are about to deploy before you do so. While you could use the following pipelines with any Node.js project, it will be easier to follow along if you have the same code samples.

Start by forking the code repository found at https://github.com/PacktPublishing/tekton-book-app. It is crucial that you create your own fork, so you'll be able to add your webhooks to connect to your trigger. Once your fork is ready, clone the repository, and use the cd command to get into this new folder:

$ git clone git@github.com:<YOUR_USERNAME>/tekton-book-app.gitgit@github.com:<YOUR_USERNAME>/tekton-book-app.git 
Cloning into 'tekton-book-app'... 
remote: Enumerating objects: 36, done. 
remote: Counting objects: 100% (36/36), done. 
remote: Compressing objects: 100% (24/24), done. 
remote: Total 36 (delta 14), reused 30 (delta 8), pack-reused...

Updating the application manually

Now that the application is up and running in a Kubernetes cluster, it is time to change the code base and update this application with the new version. Doing this update by hand will help you identify the parts that you can automate.

First, make a change in a file. Change the response to the "/" route in server.js to return a different response:

app.get("/", (req, res) => {
  res.send({ 
    message: "Hello", 
    change: "changed" 
  }).status(200);
});

Commit that change and push it to your code repository:

$ git commit -am "Change a server response" 
$ git push origin main 

Run the tests and linting to ensure that everything passes:

$ npm run test 
$ npm run lint 

Build a new image and push it to your registry:

$ docker build –t <YOUR_USERNAME>/tekton-lab-app . 
$ docker push <YOUR_USERNAME...

Summary

In this chapter, you've explored the code base for the application for which you will write a CI/CD pipeline. You've seen how this application has a test suite and some linting that should be done before deploying a new version.

You have also seen how to use Docker to build the image and then use kubectl to deploy this image to your cluster.

The most critical part of this chapter was the last section. In there, you saw the manual steps that are needed to deploy a new version of this application to your cluster. Of these steps, it is easy for someone to neglect running the test suite and accidentally push some broken code into your cluster. This is why automating these steps is crucial to deploying code faster.

In the next chapter, you will see how to build your Tekton CI/CD pipeline to automate this process.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Building CI/CD Systems Using Tekton
Published in: Sep 2021Publisher: PacktISBN-13: 9781801078214
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Author (1)

author image
Joel Lord

Joel Lord (joel__lord on Twitter) is passionate about the web and technology in general. He likes to learn new things, but most of all, he wants to share his discoveries. He does so by traveling to various conferences all across the globe. He graduated from college with a degree in computer programming in the last millennium. Apart from a little break to get his BSc in computational astrophysics, he has always worked in the industry. In his daily job, Joel is a developer advocate with MongoDB, where he connects with software engineers to help them make the web better by using best practices around JavaScript. In his free time, he can be found stargazing on a campground somewhere or brewing a fresh batch of beer in his garage.
Read more about Joel Lord