Kubernetes persistent storage architecture showing PersistentVolume, PersistentVolumeClaim, and a pod mounting the volume in a Minikube cluster

📁 Organising Our Kubernetes Exercises

As we move deeper into Kubernetes, there are a few topics that often get overlooked in beginner guides but are absolutely essential in real-world environments.

Three of the most important ones are:

  • 💾 Storage
  • 🔐 Security
  • ⚙️ Jobs & batch workloads
Why this matters 🧠 If you work with Kubernetes professionally, these three areas come up constantly. Databases need storage, production clusters need security controls, and many workloads run as scheduled jobs.

Create the Directories

# Create storage, security, and jobs directories across all levels

New-Item -ItemType Directory -Path `
"exercises\1-basics\storage","exercises\1-basics\security","exercises\1-basics\jobs",`
"exercises\2-intermediate\storage","exercises\2-intermediate\security","exercises\2-intermediate\jobs",`
"exercises\3-advanced\storage","exercises\3-advanced\security","exercises\3-advanced\jobs"

This PowerShell command creates all required directories in one go. The backtick (`) simply allows us to break the command onto multiple lines.

💾 Testing Kubernetes Persistent Storage with Minikube

One of the most important concepts in Kubernetes is persistent storage.

Containers are normally ephemeral. This means when a container is deleted, its filesystem disappears with it.

Real world example 🧠 Imagine running a database container. If the pod restarts and all the data disappears, that database would be useless.

Kubernetes solves this problem using three main components:

Component Purpose
PersistentVolume (PV) Actual storage resource in the cluster
PersistentVolumeClaim (PVC) Request for storage made by applications
Pod / Deployment Uses the storage by mounting the PVC

1️⃣ Create the Persistent Volume

A PersistentVolume represents the actual storage resource available in the cluster.

In our case, we will create a simple storage volume using Minikube's local filesystem.

File: 01-persistent-volume.yaml

apiVersion: v1
kind: PersistentVolume

metadata:
  name: example-pv

spec:

  # Total storage capacity available
  capacity:
    storage: 1Gi

  # Filesystem volume type
  volumeMode: Filesystem

  # Access mode defines how the volume can be mounted
  accessModes:
    - ReadWriteOnce

  # What happens when the claim is deleted
  persistentVolumeReclaimPolicy: Retain

  # Storage class used by the cluster
  storageClassName: standard

  # Using a hostPath for local storage in Minikube
  hostPath:
    path: /data/example-pv
    type: DirectoryOrCreate

Important fields explained:

  • capacity → Maximum storage size
  • accessModes → Defines how the storage can be used
  • hostPath → Local directory inside the Minikube VM

Apply the PV

kubectl apply -f 01-persistent-volume.yaml

2️⃣ Create the Persistent Volume Claim

Applications do not use PersistentVolumes directly. Instead they create a PersistentVolumeClaim (PVC).

Think of it like requesting storage from the cluster.

File: 02-persistent-volume-claim.yaml

apiVersion: v1
kind: PersistentVolumeClaim

metadata:
  name: example-pvc

spec:

  accessModes:
    - ReadWriteOnce

  resources:
    requests:
      storage: 500Mi

  storageClassName: standard

Here the application is requesting 500Mi of storage. Kubernetes will bind it to the 1Gi PV we created earlier.

Apply the PVC

kubectl apply -f 02-persistent-volume-claim.yaml

3️⃣ Deploy an Application Using the Storage

Now we will create a deployment that actually uses the storage volume.

We will use a simple Nginx container and mount the persistent storage into its web directory.

File: 03-deployment-with-volume.yaml

apiVersion: apps/v1
kind: Deployment

metadata:
  name: nginx-with-storage

spec:
  replicas: 1

  selector:
    matchLabels:
      app: nginx-storage

  template:
    metadata:
      labels:
        app: nginx-storage

    spec:

      containers:
      - name: nginx
        image: nginx:1.14.2

        volumeMounts:
        - mountPath: "/usr/share/nginx/html"
          name: web-content

      volumes:
      - name: web-content
        persistentVolumeClaim:
          claimName: example-pvc

Apply the Deployment

kubectl apply -f 03-deployment-with-volume.yaml

🧪 Testing the Persistent Storage

Now let's verify that the storage is actually working.

Create a test file inside the container

kubectl exec deploy/nginx-with-storage -- sh -c \
'echo "Hello from persistent storage!" > /usr/share/nginx/html/index.html'

Verify the file exists

kubectl exec deploy/nginx-with-storage -- cat /usr/share/nginx/html/index.html

🔁 Testing Persistence

Now we test the most important behaviour: Does the data survive a pod restart?

Delete the Pod

kubectl delete pod -l app=nginx-storage

The deployment will automatically create a new pod.

Check the file again

kubectl exec deploy/nginx-with-storage -- cat /usr/share/nginx/html/index.html
Success 🎉 If the text still appears, the persistent storage is working correctly.

🧹 Resetting Your Minikube Environment

During testing you may want to quickly clean your cluster.

Delete common workloads

kubectl delete all --all

This removes common workload resources such as:

  • Pods
  • Deployments
  • Services
  • ReplicaSets

Delete everything including storage

kubectl delete deployments,services,pods,pv,pvc,configmaps,secrets --all
Note ⚠️ This command deletes almost everything in the namespace, including persistent volumes and secrets. Use it carefully in real clusters.

🔐 What’s Next?

So far we’ve explored how Kubernetes handles persistent storage and how applications can safely store data outside of containers. This is a core building block for many real-world workloads such as databases, uploads, and configuration data.

However, running workloads in Kubernetes isn’t just about deploying containers and managing storage. Another critical piece of the puzzle is security.

Why security matters 🛡️ Kubernetes clusters often run multiple applications, services, and users. Without proper security controls, containers could gain access to sensitive data, secrets, or even other workloads running in the cluster.

In the next post, we’ll start exploring the basics of Kubernetes security. We’ll look at simple but important concepts that help protect your workloads and cluster environment.

Coming up next 🚀 In the next guide we’ll walk through some basic Kubernetes security practices and see how they help keep your containers and applications safer inside the cluster.

Leave a Reply

Your email address will not be published. Required fields are marked *