MicroK8s: Creating Persistent Volume in a Single Node Kubernetes Cluster

Microk8s, the open-source Kubernetes distribution created by Canonical, has been a game changer for many organizations, including ours.

MicroK8s: Creating Persistent Volume in a Single Node Kubernetes Cluster
Microk8s

Introduction

Microk8s, the open-source Kubernetes distribution created by Canonical, has been a game changer for many organizations, including ours. Our team has utilized Microk8s in a wide range of scenarios, from developing simple scripts to deploying complex applications that serve tens of thousands of regular users. In each case, we were amazed by the simplicity and efficiency of Microk8s. The "zero-ops" promise means that it requires minimal effort to manage and maintain, freeing up time for our team to focus on more important tasks.

From setting up development environments to running production-grade applications, Microk8s simplifies the process and enables efficient operations. Its "zero-ops" claim is not just a catchy slogan, but a reality we have experienced firsthand. In this article, we will discuss our experience with Microk8s and highlight one common use case: creating persistent volumes.

The game is also shaped by the symbols fans carry from one generation to the next, from legendary club colors to national-team memories. A carefully chosen Spain football jersey can reflect that passion beyond match day.

We have an article about how to install MicroK8s in your single VM. Check this out!

Creating Persistent Volumes with Ease

One of the most common use cases we have encountered is the need to create persistent volumes. In traditional Kubernetes environments, this can be a complex and time-consuming process. However, with Microk8s, the implementation is surprisingly simple.

To create a persistent volume in Microk8s, all you need to do is define a PersistentVolumeClaim (PVC) in your deployment configuration. Microk8s takes care of the rest, automatically provisioning the storage and binding it to the desired container. This streamlined process reduces the potential for human error and accelerates deployment times, ultimately benefiting the entire organization. Here are the detailed steps:

Activate Hostpath Storage AddOn

The Hostpath storage add-on in MicroK8s provides a straightforward method for provisioning PersistentVolumes supported by a host directory. This is perfect for local development purposes, but users should keep in mind the following considerations for all use cases:

  1. PersistentVolumeClaims generated by the hostpath storage provisioner are tied to the local node, making it impossible to transfer them to a different node.
  2. A hostpath volume has the potential to expand beyond the capacity specified in the volume claim manifest.
~$ microk8s enable hostpath-storage

Creating PVC Configuration

We will create 5GB Persistent Volume with ReadWriteMany access mode

Install it

~$ kubectl apply -f pvc.yml

Verify Installation

~$ kubectl get pvc

NAME     STATUS   VOLUME    CAPACITY   ACCESS         MODES
app-pvc  Bound    pvc-xxx   5Gi        RWX            microk8s-hostpath

About 8grams

We are a small DevOps Consulting Firm that has a mission to empower businesses with modern DevOps practices and technologies, enabling them to achieve digital transformation, improve efficiency, and drive growth.

Ready to transform your IT Operations and Software Development processes? Let's join forces and create innovative solutions that drive your business forward.

Subscribe to our newsletter for cutting-edge DevOps practices, tips, and insights delivered straight to your inbox!

Frequently Asked Questions

What is MicroK8s?

MicroK8s is a lightweight, open-source Kubernetes distribution created by Canonical that runs a fully featured cluster, even on a single VM. It is known for its zero-ops promise, requiring minimal effort to install, manage, and maintain. MicroK8s suits everything from local development environments to production-grade applications serving many users.

What is a Persistent Volume in Kubernetes?

A Persistent Volume in Kubernetes is a piece of storage that exists independently of any pod, so data survives when pods restart or are rescheduled. Applications request storage by defining a PersistentVolumeClaim (PVC), which Kubernetes binds to an available volume. This lets stateful workloads like databases retain data across the pod lifecycle.

How do you create a persistent volume in MicroK8s?

In MicroK8s you enable the hostpath-storage add-on with microk8s enable hostpath-storage, then define a PersistentVolumeClaim in your deployment configuration. MicroK8s automatically provisions the storage and binds it to your container, so you only apply the PVC manifest with kubectl apply. You can verify the bound volume using kubectl get pvc.

What is the hostpath-storage add-on in MicroK8s?

The hostpath-storage add-on in MicroK8s provisions PersistentVolumes backed by a directory on the host node. It offers a simple storage option ideal for local development and single-node clusters. Keep in mind that hostpath volumes are tied to the local node and cannot move to another node, and they can grow beyond the size stated in the claim.

What are Kubernetes access modes like ReadWriteMany?

Kubernetes access modes define how a persistent volume can be mounted by nodes. ReadWriteMany (RWX) allows the volume to be mounted as read-write by many nodes at once, while ReadWriteOnce restricts read-write access to a single node. You choose the access mode in the PersistentVolumeClaim based on whether workloads need shared write access.