Kubernetes Volumes on OpenStack

In this blog:

  • Why Volumes Are Needed?
  • What Is A Container Storage Interface (CSI)?
  • CSIs Available On OpenStack
  • Using Cinder For Workloads
  • Install Cinder

At the beginning of the Kubernetes era, many engineers had a concern – what about apps that have to store data? Kubernetes got a “reputation” of only being for stateless applications and applications that didn’t need to store data. However, that’s vastly changed over the years when implementing Kubernetes. In this blog post, you’re going to learn how to manage Kubernetes volumes and what CSIs are, along with how to install a CSI plugin on a Kubernetes cluster running in OpenStack.

Prerequisites

To follow along with the hands-on portion of this blog post, you should have:
-A Kubernetes cluster that you have access to.

Why Volumes Are Needed?

When you’re working with any application, chances are some data needs to be stored. From a stateful app perspective, there’s a combination of data that needs to be stored and values that need to stay unique. For example, a stateful app in Kubernetes keeps Pod network ID’s the same, which allow them to stay unique. Outside of stateful apps in Kubernetes, you have stateless apps which also may need to store data. For example, let’s say you have an Nginx application. The Nginx application will most likely have some type of frontend stored on it for the overall website configuration. As the website changes, the data that’s being changed must be stored. This is where a Kubernetes volume can come into play. You can mount a volume at, for example, /var/lib/www/html to ensure that the data in that location is stored on the Kubernetes volume. That way, if a Kubernetes Deployment or Pods go down, the data still exists for when the Pods come back up in the Kubernetes cluster.

What Is A Container Storage Interface (CSI)?

Before talking about CSI’s, let’s talk about what would occur before a CSI.

Before the CSI plugin was available, organizations had to build volume connections inside of the raw Kubernetes code. For example, let’s say that OpenStack wanted to create a way for engineers to use OpenStack volumes inside of a Kubernetes cluster. OpenStack would then have to write the code to make this possible, and that code would have to ship with the core Kubernetes code. That means not only would you have to “give the code” to the Kubernetes maintainers, but if there was a bug in your code, you’d have to wait until the next Kubernetes API release. This was not only a huge strain on organizations trying to help engineers use volumes in Kubernetes, but it was a huge strain on the Kubernetes maintainers to have to worry about all of the extra code configs.
CSI’s were created to avoid the above. With CSI plugins, any organization can create a Container Storage Interface plugin for engineers to use. For example, OpenStack has a CSI plugin, and so does NetApp, along with almost every other organization that’s dealing with storage.

CSIs Available On OpenStack

At the time of writing this, there are two CSI’s available for OpenStack:

  • Cinder
  • Manila

Cinder was the first CSI available for OpenStack and continues to remain popular as many engineers are using volumes for block storage for their Kubernetes deployments. Manila was created to solve the need for storage on distributed file systems when standard block storage wasn’t needed. For example, if you need a way to create and manage file shares as you would with NTFS on Windows, you would use Manila on OpenStack.
The key differences are – Cinder provides block storage and Manila provides distributed file system storage.
In terms of overall adoption ratings, Cinder is still used more over Manila.

You can see both CSI’s, along with the code, available here.

Using Cinder For Workloads

Now that you know what CSI’s are, along with why they’re used and what CSI’s are available on OpenStack, let’s learn how to install Cinder and use it in a Kubernetes Manifest. You’ll first need to install Cinder, the CSI plug-in. Then, you’ll have to configure the plug-in to run on your Kubernetes cluster. After that, you’ll be able to create a StorageClass and a PersistentVolumeClaim to be used for your Pods.

Install Cinder

First, clone the GitHub repo where the Manifests to get Cinder up and running on your Kubernetes cluster exist.

git clone https://github.com/kubernetes/cloud-provider-openstack.git

Next, change directories into the cloud-provider-openstack directory.

cd cloud-provider-openstack

The first Kubernetes Manifest you’ll deploy is to create the CSI secret needed for Cindr.

kubectl create -f manifests/cinder-csi-plugin/csi-secret-cinderplugin.yaml

