This project is no longer actively developed or maintained.
In this tutorial you will deploy a fully-functional implementation of the automated image building pipeline described in the Automated Image Builds with Jenkins, Packer, and Kubernetes solution paper.
You will use Google Kubernetes Engine and Kubernetes to deploy the environment.
If you follow these instructions exactly, you will deploy (2) g1-small GCE instances and a network load balancer, all resources that are billed for. It is very important that you follow the instructions to turn down the cluster if you do not want to continue to be billed for these resources. This calculator quote provides an estimate of the monthly cost of the resources provisioned in this example.
Be sure to create a brand new project for this tutorial (instructions are in the deploy sections below). Also be sure to complete the Delete the Deployment section when you're done. It's super quick and will tear down everything you created.
The instructions in this tutorial assume you have access to a terminal on a Linux or OS X host. For Windows hosts, Cygwin should work.
You will need to enter commands in your terminal. Those commands are indicated in the following format, where $
indicates a prompt (do not paste the $ into your terminal, just everything that follows it):
$ echo "This is a sample command"
Before you deploy the sample you'll need to make sure a few things are in order:
Create a new project in the Google Developer Console and note the new project's ID.
In the APIs & Auth section of the Google Developers Console of your new project, enable the following APIs:
Install the Cloud SDK verssion 0.9.68
or greater using these instructions.
Authenticate to gcloud:
$ gcloud auth login
Set your project:
$ gcloud config set project YOUR_PROJECT_ID
Enable kubernetes
features:
$ gcloud components update kubectl
If you are using Windows to complete the tutorial, install Cygwin and execute the steps in a terminal.
These quick deploy instructions are easiest way to get started. The work to create a Google Kubernetes Engine cluster and launch the necessary Kubernetes resources is captured in the cluster_up.sh
script.
To quick deploy the image builder application:
Clone this repository ($ git clone https://github.com/GoogleCloudPlatform/kube-jenkins-imager.git
) or download and unzip a copy from releases.
Navigate to the directory:
$ cd kube-jenkins-imager
From a terminal in the directory you cloned or unzipped, run:
$ ./cluster_up.sh
The script will take several minutes to complete. The abbreviated output should look similar to:
Creating cluster imager...done.
...
...
<TRUNCATED>
...
...
All resources deployed.
Continue to the Access Jenkins section (skip the Stepwise Deploy section)
You can find open the cluster_up.sh
script and execute the commands from each line for a closer look at everything that's taking place.
Access the URL output when you created your deployment. Click the login button and use the username and password
that was output by the cluster_up.sh
script:
After a successful login you should see the Jenkins admin landing page:
In the following sections you will create a credential, define and run an image build job, and backup the Jenkins configuration.
Optional: Configure a Jenkins login (in addition to the basic access authentication at the reverse proxy) by navigating to Manage Jenkins >> Configure Global Security and configuring authentication and authorization settings to your requirements
Create a credential by clicking on the Credentials link in the left nav, then clicking the Global credentials link:
Click Add Credentials in the left nav, choose Google Service Account from metadata
in the Kind dropdown, and click OK. The Project Name will be auto-populated:
In the following sections you will clone an existing repo (from the previous Scalable and Resilient Web Applications tutorial that includes a working build configuration. You will then push that repo to your project's Cloud Repository, create a Jenkins job to build it, and run the job.
Clone the existing sample repository to your workstation (you must have git
installed) and go into the new directory:
$ git clone https://github.com/GoogleCloudPlatform/scalable-resilient-web-app.git
$ cd scalable-resilient-web-app
Create a Cloud Source Repository and push your code to it:
$ gcloud source repos create scalable-resilient-web-app
$ git config --global credential.https://source.developers.google.com.helper gcloud.sh
$ export PROJECT=$(gcloud config get-value project)
$ git remote add google https://source.developers.google.com/p/${PROJECT}/r/scalable-resilient-web-app
$ git push --all google
After you've pushed your files to the Cloud Source Repository, find and copy its Fetch URL for use in the next section:
$ git remote -v show -n google | grep Fetch
Fetch URL: https://source.developers.google.com/p/your-new-project/
Note: The URL should be your project ID appended to the string https://source.developers.google.com/p/
Access Jenkins in your browser. If you don't remember the URL, you can run the following command in the terminal where you created the deployment to find it:
$ echo http://$(kubectl get service cd-jenkins -o "jsonpath={.status.loadBalancer.ingress[0].ip}")
From the Jenkins main page, choose *New Item, name the item redmine-immutable-image
, choose Pipeline, then click OK. It is important the name does not include spaces.
Under Build Triggers, choose Poll SCM and enter a value for Schedule. In this example, H/5 * * * *
will poll the repository every 5 minutes. Choose a value that you consider appropriate:
Under Pipeline, in the Definition dropdown choose Pipeline script from SCM.
Paste your Cloud Repository URL (https://source.developers.google.com/p/your-project-id
) from the previous section, and choose the credential you created earlier from the dropdown:
Click Save to save your job.
After saving the project, choose the Build Now menu item, then click the job number when it appears:
Choose the Console Output menu item and observe the job's progress:
Jenkins parallelizes the GCE and Docker builds. You can expect the build to take about 20 minutes; the sample build is updating the OS, building and installing Ruby, and installing the Redmine project management application and all of its gem dependencies.
The build is done when you see a Finished: SUCCESS
line in the output. A few lines before that you should see the outputs (GCE and Docker iamges) of the build:
==> Builds finished. The artifacts of successful builds are:
--> googlecompute: A disk image was created: redmine-1431028076-master-c84d21f
--> docker: Imported Docker image: 0717053a7fce3c637a5bfd887954f41b4327e80493eb6492277e2dbb132c2bf4
--> docker: Imported Docker image: gcr.io/your-new-project/redmine:master-c84d21f
...
...
Finished: SUCCESS
In the Google Developers Console navigate to Compute > Images and confirm that your GCE image for Redmine is there:
It is very important (as mentioned in the Very Important Things section of this document) that you delete your deployment when you are done. You will be charged for any running resources.
Whether you followed the Quick Deploy or Stepwise Deploy instructions, deleting resources is very easy. Simply delete the project you created at the beginning of this tutorial: