CI/CD for Kubernetes With Jenkins and Spinnaker

DZone 's Guide to

CI/CD for Kubernetes With Jenkins and Spinnaker

Here's a new tool that can help you continuously deploy new builds to your Kubernetes clusters.

· Cloud Zone ·
Free Resource

Every organization which has adopted DevOps practices wants to quickly adopt "Continuous" everything, be it integration, deployment, testing, or monitoring. For a successful DevOps operation, CI/CD is very important for any small or big size organization to shorter development cycles and innovate faster, reduce deployment failures, safe rollbacks and reduce MTTR (mean time to recover).

In this article, we will uncover a new way of bringing continuous integration and continuous delivery of applications to your Kuberenetes cluster. We are using Jenkins as the CI tool, which will poll the Git repositories to build Docker images on commits and push it to Docker registry. We will use Spinnaker as the CD tool, which continuously polls the Docker registry and triggers the deployment pipelines to update applications in your Kubernetes cluster.

Image title

The above diagram shows when the developer commits changes to Github, Jenkins polls for commits to a configured branch and triggers a new build on a new commit. Jenkins builds the Docker image and pushes it to the Docker registry with a tag (you can choose different techniques to tag your images like using the build-commit number or an incremental number). With Spinnaker, we configure the deployment pipeline such that it will trigger the deployment when there is a new tag (Docker image) found in the registry.

What Is Spinnaker?

Spinnaker is an open source, multi-cloud continuous delivery tool created by Netflix. It allows us to configure multiple deployment strategies such as Highlander, Red/Black. It not only allows us to rollback in case of failures but also trigger promoted pipelines. Meaning we can configure complex pipelines by allowing us to define testing pipelines and promote to next stage or rollback easily and safely in controlled Kubernetes cluster(s). We will learn more about deployment strategies and pipeline configuration in next article in this series.

Components of Spinnaker

To understand installation of Spinnaker we need to understand its working components. Lets take a breif look at its components and their functions.

Image title

You can view the detailed dependency matrix and default bind ports for the follwing components at Spinnaker's official documentation page.

Deck: Browser-based UI for Spinnaker.

Gate: API callers and Spinnaker UI communicate to Spinnaker server via this API gateway called Gate.

Orca: Pipelines and other ad-hoc operations are managed by this orchestration engine called Orca.

Clouddriver: Indexing and Caching of deployed resources are taken care by Clouddriver. It also facilitates calls to cloud providers like AWS, GCE, and Azure.

Echo: It is responsible for sending notifications, it also acts as incoming webhook.

Igor: It is used to trigger pipelines via continuous integration jobs in systems like Jenkins and Travis CI, and it allows Jenkins/Travis stages to be used in pipelines.

Front50: It's the metadata store of Spinnaker. It persists metadata for all resources which include pipelines, projects, applications and notifications.

Rosco: Rosco bakes machine images (AWS AMIs, Azure VM images, GCE images).

Rush: It is Spinnaker's script excution engine.

Installation of Spinnakerhttps://docs.microsoft.com/en-us/azure/virtual-machines/linux/classic/about-images


Before we start installation, let's look at the following requirements. Halyard has the following requirements. We used Ubuntu 16.04 in our case.

  • Ubuntu 14.04 or 16.04 (Ubuntu 16.04 requires Spinnaker 1.6.0 or later)
  • Debian 8 or 9
  • If you are installing on local machine, macOS only (tested on High Sierra)

1. We start with the Halyard installation. It is the lifecycle manager of Spinnaker deployment.

The following command will install the latest version of Halyard.

curl -O https://raw.githubusercontent.com/spinnaker/halyard/master/install/debian/InstallHalyard.sh
sudo bash InstallHalyard.sh

2. After that will set the Spinnaker version which we want to use.

hal version list ### this will return availabel version 
hal config version edit --version $VERSION 

3. Now we will choose the storage driver where Spinnaker will store all its data. Spinnaker support multiple types of storage drivers like S3, Minio, and Redis. We will use Minio as our storage driver.

This will run Minio as a container on the server and add Minio as storage in Spinnaker.

docker run -p 9000:9000 --name minio1 \
  -e "MINIO_ACCESS_KEY={{access_key}}" \
  -e "MINIO_SECRET_KEY={{secret_key}} \
  -v /mnt/data:/data \
  -v /mnt/config:/root/.minio \
  minio/minio server /data

echo {{secret_key}} | hal config storage s3 edit --endpoint http://localhost:9000 \
    --access-key-id {{access_key}} \
hal config storage edit --type s3

4. After setting up storage for Spinnaker, we will add Kubernetes cluster(s) as cloud-provider(s).

The account name will be the name of the Kubernetes cluster. This way we can manage multiple cloud-providers (K8s clusters) managed from single Spinnaker.

Kubeconfig-file will be the config file of Kkubernetes which you can get from the "~/.kube/" folder on the Kubernetes master node.

hal config provider kubernetes account add {{account name}} --kubeconfig-file={{ kubeconfig-file path }}

5. Once we add cloud-provider, it will deploy the changes to Spinnaker.

hal deploy apply 

Now our Spinnaker setup is ready. In the next article, we will go through steps on how to create applications and deploy the changes using Spinnaker pipelines. Also if you are wondering why Jenkins is missing in this article, we will have a brief section on Jenkins setup as an image builder for our use case in the next article as well.

Stay tuned.

Part 2 link: https://dzone.com/articles/cicd-for-kubernetes-with-jenkins-and-spinnaker-con

You can connect with Arvind and Karan on LinkedIn

cloud, continuous delivery, docker, kubernetes, spinnaker, tutorial

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}