Manage Kubernetes Storage using Persistent Volume (PV) and Persistent Volume Claim (PVC)

Background

This is the sixth part of the series on building highly scalable multi-container apps using AKS. So far in this series we have covered following topics.

In this post we will learn about a very important concept of Persistent Volumes (PV) and Persistent Volume Claim (PVC). We will use these concepts to manage data for the SQL Server 2017 Linux container.

Why do we need volume in the first place?

Managing data in a containerized scenario is quite tricky. Containers are ephemeral by design. Which means that they can be created, deleted and rescheduled on any host in the cluster. If the container is recreated, what happens to the data stored inside the container? It is oblivious that the data stored locally inside the container will be lost.

This scenario might be ok while testing. But as we start moving to deploying the applications using containers, we would want to persist the data even if the container restarts or a newer version of the image is used to upgrade the older version of container. In such scenario it makes sense to store the data external to the container. It is in such scenario that external volumes play a very important role.

During the course of this post we will focus on following

  • Provision Persistent Volume (PV)  using Azure Disk
  • Create Persistent Volume Claim (PVC) to the provisioned volume

Provision Persistent Volume (PV)  using Azure Disk

Persistent Volume abstracts from users details of how the storage is provided and how it is consumed. It is a cluster level resource provisioned by administrator and available to the pods to use. Persistent volume supports multiple types of storage including network storage, physical disks or cloud storage like Azure Disk. The storage is provisioned using one of the supported Storage Class. Lets look at an example of creating a storage class based on Azure Disk

We will skip the initial metadata, on line 7 we specify the provisioner as azure-disk. We also specify the parameters storage account type as Standard_LRS and kind as Managed. The parameters will be different for different types of provisioner. You can refer to the storage-class provisioner link below to know more about the supported provisioners with Kubernetes.

Lets go and apply this Kubernetes manifest to our cluster. Use kubectl command line to execute the command

kubectl apply –f 01_storage-class.yml

We can browse to the Kubernetes dashboard and see that the storage class is created successfully.

storage class

The creation of Storage Class is an indication of what kind of storage we are going to provision within the Kubernetes cluster. Lets go ahead and create a Persistent Volume Claim.

Create Persistent Volume Claim to the provisioned storage

Lets look at an example of the Kubernetes manifest file to create a Persistent Volume Claim (PVC).

Above we see the definition of PVC. Line 8 links the storage class named azure-disk. Note that this is the name we gave while creating the storage class earlier. From line 9 onwards we specify the requirements for the storage claim. In our example we have specified ReadWriteOnce as the access mode. For the resource request, we specified 1Gb as the disk space. When we apply this manifest, 1Gb of disk space will be provisioned for us. Run the kubectl command

kubectl apply –f 02_PersistentVolumeClaim.yml

The Persistent Volume has different lifecycle. It takes few minutes to provision the storage and bind it to the Kubernetes cluster. Initially the status of the persistent volume claim will be Pending.

PVC Pending

Once the volume is successfully provisioned it is bound to the claim. We can verify this by looking at the bound state.

PVC Bound

At this point we can go to the Persistent Volumes section on the left of the Kubernetes dashboard and find details about the underlying volume.

PVC

In this view we can find details like the name of the volume, its capacity, access modes, status, associated claim etc. Like we had done in earlier parts of this series, we can use the Kubernetes cli to query the PV object to know more details. Execute the following command

kubectl describe pv <<name of the pvc>>

The output will be as shown in the screenshot  below

kubectl describe PVC

It is same as what we see in the Kubernetes dashboard. We will see how to make use of this Persistent Volume in the next part of this series.

References

[1] Kubernetes Storage class provisioner : https://kubernetes.io/docs/concepts/storage/storage-classes/

[2] Persistent Volumes : https://kubernetes.io/docs/concepts/storage/persistent-volumes/

Conclusion

We saw how to provision a Persistent Volume backed by Azure Disk. With the help of 2 Kubernetes Manifest files we were able to get the disk and associate a claim with it.

Persistent Volumes are quite powerful concept in Kubernetes. It allows developers and cluster administrators to work on different parts of the application. Using Persistent volumes, the administrator can provision storage which can be used by developers without knowing the underlying storage mechanism. This can be used to swap the underlying storage without any need to make changes to application code. This may not be very clear right now, but I am sure it will make sense in the next part where we will see how to utilize these volumes

Until next time, Code with Passion and Strive for Excellence.

Share:
spacer

