Jenkins X Quick Start

An opinionated CI/CD platform built on top of Kubernetes.

Introduction from Cloudbees:

Terraform is recommended going forward. K8s cluster must be compatiable with jx.

Prerequisites:

  • Know how classic Jenkins pipeline works
  • Know how to operate on Kubernetes
  • Know how to run Docker container
  • Know how to use Helm

All JX projects are deployed to Kubernetes using Docker and Helm.

Aerial View

Jenkin X: https://jenkins-x.io/

Traditional CI/CD pipeline like classic Jenkins they require heavy customization, and not cloud-native.

Jenkins X is opinionated and cloud-native CI/CD pipeline built on top of Kubernetes. Jenkins X uses Tekton (a Kubernetes-native pipeline engine) to do the job.

Setup Jenkins X

Create a cluser with Terraform on GCP.

Steps please see my github repository: https://github.com/chengdol/jenkins-X-deployment

First install gcloud SDK and Terraform at local.

1
2
3
4
## init the environment, configuration and link to the target gcloud project
gcloud init
## we need kubectl to interact with K8s cluster
gcloud components install kubectl

Then create main.tf file to provision jenkins X cluster on GCP, go to https://registry.terraform.io/ and search jx.

1
2


Create First App on Jenkins X Pipeline

Key components:

  • Applciation code source
  • Docker file: All services store in docker image
  • Helm chart: All docker images wrapped in helm packages
  • Jenkins X file: Defines the build pipeline
1
jx create quickstart

JX commands recap:

1
2
3
4
5
6
7
8
9
10
## out of box workflow for many language projects
jx create qucikstart
## import an existing project to jx
jx import

## watch pipeline for a project
jx get activity -f <project name> -w

## view logs for a build pipeline
jx get build logs <project name>

Environment with GitOps

Introduce GitOps:

Jenkins X adopts GitOps, where Git is the single-source-of-truth for our environment.

1
2
3
4
5
6
## list all available environment
jx get env
## create new env
jx create env

jx promote

Pull Requests and ChatOps

Jenkins streamlines the pull request workflow.

Prow: https://jenkins-x.io/docs/reference/components/prow/

  • Kubernetes CI/CD system
  • Orchestrates Jenkins X pipelines via GitHub events
  • Automates interactions with pull requests Enables
  • ChatOps driven development
  • GitHub only, to be superseded by Lighthouse

Github webhook will call Prow, the webhook is actuall a HTTP POST request that contains the event payload, then Prow will execute pipeline. Conversely, Prow can call Github API.

Introduce ChatOps:

1
2
3
jx create pullrequest
jx get previews
jx delete previews

Creating Custom QucikStart and Build Packs

Build Packs: https://buildpacks.io/, the Jenkins X project template, powered by Draft, contains:

  • Dockerfile
  • Production and Preview Helm charts
  • Jenkins X pipeline

Quick start workflow: jx create quickstart -> choose quick start projects -> generate Vanilla project -> detects Build packs -> modifies Jenkins X project

So bascially, we use quickstart to create a vanilla project skeleton, then Jenkins X-ify this project by build packs (generate languange specific Jenkins X template files). So jx import existing project also use build packs to do the job.

1
2
3
4
5
6
7
8
9
10
11
## list repositories containing quickstarts
jx get quickstartlocation

## create new quickstart repository
jx create quickstartlocation

## delete new quickstart repository
jx delete quickstartlocation

## edit current buildpack location
jx edit buildpack

Customize Jenkins X Pipeline

Jenkins X file definition has YAML file structure, make use of inheritance to reduce repetition.

1
2
3
4
5
## validate pipeline syntax
jx step syntax validate pipeline

## show full pipeline
jx step syntax effective

Versioning and Releasing App

Jenkins X adopts Semantic versioning, split into 3 components.

  • Major: breaking changes
  • Minor: non-breaking changes
  • Patch: bug fixes

Patch number is auto-incremented, Major/Minor versions are set manually.

Custom Domain and TLS

nip.io, the IP with it is not human readable and prevents TLS, insecure. 比如外界访问部署后的应用。 Jenkins X allows custom domains and HTTPS

External DNS:

  • Makes Kubernetes resources discoverable on public DNS servers
  • Automates creation of DNS records

Certificate Manager:

  • Issues SSL certificates for our applications
  • Leverages Lets Encrypt behind the scenes

First buy domain from Google Domains web site then use it in Google Cloud settings.

0%