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
Automating Tests in DevOps

In this chapter, we will discuss automating tests in DevOps workflow to accelerate time to production, reduce the loss of delivery risks, and detect service anomalies using known test automation tools on Kubernetes. After following the recipes in this chapter, you will have gained the skills to prevent known defects as well as quickly find new defects to reduce service downtime.

In this chapter, we will cover the following recipes:

  • Building event-driven automation with StackStorm
  • Automating tests with the Litmus framework
  • Automating Chaos Engineering with Gremlin
  • Automating your code review with Codacy
  • Detecting bugs and anti-patterns with static code analysis with SonarQube
  • Detecting license compliance issues with Fossa

Technical requirements

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

The Kubernetes command-line tool, kubectl, will be used for the rest of the recipes in this chapter, since it's the main command-line interface for running commands against Kubernetes clusters. We will also use helm, where Helm charts are available to deploy solutions.

Building event-driven automation with StackStorm

StackStorm is an open source, event-driven automation platform. Using the GitOps approach, it helps run workflows based on events. In this section, we will perform arbitrary automation or remediation tasks using StackStorm on Kubernetes. You will learn how to deploy StackStorm in a highly available configuration on Kubernetes using Helm charts and get started by deploying examples of rules, custom sensors, actions, and workflows.

Getting ready

Make sure you have a Kubernetes cluster ready, as well as kubectl and helm configured so that you can manage the cluster resources.

How to do it…

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

  • Installing StackStorm
  • Accessing the StackStorm UI
  • Using the st2 CLI
  • Defining a rule
  • Deploying a rule

Installing StackStorm

Although StackStorm can be distributed as a Red Hat Package Manager/Debian (RPM/Deb) for Linux systems and as Docker images, if you...

Automating tests with the Litmus framework

Litmus is an open source toolset that's used to run chaos experiments in Kubernetes. Litmus provides the Chaos Central Registration Depository (CRD) for cloud-native developers and SREs to inject, orchestrate, and monitor chaos to find potential weaknesses in Kubernetes deployments in real time in production. In this section, we will run some of these chaos experiments to validate the resiliency of the systems. You will learn how to build pipelines for CI and end-to-end testing in order to validate and certify the new Kubernetes version.

Getting ready

Clone the k8sdevopscookbook/src repository to your workstation to be able to use the manifest files under the chapter4 directory:

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

Make sure you have a Kubernetes cluster ready and kubectl and helm configured so that you can manage the cluster resources.

How to do it…

This section is further divided into the...

Automating Chaos Engineering with Gremlin

Gremlin is a Chaos Engineering service that prevents outages and builds more reliable systems. In this section, we will run chaos attacks in production to validate the resiliency of the systems using Gremlin. You will learn how to create CPU and node shutdown attacks to test the resiliency of your infrastructure.

Getting ready

For this recipe, we need to have the Kubernetes command-line tool, kubectl, and helm installed.

All the operations mentioned here require a Gremlin account. If you don't have one, go to https://app.gremlin.com/signup and create one.

How to do it…

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

  • Setting up Gremlin credentials
  • Installing Gremlin on Kubernetes
  • Creating a CPU attack against a Kubernetes worker
  • Creating a node shutdown attack against a Kubernetes worker
  • Running predefined scenario-based attacks
  • Deleting Gremlin from your cluster

Setting up Gremlin credentials...

Automating your code review with Codacy

In this section, we will use Codacy to automate code reviews without having to make any additional code changes to our repositories and generate notifications on code quality and security issues. You will learn how to automate one of the most underestimated tasks when it comes to the development of code reviews and checks.

Getting ready

All the operations mentioned here require a Codacy account. If you don't have one, go to https://www.codacy.com/pricing and create one.

How to do it…

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

  • Accessing the Project Dashboard
  • Reviewing commits and PRs
  • Viewing issues by category
  • Adding a Codacy badge to your repository

Accessing the Project Dashboard

Let's perform the following steps to access the Codacy Project Dashboard:

  1. Log in to Codacy at https://app.codacy.com, which will bring you to your Organization Dashboard.
  2. Click on Projects on the left...

Detecting bugs and anti-patterns with SonarQube

SonarQube is a popular development tool that is used in software development to catch bugs and vulnerabilities in your applications. In this section, we will learn how to automate static code analysis to detect bugs and anti-patterns that you can use in your CI/CD pipelines.

Getting ready

Clone the k8sdevopscookbook/src repository to your workstation in order to use the manifest files under the chapter4 directory:

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

Make sure you have a Kubernetes cluster ready and kubectl and helm configured so that you can manage the cluster resources.

How to do it…

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

  • Installing SonarQube using Helm
  • Accessing the SonarQube Dashboard
  • Creating a new user and tokens
  • Enabling Quality Profiles
  • Adding a project
  • Analyzing a project
  • Viewing issues by category
  • Adding a SonarQube badge to your...

Detecting license compliance issues with FOSSA

FOSSA is an open source software license compliance tool that allows modern teams to be successful with open source software development. In this section, we will scan software licenses with the FOSSA framework. You will learn how to automate license compliance and vulnerability checks.

Getting ready

All the operations mentioned here require a FOSSA account. If you don't have one, go to https://app.fossa.com/account/register and create one.

How to do it…

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

  • Adding projects to FOSSA
  • Triaging licensing issues
  • Adding a FOSSA badge to your project

Adding projects to FOSSA

Let's perform the following steps to add projects to FOSSA:

  1. Log in to FOSSA at https://app.fossa.com/projects.
  2. Click on the ADD PROJECTS button:
  1. Select QUICK IMPORT and then Continue:

  1. Select your repository location. In this recipe, we will use Gitlab:
  1. Click...
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 $15.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