Chapter 7. Designing for Continuous Integration and Delivery
This chapter will show the reader how to integrate their build pipeline and deployments with a Kubernetes cluster. It will cover the concept of using gulp.js and Jenkins in conjunction with your Kubernetes cluster. We'll also use Helm and Minikube to show you another demo of how Continuous Integration and Delivery works with newer, more advanced methods.
The following topics will be covered in the chapter:
- Integrating Kubernetes with a Continuous Deployment pipeline
- Using gulp.js with Kubernetes
- Integrating Jenkins with Kubernetes
- Installing and using Helm and Jenkins
Integrating Kubernetes with a continuous delivery pipeline
Continuous integration and delivery are key components in modern development shops. Continuous Integration/Continuous Delivery (CI/CD) often easy to remove them after builds are run. In addition, if you already have a large portion of infrastructure available on your cluster, it can make sense to utilize the idle capacity for builds and testing.
In this article, we will explore two popular tools used in building and deploying software:
- gulp.js: This is a simple task runner used to automate the build process using JavaScript and Node.js
- Jenkins: This is a fully-fledged continuous integration server
gulp.js gives us the framework to do build as code. Similar to Infrastructure as code, this allows us to programmatically define our build process. We will walk through a short example to demonstrate how you can create a complete workflow, from a Docker image build through to the final Kubernetes service.
For this section of the article, you will need a Node.js environment installed and ready, including the node package manager (npm). If you do not already have these packages installed, you can find instructions for installing them at https://docs.npmjs.com/getting-started/installing-node.
You can check whether or not Node.js is installed correctly by using the node -v
command.
You'll also need Docker CE and a Docker Hub account to push a new image. You can find instructions to install Docker CE at https://docs.docker.com/installation/. You can easily create a DockerHub account at https://hub.docker.com/.
After you have your credentials, you can log in with...
The Kubernetes plugin for Jenkins
One way we can use Kubernetes for our CI/CD pipeline is to run our Jenkins build slaves in a containerized environment. Luckily, there is already a plugin, written by Carlos Sanchez, that allows you to run Jenkins slaves in Kubernetes' pods.
You'll need a Jenkins server handy for this next example. If you don't have one you can use, there is a Docker image available at https://hub.docker.com/_/jenkins/.
Running it from the Docker CLI is as simple as the following command:
docker run --name myjenkins -p 8080:8080 -v /var/jenkins_home jenkins
Log in to your Jenkins server, and from your home dashboard, click on Manage Jenkins
.
Note
A note for those installing a new Jenkins server: when you first log in to the Jenkins server, it asks you to install plugins. Choose the default ones, or no plugins will be installed!
Then, on the Manage Jenkins
page, select Manage Plugins
from the list, as follows:
The main dashboard in Jenkins
The credentials...
Let's try setting up some CI/CD with other tools, so we can experiment with the newest offerings in the Kubernetes ecosystem. First, let's explore how easy it is to install Jenkins with Helm.
First, open the Minikube dashboard so you can see what happens when we install various things. Do this with the following command:
$ minikube dashboard
Let's create a namespace for the Jenkins environment, as follows:
$ kubectl get namespaces
NAME STATUS AGE
default Active 3d
kube-public Active 3d
kube-system Active 3d
Now, let's create a template:
$ mkdir -p ~/gsw-k8s-helm && cd ~/gsw-k8s-helm
$ cat <<K8s >> namespace-jenkins.yaml
apiVersion: v1
kind: Namespace
metadata:
name: gsw-k8s-jenkins
K8s
Now, you can create the namespace as follows:
kubectl create -f namespace-jenkins.yaml
namespace "gsw-k8s-jenkins" created
There are two ways to verify that it was actually created. First, you can take a look at the dashboard with the minikube dashboard
command...
fabric8 bills itself as an integration platform. It includes a variety of logging, monitoring, and continuous delivery tools. It also has a nice console, an API registry, and a 3D game that lets you shoot at your pods. It's a very cool project, and it actually runs on Kubernetes. The website for the project can be found at http://fabric8.io/.
fabric8 can be set up easily on your Kubernetes cluster with just a single command, so refer to http://fabric8.io/guide/getStarted/gke.html/ for more information.
We looked at two continuous integration tools that can be used with Kubernetes. We did a brief walk-through, examining how to deploy the gulp.js task on our cluster. We also looked at a new plugin used to integrate Jenkins build slaves into your Kubernetes cluster. You should now have a better sense of how Kubernetes can integrate with your own CI/CD pipeline.
If you'd like some additional information on the Node.js and gulp.js ecosystems, check out these titles:
If you'd like some additional guidance on how to use Jenkins, read the following: