Skip to main content
Version: 3.2

Using pre-provisioned volumes in GCP Anthos

This document describes how to use a pre-provisioned volume in your cluster.

Create a Portworx volume using pxctl

First create a volume using the Portworx CLI. On one of the nodes with Portworx installed, run the following command:

/opt/pwx/bin/pxctl volume create testvol --size 2

For more details on creating volumes using pxctl, see Concepts.

Alternatively, you can also use snapshots that you previously created.

Use the Portworx volume

Once you have a Portworx volume, you can use it in 2 different ways:

1. Using the Portworx volume directly in a pod

You can create a pod that directly uses a Portworx volume as follows:

apiVersion: v1
kind: Pod
metadata:
name: nginx-px
spec:
containers:
- image: nginx
name: nginx-px
volumeMounts:
- mountPath: /test-portworx-volume
name: testvol
volumes:
- name: testvol
# This Portworx volume must already exist.
portworxVolume:
volumeID: testvol
note

The name and volumeID above must be the same and should be the name of the Portworx volume created using pxctl.

2. Using the Portworx volume by creating a PersistentVolume & PersistentVolumeClaim

Creating PersistentVolume

First create a PersistentVolume that references the Portworx volume. Following is an example spec.

apiVersion: v1
kind: PersistentVolume
metadata:
name: testvol
spec:
capacity:
storage: 2Gi
claimRef:
apiVersion: v1
kind: PersistentVolumeClaim
name: testvol-pvc
namespace: default
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
portworxVolume:
volumeID: <px-volume-id>
note

The preceding PersistentVolume example references an existing Portworx volume called testvol that was created using pxctl.

Creating PersistentVolumeClaim

Now create a PersistentVolumeClaim that will claim the previously created volume. Following is an example spec.

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: testvol-pvc
spec:
selector:
matchLabels:
name: testvol
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
volumeName: testvol
note

If you are planning to use the PersistentVolumeClaim in a pod in a non-default namespace, you must create the PersistentVolumeClaim in that namespace.

Creating a pod using the PersistentVolumeClaim

Now you can create a pod that references the PersistentVolumeClaim that you created. Following is an example.

apiVersion: v1
kind: Pod
metadata:
name: nginx-px
spec:
containers:
- image: nginx
name: nginx-px
volumeMounts:
- mountPath: /test-portworx-volume
name: testvol
volumes:
- name: testvol
persistentVolumeClaim:
claimName: testvol-pvc

note

To access PV/PVCs with a non-root user, refer to Access via Non-Root Users