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
Preparing for Stateful Workloads

In this chapter, we will discuss using popular open source storage solutions on Kubernetes and how to protect the state of applications from node or application failures and share the same data, or how to handle reattaching volumes when the pod is rescheduled on a different node. After following the recipes in this chapter, you will have acquired the skills to use both block and file storage options in self-managed infrastructure or private clouds.

In this chapter, we will be covering the following recipes:

  • Managing Amazon EBS volumes in Kubernetes
  • Managing GCE PD volumes in Kubernetes
  • Managing Azure Disk volumes in Kubernetes
  • Configuring and managing persistent storage using Rook
  • Configuring and managing persistent storage using OpenEBS
  • Setting up NFS for shared storage on Kubernetes
  • Troubleshooting storage issues

Technical requirements

Recipes in this section assume that you have a functional Kubernetes cluster deployed according to one of the recommended methods described in Chapter 1, Building Production-Ready Kubernetes Clusters.

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

Managing Amazon EBS volumes in Kubernetes

Amazon Elastic Block Store (Amazon EBS) provides persistent block-level storage volumes for Amazon EC2 instances used in both kops-created Kubernetes clusters and Amazon EKS clusters in AWS. In this section, we will create storage classes for your applications in Kubernetes running in AWS. You will learn how to create a StorageClass resource in Kubernetes, you will learn about the parameters available with the variation in performance of EBS volume types and also use the new Container Storage Interface (CSI) to consume EBS volumes.

Getting ready

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

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

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

How to do it…

This section is sub-divided further into the following subsections to facilitate...

Managing GCE PD volumes in Kubernetes

Google Cloud Platform (GCP) provides persistent block-level storage volumes for use with Google Kubernetes Engine (GKE) instances. In this section, we will create storage classes for your applications in Kubernetes running in the GKE. You will learn to create a StorageClass resource in Kubernetes, you will learn about the parameters available with the variation in performance of GCP PD volume types, and also use the new CSI.

Getting ready

Clone the k8sdevopscookbook/src repository to your workstation:

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

Make sure that you have a regional GKE cluster ready and kubectl configured to manage the cluster resources.

How to do it…

This section is sub-divided further into the following subsections to facilitate the process:

  • Creating a GCE persistent disk storage class
  • Changing the default storage class
  • Using GCE PD volumes for persistent storage
  • Using GCE PD storage classes to...

Managing Azure Disk volumes in Kubernetes

Azure Cloud provides persistent block-level storage volumes for use with Azure Kubernetes Engine (AKS). In this section, we will create storage classes for your applications in Kubernetes running in the AKS. You will learn how to create a StorageClass resource in Kubernetes, you will learn about the parameters available with the variation in performance of Azure Disk volume types, and you will also learn how to use the new CSI.

Getting ready

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

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

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

How to do it…

This section is sub-divided further into the following subsections to facilitate the process:

  • Creating an Azure Disk storage class
  • Changing the default storage class to ZRS
  • Using Azure Disk...

Configuring and managing persistent storage using Rook

Rook is a cloud-native, open source storage orchestrator for Kubernetes. Rook provides self-managing, self-scaling, and self-healing distributed storage systems in Kubernetes. In this section, we will create multiple storage providers using the Rook storage orchestrator for your applications in Kubernetes. You will learn to create a Ceph provider for your stateful applications that require persistent storage.

Getting ready

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

How to do it…

This section is sub-divided further into the following subsections to facilitate the process:

  • Installing a Ceph provider using Rook
  • Creating a Ceph cluster
  • Verifying a Ceph cluster's health
  • Create a Ceph block storage class
  • Using a Ceph block storage class to create dynamic PVs

Installing a Ceph provider using Rook

Let's perform the following steps to get a Ceph scale-out storage...

Configuring and managing persistent storage using OpenEBS

OpenEBS is a popular open source, cloud-native storage (CNS) project with a large community. In this section, we will install an OpenEBS persistent storage provider. You will learn how to create volumes using different types of storage engine options for stateful workloads on Kubernetes.

Getting ready

For this recipe, we need to have helm and kubectl installed. Make sure you have a Kubernetes cluster ready and kubectl configured to manage the cluster resources.

How to do it…

This section is sub-divided further into the following subsections to facilitate the process:

  • Installing iSCSI client prerequisites
  • Installing OpenEBS
  • Using ephemeral storage to create persistent volumes
  • Creating storage pools
  • Creating OpenEBS storage classes
  • Using an OpenEBS storage class to create dynamic PVs

Installing iSCSI client prerequisites

The OpenEBS storage provider requires that the iSCSI client runs on all worker nodes:

  1. On all your worker...

Setting up NFS for shared storage on Kubernetes

Although it's not the best-performing solution, NFS is still used with cloud-native applications where multi-node write access is required. In this section, we will create an NFS-based persistent storage for this type of application. You will learn how to use OpenEBS and Rook to ReadWriteMany (RWX) accessible persistent volumes for stateful workloads that require shared storage on Kubernetes.

Getting ready

For this recipe, we need to have either rook or openebs installed as an orchestrator. Make sure that you have a Kubernetes cluster ready and kubectl configured to manage the cluster resources.

How to do it…

There are two popular alternatives when it comes to providing an NFS service. This section is sub-divided further into the following subsections to explain the process using Rook and OpenEBS:

  • Installing NFS prerequisites
  • Installing an NFS provider using a Rook NFS operator
  • Using a Rook NFS operator storage class to create...

Troubleshooting storage issues

In this section, you will learn how to solve the most common storage issues associated with Kubernetes. After following the recipes in this chapter, you will gain the basic skills required to troubleshoot persistent volumes stuck in pending or termination states.

Getting ready

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

How to do it…

This section is sub-divided further into the following subsections to facilitate the process:

  • Persistent volumes in the pending state
  • A PV is stuck once a PVC has been deleted

Persistent volumes in the pending state

You have deployed an application, but both pods and persistent volume claims are stuck in the pending state, similar to the following:

$ kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
mysql-pv-claim Pending rook-ceph-block 28s

Let's perform the following steps to start troubleshooting:

  1. First, describe the PVC to...
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