• This repository has been archived on 20/Sep/2022
  • Stars
    star
    261
  • Rank 150,987 (Top 4 %)
  • Language
    Shell
  • License
    Apache License 2.0
  • Created almost 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

This project is no longer actively developed or maintained.

Automated Image Builder with Jenkins, Packer, and Kubernetes

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.

Very Important Things

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.

Conventions

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"

Deploy

Deployment Requirements

Before you deploy the sample you'll need to make sure a few things are in order:

  1. Create a new project in the Google Developer Console and note the new project's ID.

  2. In the APIs & Auth section of the Google Developers Console of your new project, enable the following APIs:

    • Google Compute Engine
    • Google Kubernetes Engine API
    • Cloud Build API
  3. Install the Cloud SDK verssion 0.9.68 or greater using these instructions.

  4. Authenticate to gcloud:

    $ gcloud auth login
  5. Set your project:

    $ gcloud config set project YOUR_PROJECT_ID
  6. Enable kubernetes features:

    $ gcloud components update kubectl
  7. If you are using Windows to complete the tutorial, install Cygwin and execute the steps in a terminal.

Quick Deploy

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:

  1. Clone this repository ($ git clone https://github.com/GoogleCloudPlatform/kube-jenkins-imager.git) or download and unzip a copy from releases.

  2. Navigate to the directory:

    $ cd kube-jenkins-imager
  3. 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.
  4. Continue to the Access Jenkins section (skip the Stepwise Deploy section)

Stepwise Deploy

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 Jenkins

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

  2. After a successful login you should see the Jenkins admin landing page:

Configure Jenkins

In the following sections you will create a credential, define and run an image build job, and backup the Jenkins configuration.

Create Credentials

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

  2. Create a credential by clicking on the Credentials link in the left nav, then clicking the Global credentials link:

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

Create and Run a Build Job

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.

Replicate a GitHub Repo

  1. 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
  2. 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
  3. 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/

Create Jenkins Job

  1. 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}")
  2. 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.

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

  4. Under Pipeline, in the Definition dropdown choose Pipeline script from SCM.

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

  6. Click Save to save your job.

Run the Build

  1. After saving the project, choose the Build Now menu item, then click the job number when it appears:

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

  1. 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
  2. In the Google Developers Console navigate to Compute > Images and confirm that your GCE image for Redmine is there:

Delete the Deployment

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:

  1. Navigate to the Projects page of the Google Developer Console, find your project, click the trash can icon to delete, then type the project ID and click Delete Project.

More Repositories

1

microservices-demo

Sample cloud-first application with 10 microservices showcasing Kubernetes, Istio, and gRPC.
Go
15,783
star
2

terraformer

CLI tool to generate terraform files from existing infrastructure (reverse Terraform). Infrastructure to Code
Go
11,610
star
3

training-data-analyst

