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
Observability and Monitoring on Kubernetes

In this chapter, we will discuss the built-in Kubernetes tools and the popular third-party monitoring options for your containerized DevOps environment. You will learn how to monitor metrics for performance analysis, and also how to monitor and manage the real-time cost of Kubernetes resources.

By the end of this chapter, you should have knowledge of the following:

  • Monitoring in Kubernetes
  • Inspecting containers
  • Monitoring using Amazon CloudWatch
  • Monitoring using Google Stackdriver
  • Monitoring using Azure Monitor
  • Monitoring Kubernetes using Prometheus and Grafana
  • Monitoring and performance analysis using Sysdig
  • Managing the cost of resources using Kubecost

Technical requirements

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

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.

Monitoring in Kubernetes

In this section, we will configure our Kubernetes cluster to get core metrics, such as CPU and memory. You will learn how to monitor Kubernetes metrics using the built-in Kubernetes tools both in the CLI and on the UI.

Getting ready

Make sure you have a Kubernetes cluster ready and kubectl configured to manage the cluster resources.

Clone the k8sdevopscookbook/src repository to your workstation to use the manifest files in the chapter8 directory:

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

The Monitoring metrics using Kubernetes Dashboard recipe requires Kubernetes Dashboard v2.0.0 or later to function. If you want to add metric functionality to the dashboard, make sure that you have Kubernetes Dashboard installed by following the instructions in the Deploying Kubernetes Dashboard recipe in Chapter 1, Building Production-Ready Kubernetes Clusters.

How to do it…

This section is further divided into the following subsections...

Inspecting containers

In this section, we will troubleshoot problems related to pods stuck in Pending, ImagePullBackOff, or CrashLoopBackOff states. You will learn how to inspect and debug pods that are having deployment problems in Kubernetes.

Getting ready

Make sure you have a Kubernetes cluster ready and kubectl configured to manage the cluster resources.

How to do it…

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

  • Inspecting pods in Pending status
  • Inspecting pods in ImagePullBackOff status
  • Inspecting pods in CrashLoopBackOff status

Inspecting pods in Pending status

When you deploy applications on Kubernetes, it is inevitable that soon or later you will need to get more information on your application. In this recipe, we will learn to inspect common pods problem of pods stuck in Pending status:

  1. In the /src/chapter8 folder, inspect the content of the mongo-sc.yaml file and deploy it running the following command. The deployment...

Monitoring using Amazon CloudWatch

In this section, we will use Amazon CloudWatch Container Insights to monitor, isolate, and diagnose your containerized applications and microservices environments. As a DevOps or Systems Engineer, you will learn how to use Amazon ECS CloudWatch metrics to monitor service health status and current alarms using automated dashboards that summarize the performance and health of your Amazon EKS clusters by pod, node, namespace, and services.

Getting ready

Clone the k8sdevopscookbook/src repository to your workstation to use manifest files in the chapter8 directory:

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

Make sure you have an Amazon EKS Kubernetes cluster ready and kubectl configured to manage the cluster resources. If you don't already have one you can follow the instructions in Chapter 1, Building Production-Ready Kubernetes Clusters, in the Configuring a Kubernetes cluster on Amazon Web Services section.

How to...

Monitoring using Google Stackdriver

In this section, we will use Google Stackdriver Kubernetes Engine Monitoring to monitor, isolate, and diagnose your containerized applications and microservices environments. You will learn how to use Stackdriver Kubernetes Engine Monitoring to aggregate logs, events, and metrics from your Kubernetes environment on Google Kubernetes Engine (GKE) to help you understand your application's behavior in production.

Getting ready

Make sure you have a GKE cluster ready and kubectl configured to manage the cluster resources. If you don't already have one, you can follow the instructions in Chapter 1, Building Production-Ready Kubernetes Clusters, in the Configuring a Kubernetes cluster on Google Cloud Platform recipe.

How to do it…

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

  • Installing Stackdriver Kubernetes Engine Monitoring support for GKE
  • Configuring a workspace on Stackdriver
  • Monitoring...

Monitoring using Azure Monitor

In this section, we will use Azure Monitor to monitor, isolate, and diagnose your containerized applications and microservices environments. You will learn how to use Azure Monitor to aggregate logs, events, and metrics from your Kubernetes environment on Azure Kubernetes Service (AKS) to help you understand your application's behavior in production.

Getting ready

Make sure you have an AKS cluster ready and kubectl configured to manage the cluster resources. If you don't already have one, you can follow the instructions in Chapter 1, Building Production-Ready Kubernetes Clusters, in the Configuring a Kubernetes cluster on Google Cloud Platform recipe.

How to do it…

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

  • Enabling Azure Monitor support for AKS using the CLI
  • Monitoring AKS performance metrics using Azure Monitor
  • Viewing live logs using Azure Monitor

Enabling Azure Monitor support for AKS...

Monitoring Kubernetes using Prometheus and Grafana

In this section, we will deploy Prometheus and Grafana on our Kubernetes cluster. You will learn how to monitor a Kubernetes service with Prometheus and use Grafana dashboards to visualize cluster and application metrics.

Getting ready

Clone the k8sdevopscookbook/src repository to your workstation to use manifest files in the chapter8 directory:

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

Make sure you have a Kubernetes cluster ready and kubectl configured to manage the cluster resources.

How to do it…

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

  • Deploying Prometheus Operator using Helm charts
  • Monitoring metrics using Grafana dashboards
  • Adding a Grafana dashboard to monitor applications

Deploying Prometheus using Helm charts

Prometheus is a popular open source solution for event monitoring and alerting. Prometheus records real-time metrics in a time...

Monitoring and performance analysis using Sysdig

In this section, we will use Sysdig Monitor to monitor and simplify Kubernetes troubleshooting. You will learn how to install Sysdig Monitor and extend Prometheus functionality to meet more advanced enterprise needs.

Getting ready

All operations mentioned here require a Sysdig account. If you don't have one, go to https://sysdig.com/sign-up/ and create a trial or full account.

For this recipe, we need to have a Kubernetes cluster ready and the Kubernetes command-line tools kubectl and helm installed to manage the cluster resources.

How to do it…

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

  • Installing the Sysdig agent
  • Analyzing application performance

Installing the Sysdig agent

Sysdig Monitor is a tool for monitoring and troubleshooting applications available as part of the Sysdig Cloud Native Visibility and Security Platform. In this recipe, you will learn to deploy Sysdig Monitor...

Managing the cost of resources using Kubecost

In this section, we will install and configure the open source Kubecost project, which gives you cost-related visibility into your Kubernetes resources. You will learn how to monitor resource costs to reduce spending and potentially prevent resource-based outages.

Getting ready

This recipe requires a functional Kubernetes cluster deployed on AWS or GCP. Currently, other cloud providers are not supported.

Before you can execute the commands in the following recipes, you need to have kubectl and helm installed. You can find the instructions to install Helm in Chapter 2, Operating Applications on Kubernetes, in the Deploying workloads using Helm charts section.

How to do it…

This section is further divided into the following subsections to ease the process:

  • Installing Kubecost
  • Accessing Kubecost dashboard
  • Monitoring Kubernetes resource cost allocation

Installing Kubecost

Kubecost creates Kubernetes resource-granular models of current...

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