Reader small image

You're reading from  Kubernetes - A Complete DevOps Cookbook

Product typeBook
Published inMar 2020
PublisherPackt
ISBN-139781838828042
Edition1st Edition
Concepts
Right arrow
Author (1)
Murat Karslioglu
Murat Karslioglu
author image
Murat Karslioglu

Murat Karslioglu is a distinguished technologist with years of experience using infrastructure tools and technologies. Murat is currently the VP of products at MayaData, a start-up that builds data agility platform for stateful applications, and a maintainer of open source projects, namely OpenEBS and Litmus. In his free time, Murat is busy writing practical articles about DevOps best practices, CI/CD, Kubernetes, and running stateful applications on popular Kubernetes platforms on his blog, Containerized Me. Murat also runs a cloud-native news curator site, The Containerized Today, where he regularly publishes updates on the Kubernetes ecosystem.
Read more about Murat Karslioglu

Right arrow
Building CI/CD Pipelines

In this chapter, we will discuss the configuration of end-to-end Continuous Integration/Continuous Delivery (CI/CD) pipelines using the most popular CI/CD tools on both self-managed public clouds and SaaS solutions using Kubernetes. After following the recipes in this chapter, you will have gained the skills needed to build, deploy, and promote applications from development to a production environment. You will be able to use the tools that we will implement in these recipes to detect bugs, anti-patterns, and license concerns during the continuous integration process.

In this chapter, we will cover the following recipes:

  • Creating a CI/CD pipeline in Jenkins X
  • Creating a CI/CD pipeline in GitLab
  • Creating a CI/CD pipeline using CircleCI
  • Setting up a CI/CD pipeline using GitHub Actions
  • Setting up a CI/CD pipeline on Amazon Web Services
  • Setting up a CI/CD...

Technical requirements

The recipes in this section assume that you have a functional Kubernetes cluster deployed after following one of the recommended methods described in Chapter 1, Building Production-Ready Kubernetes Clusters.

Kubernetes' command-line interface, kubectl, will be used for the rest of the recipes in this section since it's the main command-line interface for running commands against Kubernetes clusters. If you are using a Red Hat OpenShift cluster, you can replace kubectl with oc. All the commands are expected to function similarly.

The recipes in this section require a Git repository with a containerized project.

Creating a CI/CD pipeline in Jenkins X

Jenkins X is a fairly new open source solution that extends the Jenkins ecosystem and solves the problem of automating CI/CD in the cloud using Kubernetes.

In this section, we will learn how to get your application as a pipeline into Jenkins X, which you will have deployed by following the Deploying and managing the life cycle of Jenkins X recipe instructions in Chapter 2, Operating Applications on Kubernetes. With that, you will learn how to create a CI/CD pipeline with automated GitOps and promote an application from staging to production, all by using simple commands.

Getting ready

Make sure you have followed the instructions in Chapter 2, Operating Applications on Kubernetes, in the Deploying and managing the life cycle of Jenkins X recipe and have a functional Kubernetes cluster with a Jenkins X deployment ready. You can find the instructions to install helm in that chapter as well.

In the following recipe, you will learn how to create a pipeline...

Creating a CI/CD pipeline in GitLab

GitLab is a complete DevOps toolchain that's delivered in a single application platform. GitLab provides all the necessary tooling you need to manage, plan, create, verify, package, release, configure, monitor, and secure your applications.

In this section, we will focus on the CI/CD pipeline features of GitLab that can be consumed as SaaS or self-hosted service. We will import an application and create a pipeline in GitLab. You will learn how to create a CI/CD pipeline with Auto DevOps and promote an application from staging into production.

Getting ready

In the following recipe, you will learn how to create a pipeline with Auto DevOps. This recipe requires GitLab (self-managed or SaaS) and an account with your preferred cloud vendor where you installed your Kubernetes cluster using GitLab.

The Community Edition of GitLab includes the Auto Build, Auto Test, Auto Review Apps, Auto Deploy, and Auto Monitoring features. In addition to these features...

Creating a CI/CD pipeline in CircleCI

In this section, we will cover the initial configuration and requirements to deploy and manage Kubernetes services using CircleCI. You will learn how to create a pipeline so that you can build container images and store them in a Container Registry.

Getting ready

This recipe requires an active GitHub account with a project to build. We will use AWS EKS to demonstrate CI with CircleCI.

First, visit the following GitHub page of our demo application project and fork your copy to your GitHub account:

$ git clone https://github.com/k8sdevopscookbook/circleci-demo-aws-eks.git

