Containers & Kubernetes

Introducing the Jenkins GKE Plugin—deploy software to your Kubernetes clusters

Containers and Kubernetics static hero

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 it’s already possible to run Jenkins on Google Kubernetes Engine (GKE) clusters, it’s harder to manage robust deployment strategies for your workloads that run on Kubernetes. 

Today, we are excited to announce the availability of the Jenkins Google Kubernetes Engine (GKE) Plugin, which provides a build step that streamlines deploying workloads to GKE clusters across GCP projects

Here is a screenshot of the user interface:

deploy gke.png

After providing credentials and configuration to the plugin it will do the following during your Jenkins job:

  1. Download ephemeral credentials for your target GKE cluster
  2. Use kubectl to apply the Kubernetes resources in your workspace
  3. 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, 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 the 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 using the graphical interface like we do with the build step configuration above can speed up your initial exploration of the plugin, 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:

More about Jenkins on GCP

We’ve released a number of Jenkins plugins that make running continuous integration and continuous delivery workloads on Google Cloud even easier:

We also have the following tutorials to help you get up to speed with Jenkins on GCP: