Jenkins is one of the most widely used tools for automating software build, test, and deployment. Kubernetes, meanwhile, is an increasingly popular deployment target for those workloads. While its been possible to run Jenkins on Kubernetes Engine clusters, it’s been more difficult and tedious to properly manage robust deployment strategies for your own workloads that target Kubernetes.

Wait for the number of replicas you have defined in your Deployment specification to reach the healthy state

Getting started with the Jenkins GKE plugin is easy. First, users provide a single set of credentials to the plugin to discover the GKE clusters across your GCP projects. Then, after choosing a project and cluster, configure the path to the manifests in your Jenkins workspace from which you’d like to deploy. You can also optionally define a namespace to deploy your manifests to.

While many deployment mechanisms fire off a kubectl command and hope that Kubernetes realizes their changes successfully, this can lead to many false positives as deployments fail to reach the healthy state. You can configure the Jenkins GKE Plugin to wait for your deployment to enter the desired state by checking the “Verify Deployments” option. For each Deployment manifest that is applied to the cluster, the plugin polls the deployment to ensure that the number of healthy pods matches the requested minimum number of healthy replicas. In the future we hope to add more of this type of logic to verify other types of resources.

Getting started via graphical interfaces like the build step configuration shown above can speed up initial exploration of the plugin by providing some guard rails and a more intuitive user experience. But in most cases you’ll want to define your application deployment processes in code so that changes can be reviewed, audited, and approved. Thankfully Jenkins provides the Pipeline syntax that lets you define your build, test and release process in a file alongside your source code. Below is an example pipeline that defines a simple rollout process that deploys to a staging cluster, waits for a manual approval from someone in the “sre-approvers” group and then finally deploys to production.

pipeline {

agent { label: “default” }

stages {

stage(‘Deploy Staging’) {

steps{

git url: ‘https://github.com/viglesiasce/sample-app’

step([$class: ‘KubernetesEngineBuilder’,

projectId: “my-project-id”,

clusterName: “staging”,

zone: “us-central1-f”,

manifestPattern: ‘k8s/staging/’,

credentialsId: “gke-service-account”,

verifyDeployments: true])

}

}

stage(‘Wait for SRE Approval’) {

steps{

timeout(time:12, unit:’HOURS’) {

input message:’Approve deployment?’, submitter: ‘sre-approvers’

}

}

}

stage(‘Deploy Production’) {

steps{

git url: ‘https://github.com/viglesiasce/sample-app’

step([$class: ‘KubernetesEngineBuilder’,

projectId: “my-project-id”,

clusterName: “production”,

zone: “us-central1-f”,

manifestPattern: ‘k8s/production/’,

credentialsId: “gke-service-account”,

verifyDeployments: true])

}

}

}

}

Now that you’ve seen some of the features of the Jenkins GKE plugin, go ahead and install it. Head over to the Jenkins Plugin Manager and search the available plugins for “Google Kubernetes Engine Plugin” to install the latest version. For more information on how to configure the plugin, check out the documentation. We’d love your feedback and contributions:

Visit our GitHub repo to let us know how we can make this plugin even better

Every business is a software business, and is under pressure to innovate constantly. This increased velocity introduces new business risks. CloudBees is building the world’s first end-to-end automated software delivery system, enabling companies to balance governance and developer freedom.Learn More