Labs and demos for courses for GCP Training (http://cloud.google.com/training).
Jupyter Notebook
7,479
star
4

python-docs-samples

Code samples used on cloud.google.com
Jupyter Notebook
6,985
star
5

generative-ai

Sample code and notebooks for Generative AI on Google Cloud
Jupyter Notebook
5,282
star
6

golang-samples

Sample apps and code written for Google Cloud in the Go programming language.
Go
4,136
star
7

nodejs-docs-samples

Node.js samples for Google Cloud Platform products.
JavaScript
2,762
star
8

tensorflow-without-a-phd

A crash course in six episodes for software developers who want to become machine learning practitioners.
Jupyter Notebook
2,735
star
9

professional-services

Common solutions and tools developed by Google Cloud's Professional Services team. This repository and its contents are not an officially supported Google product.
Python
2,730
star
10

gcsfuse

A user-space file system for interacting with Google Cloud Storage
Go
1,977
star
11

community

Java
1,908
star
12

PerfKitBenchmarker

PerfKit Benchmarker (PKB) contains a set of benchmarks to measure and compare cloud offerings. The benchmarks use default settings to reflect what most users will see. PerfKit Benchmarker is licensed under the Apache 2 license terms. Please make sure to read, understand and agree to the terms of the LICENSE and CONTRIBUTING files before proceeding.
Python
1,855
star
13

java-docs-samples

Java and Kotlin Code samples used on cloud.google.com
Java
1,610
star
14

ml-design-patterns

Source code accompanying O'Reilly book: Machine Learning Design Patterns
Jupyter Notebook
1,600
star
15

continuous-deployment-on-kubernetes

Get up and running with Jenkins on Google Kubernetes Engine
Shell
1,582
star
16

cloudml-samples

Cloud ML Engine repo. Please visit the new Vertex AI samples repo at https://github.com/GoogleCloudPlatform/vertex-ai-samples
Python
1,507
star
17

asl-ml-immersion

This repos contains notebooks for the Advanced Solutions Lab: ML Immersion
Jupyter Notebook
1,469
star
18

localllm

Python
1,449
star
19

cloud-builders

Builder images and examples commonly used for Google Cloud Build
Go
1,354
star
20

cloud-foundation-fabric

End-to-end modular samples and landing zones toolkit for Terraform on GCP.
HCL
1,343
star
21

vertex-ai-samples

Sample code and notebooks for Vertex AI, the end-to-end machine learning platform on Google Cloud
Jupyter Notebook
1,331
star
22

cloud-builders-community

Community-contributed images for Google Cloud Build
Go
1,233
star
23

data-science-on-gcp

Source code accompanying book: Data Science on the Google Cloud Platform, Valliappa Lakshmanan, O'Reilly 2017
Jupyter Notebook
1,230
star
24

berglas

A tool for managing secrets on Google Cloud
Go
1,223
star
25

cloud-sql-proxy

A utility for connecting securely to your Cloud SQL instances
Go
1,218
star
26

kubernetes-engine-samples

Sample applications for Google Kubernetes Engine (GKE)
HCL
1,178
star
27

functions-framework-nodejs

FaaS (Function as a service) framework for writing portable Node.js functions
TypeScript
1,162
star
28

cloud-vision

Sample code for Google Cloud Vision
Python
1,093
star
29

DataflowTemplates

Cloud Dataflow Google-provided templates for solving in-Cloud data tasks
Java
1,078
star
30

bigquery-utils

Useful scripts, udfs, views, and other utilities for migration and data warehouse operations in BigQuery.
Java
1,030
star
31

php-docs-samples

A collection of samples that demonstrate how to call Google Cloud services from PHP.
PHP
944
star
32

buildpacks

Builders and buildpacks designed to run on Google Cloud's container platforms
Go
937
star
33

deploymentmanager-samples

Deployment Manager samples and templates.
Jinja
928
star
34

bank-of-anthos

Retail banking sample application showcasing Kubernetes and Google Cloud
Java
926
star
35

cloud-foundation-toolkit

The Cloud Foundation toolkit provides GCP best practices as code.
Go
916
star
36

flask-talisman

HTTP security headers for Flask
Python
896
star
37

DataflowJavaSDK

Google Cloud Dataflow provides a simple, powerful model for building both batch and streaming parallel data processing pipelines.
857
star
38

gsutil

A command line tool for interacting with cloud storage services.
Python
857
star
39

k8s-config-connector

GCP Config Connector, a Kubernetes add-on for managing GCP resources
Go
826
star
40

nodejs-getting-started

A tutorial for creating a complete application using Node.js on Google Cloud Platform
JavaScript
800
star
41

keras-idiomatic-programmer

Books, Presentations, Workshops, Notebook Labs, and Model Zoo for Software Engineers and Data Scientists wanting to learn the TF.Keras Machine Learning framework
Jupyter Notebook
797
star
42

gcr-cleaner

Delete untagged image refs in Google Container Registry or Artifact Registry
Go
795
star
43

metacontroller

Lightweight Kubernetes controllers as a service
Go
790
star
44

getting-started-python

Code samples for using Python on Google Cloud Platform
Python
756
star
45

magic-modules

Add Google Cloud Platform support to Terraform
HTML
753
star
46

awesome-google-cloud

A curated list of awesome stuff for Google Cloud.
742
star
47

mlops-on-gcp

Jupyter Notebook
728
star
48

dotnet-docs-samples

.NET code samples used on https://cloud.google.com
C#
719
star
49

click-to-deploy

Source for Google Click to Deploy solutions listed on Google Cloud Marketplace.
Ruby
709
star
50

cloud-sdk-docker

Google Cloud CLI Docker Image - Docker Image containing the gcloud CLI and its bundled components.
Dockerfile
697
star
51

iap-desktop

IAP Desktop is a Windows application that provides zero-trust Remote Desktop and SSH access to Linux and Windows VMs on Google Cloud.
C#
687
star
52

tf-estimator-tutorials

This repository includes tutorials on how to use the TensorFlow estimator APIs to perform various ML tasks, in a systematic and standardised way
Jupyter Notebook
671
star
53

functions-framework-python

FaaS (Function as a service) framework for writing portable Python functions
Python
670
star
54

flink-on-k8s-operator

[DEPRECATED] Kubernetes operator for managing the lifecycle of Apache Flink and Beam applications.
Go
659
star
55

terraform-google-examples

Collection of examples for using Terraform with Google Cloud Platform.
HCL
573
star
56

functions-framework-dart

FaaS (Function as a service) framework for writing portable Dart functions
Dart
531
star
57

cloud-run-button

Let anyone deploy your GitHub repos to Google Cloud Run with a single click
Go
520
star
58

govanityurls

Use a custom domain in your Go import path
Go
513
star
59

bigquery-oreilly-book

Source code accompanying: BigQuery: The Definitive Guide by Lakshmanan & Tigani to be published by O'Reilly Media
Jupyter Notebook
499
star
60

getting-started-java

Java
478
star
61

ml-on-gcp

Machine Learning on Google Cloud Platform
Python
476
star
62

ipython-soccer-predictions

Sample iPython notebook with soccer predictions
Jupyter Notebook
473
star
63

covid-19-open-data

Datasets of daily time-series data related to COVID-19 for over 20,000 distinct locations around the world.
Python
470
star
64

ai-platform-samples

Official Repo for Google Cloud AI Platform. Find samples for Vertex AI, Google Cloud's new unified ML platform at: https://github.com/GoogleCloudPlatform/vertex-ai-samples
Jupyter Notebook
453
star
65

practical-ml-vision-book

Jupyter Notebook
441
star
66

gradle-appengine-templates

Freemarker based templates that build with the gradle-appengine-plugin
439
star
67

distributed-load-testing-using-kubernetes

Distributed load testing using Kubernetes on Google Container Engine
Smarty
438
star
68

terraform-validator

Terraform Validator is not an officially supported Google product; it is a library for conversion of Terraform plan data to CAI Assets. If you have been using terraform-validator directly in the past, we recommend migrating to `gcloud beta terraform vet`.
Go
436
star
69

hackathon-toolkit

GCP Hackathon Toolkit
HTML
434
star
70

monitoring-dashboard-samples

TypeScript
428
star
71

nodejs-docker

The Node.js Docker image used by Google App Engine Flexible.
TypeScript
406
star
72

cloud-ops-sandbox

Cloud Operations Sandbox is an open source collection of tools that helps practitioners to learn O11y and R9y practices from Google and apply them using Cloud Operations suite of tools.
HCL
398
star
73

cloud-code-vscode

Cloud Code for Visual Studio Code: Issues, Documentation and more
392
star
74

k8s-stackdriver

Go
390
star
75

professional-services-data-validator

Utility to compare data between homogeneous or heterogeneous environments to ensure source and target tables match
Python
375
star
76

cloud-code-samples

Code templates to make working with Kubernetes feel like editing and debugging local code.
Java
374
star
77

require-so-slow

`require`s taking too much time? Profile 'em.
TypeScript
373
star
78

functions-framework-go

FaaS (Function as a service) framework for writing portable Go functions
Go
373
star
79

k8s-multicluster-ingress

kubemci: Command line tool to configure L7 load balancers using multiple kubernetes clusters
Go
372
star
80

compute-image-packages

Packages for Google Compute Engine Linux images.
Python
370
star
81

healthcare

Python
367
star
82

android-docs-samples

Java
365
star
83

stackdriver-errors-js

Client-side JavaScript exception reporting library for Cloud Error Reporting
JavaScript
358
star
84

google-cloud-iot-arduino

Google Cloud IOT Example on ESP8266
C++
340
star
85

istio-samples

Istio demos and sample applications for GCP
Shell
331
star
86

ios-docs-samples

iOS samples that demonstrate APIs and services of Google Cloud Platform.
Swift
325
star
87

mlops-with-vertex-ai

An end-to-end example of MLOps on Google Cloud using TensorFlow, TFX, and Vertex AI
Jupyter Notebook
317
star
88

cloud-code-intellij

Plugin to support the Google Cloud Platform in IntelliJ IDEA - Docs and Issues Repository
315
star
89

gcping

The source for the CLI and web app at gcping.com
Go
303
star
90

spring-cloud-gcp

New home for Spring Cloud GCP development starting with version 2.0.
Java
299
star
91

airflow-operator

Kubernetes custom controller and CRDs to managing Airflow
Go
296
star
92

security-analytics

Community Security Analytics provides a set of community-driven audit & threat queries for Google Cloud
Python
289
star
93

elixir-samples

A collection of samples on using Elixir with Google Cloud Platform.
Elixir
289
star
94

gke-networking-recipes

Shell
286
star
95

datalab-samples

Jupyter Notebook
281
star
96

compute-archlinux-image-builder

A tool to build a Arch Linux Image for GCE
Shell
280
star
97

solutions-terraform-cloudbuild-gitops

HCL
276
star
98

kotlin-samples

Kotlin
276
star
99

gcpdiag

gcpdiag is a command-line diagnostics tool for GCP customers.
Python
268
star
100

PerfKitExplorer

PerfKit Explorer is a dashboarding and performance analysis tool built with Google technologies and easily extensible. PerfKit Explorer is licensed under the Apache 2 license terms. Please make sure to read, understand and agree to the terms of the LICENSE and CONTRIBUTING files before proceeding.
JavaScript
268
star