29 comments:

  1. Fine way of explaining, and fastidious paragraph to obtain information regarding my presentation subject, which i am going to present in institution of
    higher education.

    ReplyDelete
  2. Greetings! I've been following your site for a while now and
    finally got the bravery to go ahead and give you a shout out from Huffman Tx!
    Just wanted to mention keep up the excellent job!

    ReplyDelete
  3. I pay a quick visit day-to-day a few sites and blogs to
    read articles, however this website presents quality based writing.

    ReplyDelete
  4. I'm extremely pleased to discover this great site. I want to
    to thank you for your time just for this fantastic read!!
    I definitely liked every part of it and i also have you bookmarked to look at new things on your blog.

    ReplyDelete
  5. Hello, I enjoy reading through your post. I like to
    write a little comment to support you.

    ReplyDelete
  6. Wow that was strange. I just wrote an incredibly long comment but after I clicked
    submit my comment didn't appear. Grrrr... well I'm not writing all that over again.
    Anyway, just wanted to say wonderful blog!

    ReplyDelete
  7. Appreciation to my father who informed me on the topic of this weblog, this website is in fact remarkable.

    ReplyDelete
  8. This info is worth everyone's attention. Where can I find out more?

    ReplyDelete
  9. Excellent blog here! Also your web site loads up fast! What web host
    are you using? Can I get your affiliate link to your host? I wish
    my site loaded up as fast as yours lol

    ReplyDelete
  10. This piece of writing is truly a good one it assists new internet people, who
    are wishing in favor of blogging.

    ReplyDelete
  11. whoah this weblog is magnificent i really like studying your posts.
    Stay up the good work! You know, lots of persons are looking round
    for this information, you could help them greatly.

    ReplyDelete
  12. Hello! Would you mind if I share your blog with my facebook group?

    There's a lot of people that I think would really appreciate your content.

    Please let me know. Cheers

    ReplyDelete
  13. I like the helpful info you provide in your articles.

    I will bookmark your weblog and check again here regularly.

    I'm quite sure I'll learn many new stuff right here! Best of luck for the next!

    ReplyDelete
  14. Your way of telling everything in this article is genuinely fastidious,
    every one be capable of effortlessly understand it,
    Thanks a lot.

    ReplyDelete
  15. When someone writes an piece of writing he/she maintains the idea of
    a user in his/her mind that how a user can understand
    it. Therefore that's why this post is great.
    Thanks!

    ReplyDelete
  16. Piece of writing writing is also a fun, if you be familiar with after that you can write if not
    it is complicated to write.

    ReplyDelete
  17. I'm really impressed with your writing skills and also with the layout on your weblog.

    Is this a paid theme or did you customize it yourself?
    Anyway keep up the nice quality writing, it
    is rare to see a great blog like this one today.

    ReplyDelete
  18. Good information. Lucky me I discovered your website by accident (stumbleupon).
    I've saved as a favorite for later!

    ReplyDelete
  19. Heya i'm for the first time here. I came across this board and I to find It truly helpful & it helped me
    out much. I am hoping to give something back and aid others like you
    helped me.

    ReplyDelete
  20. Very nice post. I just stumbled upon your blog and wanted to say that I have truly
    enjoyed surfing around your blog posts. After all I'll be subscribing to your rss
    feed and I hope you write again soon!

    ReplyDelete
  21. Superb, what a weblog it is! This weblog presents valuable data to us,
    keep it up.

    ReplyDelete
  22. Great blog here! Also your website loads up very
    fast! What host are you using? Can I get your affiliate link to your host?
    I wish my web site loaded up as fast as yours lol

    ReplyDelete
  23. I was wondering if you ever thought of changing the page layout
    of your site? Its very well written; I love what youve got to say.
    But maybe you could a little more in the way of content so people could connect with it better.
    Youve got an awful lot of text for only having 1 or 2 images.
    Maybe you could space it out better?

    ReplyDelete
  24. Howdy I am so delighted I found your blog page, I really found you by error, while I was
    looking on Digg for something else, Anyways I am here now and would
    just like to say thanks a lot for a tremendous post and a all round thrilling blog (I also love the
    theme/design), I don’t have time to look over it all at the
    minute but I have saved it and also added in your RSS
    feeds, so when I have time I will be back to read more, Please do keep up the awesome jo.

    ReplyDelete
  25. Hi there, after reading this amazing piece of writing i am also glad to share my know-how here
    with colleagues.

    ReplyDelete
  26. whoah this weblog is wonderful i like reading your articles.

    Stay up the great work! You realize, many persons are hunting around for this information, you could help them greatly.

    ReplyDelete
  27. Keep this going please, great job!

    ReplyDelete
  28. I am actually pleased to read this blog posts which consists of plenty of valuable data, thanks for providing such data.

    ReplyDelete
  29. I read this paragraph fully regarding the comparison of latest
    and earlier technologies, it's awesome article.

    ReplyDelete