Next, install the rest of the components needed for Cinder which include:

  • RBAC permissions
  • The Cinder Kubernetes Controller
  • The driver
  • Service accounts
  • DaemonSets

And a few more components. To fully view them, take a look at all of the Manifests found here.

kubectl -f manifests/cinder-csi-plugin/ apply

You should now see the CSI running in the Kubernetes cluster.

Now that the CSI is running, it’s time to create a Kubernetes StorageClass so you can utilize storage from a volume running on OpenStack. The below code will create a StorageClass and utilize the OpenStack Cinder CSI plugin.
Save the following Kubernetes Manifest and apply it to your cluster. For example, you can save the Manifest as storageclass.yaml and run kubectl apply -f storageclass.yaml .

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: csi-sc-cinderplugin
provisioner: cinder.csi.openstack.org

Next, create a PersistentVolumeClaim so you can use some of the storage that’s available from Cinder. In this case and for example purposes, you can set the storage to 1Gi , or even larger depending on the storage that’s available in your OpenStack cluster.
Save the following Kubernetes Manifest and apply it to your cluster. For example, you can save the Manifest as pvc.yaml and run kubectl apply -f pvc.yaml .

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: csi-pvc-cinderplugin
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storageClassName: csi-sc-cinderplugin

After the StorageClass and PersistentVolume are created, you can now use the volume in any Kubernetes deployment that requires persistent storage.
For example, the Kubernetes Manifest below deploys a stateless Nginx web app that utilized the Cinder CSI for a Volume.

You can install the following manifest by saving it and giving it a name like deployment.yaml and use Kubectl to deploy it. For example – kubectl apply -f deployment.yaml .

apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginxdeployment
replicas: 2
template:
metadata:
labels:
app: nginxdeployment
spec:
containers:
- name: nginxdeployment
image: nginx:latest
ports:
- containerPort: 80
volumeMounts:
- mountPath: /var/lib/www/html
name: csi-data-cinderplugin
volumes:
- name: csi-data-cinderplugin
persistentVolumeClaim:
claimName: csi-pvc-cinderplugin
readOnly: false

Congrats! You have successfully set up the Cinder CSI in your Kubernetes cluster.

About Our Guest Writer

Michael Levan is a consultant, researcher, and content creator with a career that has spanned countless business sectors, and includes working with companies such as Microsoft, IBM, and Pluralsight. An engineer at heart, he is passionate about enabling excellence in software development, SRE, DevOps, and actively mentors developers to help them realize their full potential. You can learn more about Michael on his website at: https://michaellevan.net/

Interested in Learning More?

OpenMetal and OpenStack are the perfect fit for Kubernetes. But don’t take our word for it:

 

More From OpenMetal 

The Power of Kubernetes on OpenStack: Benefits for Modern Organizations

The Power of Kubernetes on OpenStack: Benefits for Modern Organizations.

In this article, we will explore the power of Kubernetes on OpenStack and its benefits. Kubernetes on OpenStack offers many benefits: improved scalability, cost savings, and flexibility. It also allows for better resource utilization and faster application development cycles.
Read more…

OpenStack vs OpenShift: Understanding the Differences and Choosing the Right Platform for Your Business

OpenStack vs OpenShift: Understanding The Differences And Choosing The Right Platform For Your Business

This blog post will provide a thorough overview of OpenStack and OpenShift which will help you choose the platform that is best for your organization’s needs. I’ll cover the architectures and deployment models of both platforms, as well as their key features. Read more…

Kubernetes Workloads on OpenStack

Kubernetes Workloads On OpenStack

With Kubernetes, organizations can take advantage of the scalability and flexibility of OpenStack while also leveraging the orchestration capabilities of Kubernetes.

On this page you will find a library of Kubernetes guides written by our in house engineers, video tutorials by LearnLinuxTV and Michael Levan, and blogs! Learn More…

Test Drive

For eligible organizations, individuals, and Open Source Partners, Private Cloud Cores are free to trial. Apply today to qualify.

Apply Now

Subscribe

Join our community! Subscribe to our newsletter to get the latest company news, product releases, updates from partners, and more.

Subscribe