Getting Started with Block Storage¶
This guide provides practical examples of how to create, use, and manage persistent volumes for your applications on the Contain Platform.
Creating a Persistent Volume¶
You don't create PersistentVolume objects directly. Instead, you request
storage by creating a PersistentVolumeClaim (PVC). The platform's storage
provisioner will then watch for your PVC and automatically create a
corresponding PersistentVolume that matches your requirements.
To create a claim, you define a PersistentVolumeClaim object in YAML. The most
important fields are:
spec.storageClassName: This specifies which type of storage you want. See Storage Classes for more information.spec.accessModes: This defines how the volume can be mounted. For block storage,ReadWriteOnce(RWO) is the most common mode, meaning the volume can be mounted as read-write by a single node at a time.spec.resources.requests.storage: This is where you specify the size of the volume you are requesting.
Example: Creating a 10Gi Volume¶
Here is an example of a PVC that requests a 10 gibibyte volume from the default
StorageClass.
# my-pvc.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-application-data
spec:
accessModes:
- ReadWriteOnce
storageClassName: vmware-sc # Use the StorageClass provided for your project
resources:
requests:
storage: 10Gi
Using the Volume in a Pod¶
Once your PVC has been created and bound to a volume, you can use it in your pods. You reference the PVC in your pod specification to mount it as a volume inside one or more of your containers.
Example: Mounting the Volume in a Deployment¶
This Deployment example creates a Pod with an NGINX container. It mounts the
my-application-data PVC at the path /usr/share/nginx/html inside the
container.
# my-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-web-server
spec:
replicas: 1
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
volumeMounts:
- name: web-data # This name must match the volume name below
mountPath: /usr/share/nginx/html
volumes:
- name: web-data # This is the volume name referenced by volumeMounts
persistentVolumeClaim:
claimName: my-application-data # This must match the name of your PVC
Expanding a Volume¶
You can expand the size of a persistent volume after its creation, provided the
StorageClass supports it. All standard StorageClasses on the Contain
Platform have volume expansion enabled (allowVolumeExpansion: true).
To expand a volume, you simply edit your PersistentVolumeClaim object and
change the value of the spec.resources.requests.storage field to the desired
new size. The platform will automatically resize the underlying volume and the
filesystem without any downtime for your application.
Example: Expanding a Volume to 20Gi¶
Update the original my-pvc.yaml file and re-apply it:
# my-pvc.yaml (updated)
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-application-data
spec:
accessModes:
- ReadWriteOnce
storageClassName: vmware-sc
resources:
requests:
storage: 20Gi # Changed from 10Gi to 20Gi
After you apply this change, Kubernetes will begin the expansion process. You
can monitor the status of the PVC with kubectl describe pvc my-application-data.
Shrinking Volumes¶
Shrinking is Not Supported
Shrinking a persistent volume is a complex and high-risk operation that is not supported by most storage providers, including the underlying driver used on the platform. There is no safe, automated way to decrease the size of a PVC.
You should provision storage based on your expected needs and use volume expansion when more space is required. If you need to reduce storage, the only way is to create a new, smaller PVC and migrate the data manually.