Adding New Volumes to an Existing Kubernetes Deployment

Mealie is already running with one volume — mealie-data, so we need to add two more — mealie-logs and mealie-temp. In this blog, we will attempt to add two new volumes to an existing deployment with no downtime, no delete, just edit two files and apply.


  • Edit storage.yaml first — PVCs must exist before the deployment tries to mount them
  • kubectl apply only changes what is different but existing PVC is untouched
  • volumeMounts.name and volumes.name must be identical — that is the internal link
  • claimName points to the actual PVC object name in the cluster
  • No need to delete the deployment — apply handles the rolling update

What We Have

k get pvc -n mealie
NAME          STATUS   VOLUME                                     CAPACITY
mealie-data   Bound    pvc-626c77e7-fcf9-426b-b462-784496429019   500Mi

One PVC, one volume mounted in the pod.


Step 1 — Add New PVCs to storage.yaml

We keep all PVCs for one app in a single file using --- to separate each one. Edit storage.yaml and add the two new PVCs:

---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mealie-data
  namespace: mealie
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 500Mi
  storageClassName: local-path
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mealie-logs
  namespace: mealie
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 100Mi
  storageClassName: local-path
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mealie-temp
  namespace: mealie
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 425Mi
  storageClassName: local-path

Apply it:

k apply -f storage.yaml

Expected output:

persistentvolumeclaim/mealie-data unchanged
persistentvolumeclaim/mealie-logs created
persistentvolumeclaim/mealie-temp created

mealie-data is unchanged — Kubernetes only touches what changed. The two new PVCs are created and will show as Pending until a pod mounts them and that is normal for local-path.


Step 2 — Add Volume Mounts to deployment.yaml

Edit deployment.yaml and add the new entries under volumeMounts and volumes:

        volumeMounts:
          - mountPath: /app/data
            name: mealie-data  # main app data — recipes, users, config
          - mountPath: /app/logs
            name: mealie-logs  # application logs
          - mountPath: /mealie-temp
            name: mealie-temp  # temp files
      volumes:
        - name: mealie-data
          persistentVolumeClaim:
            claimName: mealie-data
        - name: mealie-logs
          persistentVolumeClaim:
            claimName: mealie-logs
        - name: mealie-temp
          persistentVolumeClaim:
            claimName: mealie-temp

Apply it:

k apply -f deployment.yaml

Expected output:

deployment.apps/mealie configured

Kubernetes does a RollingUpdate automatically — old pod terminates, new pod starts with all three volumes mounted.


Verify

Check PVCs — all three should be Bound:

k get pvc -n mealie

Expected output:

NAME          STATUS   VOLUME                                     CAPACITY
mealie-data   Bound    pvc-edcfda00-a24d-485a-832e-7efd807d4644   500Mi
mealie-logs   Bound    pvc-4a508708-c4cd-448c-95d8-2bc70bcf72d1   100Mi
mealie-temp   Bound    pvc-c5a2dd0a-d0e0-4ca6-9298-75befac94a27   425Mi

Check pod is running:

k get pods -n mealie
NAME                     READY   STATUS    RESTARTS   AGE
mealie-dcd97746f-5hpn4   1/1     Running   0          39s

Confirm all 3 volumes are mounted:

k describe pods mealie-dcd97746f-5hpn4 -n mealie 

Expected output:

Mounts:
  /app/data from mealie-data (rw)
  /app/logs from mealie-logs (rw)
  /mealie-temp from mealie-temp (rw)


Step 4 — Verify Inside the Pod

Exec into the running pod and confirm the mount points exist on the filesystem:

k exec -it mealie-dcd97746f-5hpn4 -- /bin/bash

List the root filesystem — you can see mealie-temp mounted directly at /:

root@mealie-dcd97746f-5hpn4:/# ls
app  bin  boot  dev  etc  home  lib  lib64  mealie-temp  media  mnt  nltk_data  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

Check the /app directory — data and logs are there, both writable:

root@mealie-dcd97746f-5hpn4:/# ls -l app/
total 16
drwxrwxrwx 7 abc abc 4096 Apr 12 10:47 data
-rwxr-xr-x 1 abc abc  294 Mar 18 14:09 healthcheck.sh
drwxrwxrwx 2 abc abc 4096 Apr 12 10:59 logs
-rwxr-xr-x 1 abc abc 1768 Mar 18 14:09 run.sh

(Visited 2 times, 1 visits today)

By Ash Thomas

Ash Thomas is a seasoned IT professional with extensive experience as a technical expert, complemented by a keen interest in blockchain technology.