Skip to main content

💾 Storage

A container's disk is temporary: when the pod is recreated, everything that was on it is lost. To store data that must survive (databases, uploads, files), Kubernetes uses persistent disks.

TermWhat it isAnalogy
StorageClassThe type of disk available (for example, SSD)The disk catalog
PVC (PersistentVolumeClaim)The request for a disk, with a sizeThe purchase order
PV (PersistentVolume)The disk itself, created automatically from the requestThe delivered disk

In practice, you only create the PVC. The cluster creates the disk on its own.

info

The PVC is created with kubectl. The created disk can also be viewed in the Nuvion Panel (step 6).


🚀 Before you start​

🚀 1. See the available disk types​

kubectl get storageclass

Note the name of the class marked (default). It is used when you do not choose one.

🚀 2. Request a disk (create the PVC)​

Create the file pvc-dados.yaml:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-dados
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
kubectl apply -f pvc-dados.yaml
tip

If the list from step 1 has no (default) class, add the line storageClassName: CLASS-NAME inside spec.

ReadWriteOnce means the disk can be used by one node at a time.

🚀 3. Check the request​

kubectl get pvc pvc-dados

The STATUS should be Bound (disk delivered). In some clusters the status stays Pending until a pod uses the disk, and that is normal. Go to step 4.

🚀 4. Use the disk in a pod​

Create the file pod-storage.yaml. Each time the pod starts, it writes the date and time to the file /dados/historico.txt:

apiVersion: v1
kind: Pod
metadata:
name: pod-storage
spec:
containers:
- name: app
image: busybox
command: ["sh", "-c", "date >> /dados/historico.txt; sleep 3600"]
volumeMounts:
- name: dados
mountPath: /dados
volumes:
- name: dados
persistentVolumeClaim:
claimName: pvc-dados
kubectl apply -f pod-storage.yaml
kubectl get pvc pvc-dados
kubectl exec pod-storage -- cat /dados/historico.txt

The PVC becomes Bound and the file shows one line with the date.

🚀 5. Prove that the data survives​

Delete the pod and create it again:

kubectl delete pod pod-storage
kubectl apply -f pod-storage.yaml
kubectl exec pod-storage -- cat /dados/historico.txt

Now the file shows two lines: the previous one and the new one. The pod was recreated, but the disk kept the data.

🚀 6. See the created disk​

Go to Compute > Volumes and look for a new 1 GiB volume, created automatically by the cluster.

Volume created by the PVC in the panel

✅ How to know it worked​

The file /dados/historico.txt accumulates a new line each time the pod is recreated.

warning

When you delete the PVC, the disk and all data are erased (in the default configuration). Deleting only the pod erases nothing.

❗ Common problems​

SymptomCauseSolution
PVC Pending and the pod tooNo default StorageClassAdd storageClassName to the PVC (step 2)
Pod stuck in ContainerCreatingThe disk is still being preparedWait and see the Events section in kubectl describe pod pod-storage
Multi-Attach errorReadWriteOnce disk in use by a pod on another nodeUse only one pod with this disk, or make sure they stay on the same node
Requested size larger than allowedVolume limit or quotaRequest a smaller size or contact support

🧹 Cleanup​

kubectl delete pod pod-storage
kubectl delete pvc pvc-dados

The second command erases the disk and the data.

➡️ Next step: Networking

🧠 Questions?​

Talk to our SaveinCloud technical support team!