Reader small image

You're reading from  Getting Started with Kubernetes, - Third Edition

Product typeBook
Published inOct 2018
PublisherPackt
ISBN-139781788994729
Edition3rd Edition
Concepts
Right arrow
Authors (2):
Jonathan Baier
Jonathan Baier
author image
Jonathan Baier

Jonathan Baier is an emerging technology leader living in Brooklyn, New York. He has had a passion for technology since an early age. When he was 14 years old, he was so interested in the family computer (an IBM PCjr) that he pored over the several hundred pages of BASIC and DOS manuals. Then, he taught himself to code a very poorly-written version of Tic-Tac-Toe. During his teenage years, he started a computer support business. Throughout his life, he has dabbled in entrepreneurship. He currently works as Senior Vice President of Cloud Engineering and Operations for Moody's corporation in New York.
Read more about Jonathan Baier

Jesse White
Jesse White
author image
Jesse White

Jesse White is a 15-year veteran and technology leader in New York City's very own Silicon Alley, where he is a pillar of the vibrant engineering ecosystem. As founder of DockerNYC and an active participant in the open source community, you can find Jesse at a number of leading industry events, including DockerCon and VelocityConf, giving talks and workshops.
Read more about Jesse White

View More author details
Right arrow

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

Technical requirements


You'll need to have your Google Cloud Platform account enabled and logged in, or you can use a local Minikube instance of Kubernetes. You can also use the Play with Kubernetes app, designed for use over the web, at https://labs.play-with-k8s.com/.

Here's the GitHub repository for this chapter: https://github.com/PacktPublishing/Getting-Started-with-Kubernetes-third-edition/tree/master/Code-files/Chapter07.

 

 

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


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.

Prerequisites

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.

Prerequisites

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

Installing plugins

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...

Helm and Minikube


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...

Bonus fun


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.

Summary


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.

Questions


  1. What type of software does gulp.js enable us to build?
  2. What is the name of the popular CI/CD system that we installed?
  3. What is an alternative method of installation for Jenkins?
  4. What type of volume is required to run Jenkins on Kubernetes?
  5. What is the other requirement for running Jenkins on Kubernetes?
  6. What kind of controller is used when deploying with gulp.js?
  7. What tool did we use to install gulp.js?
lock icon
The rest of the chapter is locked
You have been reading a chapter from
Getting Started with Kubernetes, - Third Edition
Published in: Oct 2018Publisher: PacktISBN-13: 9781788994729
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 $15.99/month. Cancel anytime

Authors (2)

author image
Jonathan Baier

Jonathan Baier is an emerging technology leader living in Brooklyn, New York. He has had a passion for technology since an early age. When he was 14 years old, he was so interested in the family computer (an IBM PCjr) that he pored over the several hundred pages of BASIC and DOS manuals. Then, he taught himself to code a very poorly-written version of Tic-Tac-Toe. During his teenage years, he started a computer support business. Throughout his life, he has dabbled in entrepreneurship. He currently works as Senior Vice President of Cloud Engineering and Operations for Moody's corporation in New York.
Read more about Jonathan Baier

author image
Jesse White

Jesse White is a 15-year veteran and technology leader in New York City's very own Silicon Alley, where he is a pillar of the vibrant engineering ecosystem. As founder of DockerNYC and an active participant in the open source community, you can find Jesse at a number of leading industry events, including DockerCon and VelocityConf, giving talks and workshops.
Read more about Jesse White