Skip to main content

Command Palette

Search for a command to run...

❄️Day 36 - Managing Persistent Volumes in Your Deployment 💥

Published
2 min read
❄️Day 36 - Managing Persistent Volumes in Your Deployment 💥
S
Hi, I’m Sarika 👋 I’m a QA Engineer with 2+ years of experience in software testing. I have hands-on experience in: * Functional & Regression Testing * API Testing using Postman * Database validation using SQL * Cross-browser testing Currently, I’m focusing on: * Automation Testing using Selenium & Playwright (Java) * Building real-world testing frameworks * End-to-End testing (UI + API + DB) This blog is where I share: * What I learn daily * Real testing scenarios * Practical examples (not just theory) * Interview-focused concepts 🚀 Learning | Building | Sharing Follow me on LinkedIn: https://www.linkedin.com/in/sarika-kamble-3153b3218/

In Kubernetes, a Persistent Volume (PV) is a piece of storage in the cluster that has been provisioned by an administrator. A Persistent Volume Claim (PVC) is a request for storage by a user. The PVC references the PV, and the PV is bound to a specific node.

✒️Task 1:

  • Create a Persistent Volume using a file on your node.

  • Create a Persistent Volume Claim that references the Persistent volume.

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-todo-app
spec:
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  hostPath:
    path: "/tmp/data"

Apply the updates using command kubectl apply -f pv.yaml

  • Create a Persistent Volume Claim that references the Persistent volume.
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pvc-todo-app
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 500Mi

Apply the updates using command kubectl apply -f pvc.yaml

  • Update your deployment.yml file to include the Persistent Volume Claim. After Applying pv.yml pvc.yml your deployment file
apiVersion: apps/v1
kind: Deployment
metadata:
  name: node-todo-app
  namespace: node-app-deployment
  labels:
    app: node-app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: node-app
  template:
    metadata:
      labels:
        app: node-app
    spec:
      containers:
        - name : node-app
          image: sarikak/node-app-batch-6
          ports:
            - containerPort: 8000
          volumeMounts:
            - name: todo-app-data
              mountPath: /app
      volumes:
        - name: todo-app-data
          persistentVolumeClaim:
            claimName: pvc-todo-app
  • Apply the updated deployment using the command: kubectl apply -f deployment.yml

  • Verify that the Persistent Volume has been added to your Deployment by checking the status of the Pods and Persistent Volumes in your cluster. Use this commands kubectl get pods ,kubectl get pv

✒️Task 2:

  • Connect to a Pod in your Deployment using command : `kubectl exec -it -- /bin/bash

  • Verify that you can access the data stored in the Persistent Volume from within the Pod

📚Happy Learning :)