Clone the k8sdevopscookbook/circleci-demo-aws-eks repository to your workstation in order to use the circleci-demo-aws-eks example at https://github.com/k8sdevopscookbook/circleci-demo-aws-eks.

How to do it...

This section is further divided into the following subsections to make this process easier:

  • Getting started with CircleCI
  • Deploying changes to a Kubernetes cluster on Amazon...

Setting up a CI/CD pipeline using GitHub Actions

GitHub Actions enable you to create custom software development workflows directly in your GitHub repository. If you are already using GitHub as your code repository, built-in CI/CD capabilities make this option very compelling.

In this section, we will cover the GitHub Actions workflow configuration and built-in CI/CD capabilities. You will learn how to manage workflows and create new GitHub Actions.

Getting ready

In the following recipe, you will learn how to create a basic action example in a repository you own by adding a Dockerfile. This recipe requires an active GitHub account with a project to build. We will use AWS EKS to demonstrate CI with GitHub.

How to do it...

This section is further divided into the following subsections to make this process easier:

  • Creating a workflow file
  • Creating a basic Docker build workflow
  • Building and publishing images to Docker Registry
  • Adding a workflow status badge

Creating a workflow file

GitHub...

Setting up a CI/CD pipeline on Amazon Web Services

In this section, we will cover the CI/CD pipeline construction workflow on AWS and built-in CI/CD capabilities. You will learn how to manage pipelines, how to run build commands during the pipeline steps, and how to store build result images on the Amazon Elastic Container Registry (ECR).

Getting ready

In the following recipe, you will learn how to build, test, and deploy an example service based on AWS services. All the operations mentioned here require an AWS account and an AWS user with a policy that has permission to use the related services, have HTTPS Git credentials for CodeCommit assigned, and a Kubernetes cluster deployed using AWS EKS. If you don't have one, go to https://aws.amazon.com/account/ and create one.

How to do it...

This section is further divided into the following subsections to make this process easier:

  • Creating an AWS CodeCommit code repository
  • Building projects with AWS CodeBuild
  • Creating an AWS CodeDeploy...

Setting up a CI/CD pipeline with Spinnaker on Google Cloud Build

Google Cloud Build is a managed CI/CD and deployment platform that lets you build, test, and deploy in the cloud. In this section, we will cover the CI/CD pipeline with Google Cloud Build configuration using Spinnaker capabilities, an open source, multi-cloud continuous delivery platform.

Getting ready

Clone the k8sdevopscookbook/src repository to your workstation to use the manifest files under the chapter3 directory:

$ git clone https://github.com/k8sdevopscookbook/src.git
$ cd /src/chapter3

Make sure you have the necessary credentials to use GCP services and have access to the current project. If you don't have one already, go to https://console.cloud.google.com and create an account.

How to do it...

This section is further divided into the following subsections to make this process easier:

  • Installing and configuring the Spin CLI
  • Configuring a service account for the CI/CD
  • Configuring events to trigger the pipeline...

Setting up a CI/CD pipeline on Azure DevOps

Azure DevOps provides version control, reporting, automated builds, and project/lab/testing and release management capabilities. Azure DevOps is available as a SaaS or on-premises server product. In this section, we will cover the Azure DevOps workflow configuration and built-in CI/CD capabilities using the SaaS product. You will learn how to manage workflows and create Azure pipelines.

Getting ready

In the following recipe, you will learn how to create a pipeline example in a repository you own by adding a YAML file. This recipe requires an active GitHub account with a project ready to be built. We will use AKS to demonstrate continuous delivery with Azure Pipelines.

All the operations mentioned here require an Azure DevOps account. If you don't have one, go to https://azure.microsoft.com/services/devops/ and create one. Deploying the application on Azure Kubernetes Service also requires an active Azure Cloud subscription.

How to do it...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Kubernetes - A Complete DevOps Cookbook
Published in: Mar 2020Publisher: PacktISBN-13: 9781838828042
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime

Author (1)

author image
Murat Karslioglu

Murat Karslioglu is a distinguished technologist with years of experience using infrastructure tools and technologies. Murat is currently the VP of products at MayaData, a start-up that builds data agility platform for stateful applications, and a maintainer of open source projects, namely OpenEBS and Litmus. In his free time, Murat is busy writing practical articles about DevOps best practices, CI/CD, Kubernetes, and running stateful applications on popular Kubernetes platforms on his blog, Containerized Me. Murat also runs a cloud-native news curator site, The Containerized Today, where he regularly publishes updates on the Kubernetes ecosystem.
Read more about Murat Karslioglu