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
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