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.
✔️ 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
cdsample-app
✔️ Create the Kubernetes namespace to logically isolate the deployment
kubectlcreatensproduction
✔️ Create the production and canary deployments, and the services
kubectlcreatensproduction
✔️ Create the production and canary deployments, and the services
✔️ 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 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
curlhttp://$FRONTEND_SERVICE_IP/version
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
gcloudsourcereposcreatedefault
✔️ Initialize the sample-app directory as its own Git repository
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:
✔️ Create a canary branch and push it to the Git server
gitcheckout-bcanarygitpushorigincanary
✔️ 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 .