Continuous Delivery with Jenkins in Kubernetes Engine

📒 link

Overview

  • Goal

    • Set up a continuous delivery pipeline with Jenkins on Kubernetes engine.

  • What you’ll do

    • Provision a Jenkins application into a Kubernetes Engine Cluster

    • Set up your Jenkins application using Helm Package Manager

    • Explore the features of a Jenkins application

    • Create and execise a Kenkins pipeline

What is Kubernetes Engine?

Kubernetes Engine is Google Cloud's hosted version of Kubernetes - a powerful cluster manager and orchestration system for containers. Kubernetes is an open source project that can run on many different environments—from laptops to high-availability multi-node clusters; from virtual machines to bare metal. As mentioned before, Kubernetes apps are built on containers - these are lightweight applications bundled with all the necessary dependencies and libraries to run them. This underlying structure makes Kubernetes applications highly available, secure, and quick to deploy—an ideal framework for cloud developers.

What is Jenkins?

Jenkins is an open-source automation server that lets you flexibly orchestrate your build, test, and deployment pipelines. Jenkins allows developers to iterate quickly on projects without worrying about overhead issues that can stem from continuous delivery.

What is Continuous Delivery / Continuous Deployment?

When you need to set up a continuous delivery (CD) pipeline, deploying Jenkins on Kubernetes Engine provides important benefits over a standard VM-based deployment.

When your build process uses containers, one virtual host can run jobs on multiple operating systems. Kubernetes Engine provides ephemeral build executors—these are only utilized when builds are actively running, which leaves resources for other cluster tasks such as batch processing jobs. Another benefit of ephemeral build executors is speed—they launch in a matter of seconds.

Kubernetes Engine also comes pre-equipped with Google's global load balancer, which you can use to automate web traffic routing to your instance(s). The load balancer handles SSL termination and utilizes a global IP address that's configured with Google's backbone network—coupled with your web front, this load balancer will always set your users on the fastest possible path to an application instance.

Now that you've learned a little bit about Kubernetes, Jenkins, and how the two interact in a CD pipeline, it's time to go build one.

Ref

Download the source code

✔️ Set zone

✔️ Copy the lab’s sample code

✔️ Change to the correct directory

Provisioning Jenkins

✔️ Creating a Kubernetes cluster

✔️ Confirm that your cluster is running

✔️ Get the credentials

✔️ Confirm that you can connect to access your newly provisioned cluster

Setup Helm

  • What is Helm?

    • Helm is a package manager that makes it easy to configure and deploy Kubernetes applications.

✔️ Add Helm’s stable chart repo

✔️ Ensure the repo is up to date

Configure and Install Jenkins

When installing Jenkins, a values file can be used as a template to provide values that are necessary for setup.

custom values file

✔️ Download the custom values file

✔️ Use the Helm CLI to deploy the chart with your configuration settings

✔️ Ensure the Jenkins pod goes to the Running state and the container is in the READT state

✔️ Configure the Jenkins service account to be able to deploy to the cluster

✔️ Setup port forwarding to the Jenkins UI from the Cloud Shell

✔️ Check that the Jenkins Service was created properly

Connect to Jenkins

✔️ Jenkins chart will automatically create an admin password for you.

✔️ To get to the Jenkins user interface, click on the Web Preview button in cloud shell, then click Preview on port 8080

Understanding the Application

Deploy the sample application, gceme, in your continuous deployment pipeline.

Deploying the Application

Environments

  • Production : The live site that your users access

  • Canary : A smaller-capacity site that receives only a percentage of your user traffic. Use this environment to validate your software with live traffic before it's released to all of your users.

✔️ Navigate to the sample application directory

✔️ Create the Kubernetes namespace to logically isolate the deployment

✔️ Create the production and canary deployments, and the services

✔️ Create the production and canary deployments, and the services

✔️ Scale up the production environment frontends

✔️ Now confirm that you have 5 pods running for the frontend, 4 for production traffic and 1 for canary releases (changes to the canary release will only affect 1 out of 5 (20%) of users)

✔️ Confirm that you have 2 pods for the backend, 1 for production and 1 for canary

✔️ Retrieve the external IP for the production services

✔️ Store the frontend service load balancer IP in an environment cariable for use later

✔️ Confirm that both services are working by opening the frontend external IP address in your browser. Check the version output of the service by running the following command

set up a pipeline for deploying your changes continuously and reliably.

Creating the Jenkins Pipeline

✔️ Creating a repository to host the sample app source code

✔️ Initialize the sample-app directory as its own Git repository

Set the username and email address. Add, commit, and push the files.

✔️ Adding yout service account credentials

  • Step 1: In the Jenkins user interface, click Manage Jenkins in the left navigation then click Manage Credentials.

  • Step 2: Click Jenkins

  • Step 3: Click Global credentials (unrestricted).

  • Step 4: Click Add Credentials in the left navigation.

  • Step 5: Select Google Service Account from metadata from the Kind drop-down and click OK.

✔️ Creating the Jenkins job

  • Step 1: Click New Item in the left navigation:

  • Step 2: Name the project sample-app, then choose the Multibranch Pipeline option and click OK.

  • Step 3: On the next page, in the Branch Sources section, click Add Source and select git.

  • Step 4: Paste the HTTPS clone URL of your sample-app repo in Cloud Source Repositories into the Project Repository field. Replace [PROJECT_ID] with your Project ID:

  • Step 5: From the Credentials drop-down, select the name of the credentials you created when adding your service account in the previous steps.

  • Step 6: Under Scan Multibranch Pipeline Triggers section, check the Periodically if not otherwise run box and set the Interval value to 1 minute.

  • Step 7: Your job configuration should look like this:

  • Step 8: Click Save leaving all other options with their defaults.

Creating the Development Environment

✔️ Creating a development branch

✔️ Modifying the pipeline definition

Open the Jenkinsfile in your terminal editor

✔️ Modify the site

Change the gceme card from blue to orange

Kick off Deployment

✔️ Commit and push your changes

✔️ Start the proxy in the background

✔️ Verify that your application is accessible by sending a request yo localhost and letting kubectl proxy forward it to your service

Deploying a Canary Release

✔️ Create a canary branch and push it to the Git server

✔️ Check the service URL to ensure that some of the traffic is being served by your new version. Your should see about 1 in 5 requests (in no particular order) returning version 2.0.0 .

Deploying to production

✔️ Create a canary branch and push it to the Git server

✔️ Check the service URL to ensure that all of the traffic is being served by your new version, 2.0.0.

✔️ Navigate to site on which the gceme application displays the info cards.

12

Last updated