by John Turner
Posted on February 14, 2017
Kubernetes, Docker, Jenkins
Last week I spent some time learning how to utilize Kubernetes and Jenkins to form the foundation of a build infrastructure. I documented some of those learnings in the posts below:
This is a pretty good start but having built out VM based build infrastructure a number of times in the past I’m well aware that there is a long way to go before I have something I can use, manage and maintain. When working with VM’s I’ve perviously chosen to use Chef to manage and maintain the Jenkins master and slave hosts. Typically, Chef facilitated automation of the installation and configuration of:
To achieve the same level of automation with Docker and Kubernetes, I will need to be able to perform all of the above and distribute as a set of Kubernetes resource definition files and Docker image(s). Before we start doing anything meaningful, I want to disable the setup wizard because, after all, we will be automating the Jenkins setup. To do this I modify the Kubernetes deployment resource file to specify a JAVA_OPTS environment variable.
You can test this by creating the Kubernetes deployment and service as described in previous posts.
The next task is to replicate the installation of the recommended Jenkins plugins. To do this we must build our own docker image but first we will need to setup our local development environment.
Install the docker command line tool:
Configure your environment to use the Docker Host provided by minikube:
I will create a working directory in which I’ll store source files. The name is not important but I will call it docker-library/jenkins. This is where I will maintain all my docker images (there’s ambition for you!).
In this directory I’ll create a Dockerfile. The first statement I’ll add is the FROM statement which tells Docker which image my image will be based on. Naturally I will base my image on the official Jenkins image.
The documentation for the official docker image details how to install additional plugins. I found this not to work with the latest version of the image but found more recent instructions on the associated github readme which I verified did behave as expected. I was able to install additional plugins by adding the statement below to the Dockerfile.
In order to mimic exactly the behavior of the install wizard I wanted to install the recommended plugins, versions and their dependencies. The wizard retrieves the recommended plugins from a json file available from the Jenkins GitHub repository.
Lets build the docker image specifying the image name and version tag.
Learn about what happens during the build process by reading the Docker getting started guide.
Verify the image was created and uploaded to the minikube local registry as follows:
It’s important that when building the image that a tag is specified. If not specified Docker will attempt and fail to find the image on DockerHub.
Now that we have our docker image available in the minikube local docker registry we can update our kubernetes deployment resource file to specify our newly created image.
You can now create the kubernetes deployment (and service) and view the Jenkins UI in a browser to verify the default plugins have been installed. Next step is to automate the installation of the various required tools.