Skip to main content

Create proxy volume PVCs

Portworx proxy volumes allow you to access external data sources, such as an NFS share, from within your Kubernetes cluster. The actual data for these volumes resides on the external data source, which is not part of the cluster.

To use a proxy volume, create a Portworx proxy volume that points to the external NFS share. Portworx acts as a medium, making the external NFS data available to the pods running in your cluster.

Portworx uses the host’s NFS utilities to mount the external NFS share when a pod using the proxy-volume PVC is scheduled on a node. You can configure it to mount an entire NFS share or only a specific directory sub-path.

note

Portworx does not support this feature for Windows NFS servers.

Access an external NFS share

You can access a full NFS share in Portworx as a proxy volume. Application using this spec will have access to the whole NFS share. If you wish to access only a subdirectory within an NFS share, refer to the Accessing a sub-path of an external NFS share section. The examples in these instructions create a proxy volume for an nginx container.

  1. Create a storage class spec for proxy volumes, specifying your own values for the following:

    • parameters.proxy_endpoint: With the endpoint of the external NFS share Portworx is reflecting from.

      note

      The nfs:// prefix instructs Portworx to use the NFS protocol for reflecting an external datasource.

    • parameters.proxy_nfs_exportpath: With the export path on the NFS server.

    • parameters.mount_options: With the standard linux NFS mount options to use while mounting the NFS share. For IPv6, you must set the protocol to tcp6 in the mount_options.

    kind: StorageClass
    apiVersion: storage.k8s.io/v1
    metadata:
    name: portworx-proxy-volume-volume
    provisioner: pxd.portworx.com
    parameters:
    proxy_endpoint: "nfs://<nfs-share-endpoint>"
    proxy_nfs_exportpath: "/<mount-path>"
    mount_options: "vers=<4.0>"
    allowVolumeExpansion: true
  2. Apply the spec:

    kubectl create -f <storageclass-name>.yaml
  3. Create the Portworx proxy volume PVC spec, specifying your own values for the following:

    • spec.accessModes: With the access mode you want to assign to your volumes.
    • spec.resources.requests.storage: With the amount of storage you want to allocate to a created volume.
    kind: PersistentVolumeClaim
    apiVersion: v1
    metadata:
    name: nfs-data
    labels:
    app: nginx
    spec:
    storageClassName: portworx-proxy-volume-volume
    accessModes:
    - <access-mode>
    resources:
    requests:
    storage: <storage-amount>
  4. Apply the spec:

    kubectl create -f <pvc-name>.yaml
  5. Create a Deployment spec that uses the proxy-volume PVC:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
    name: nginx
    spec:
    replicas: 3
    selector:
    matchLabels:
    app: nginx
    template:
    metadata:
    labels:
    app: nginx
    spec:
    containers:
    - name: nginx
    image: bitnami/nginx
    ports:
    - containerPort: 80
    volumeMounts:
    - name: nginx-persistent-storage
    mountPath: /usr/share/nginx/html
    volumes:
    - name: nginx-persistent-storage
    persistentVolumeClaim:
    claimName: nfs-data
  6. Apply the spec:

    kubectl create -f <pod-name>.yaml

Accessing a sub-path of an external NFS share

You can associate a sub-path of an NFS share with Portworx as a proxy volume. Under this approach, applications will have access to a specific sub-path within the NFS share. The examples in these instructions create a proxy volume for an nginx container.

  1. Create a storage class spec for proxy volumes, specifying your own values for the following:

    • parameters.proxy_endpoint: With the endpoint of the external NFS share Portworx is reflecting from.
    note

    The nfs:// prefix instructs Portworx to use the NFS protocol for reflecting an external datasource.

    • parameters.proxy_endpoint: With the export path on the NFS server.
    • parameters.mount_options: With the standard linux NFS mount options to use while mounting the NFS share. For IPv6, you must set the protocol to tcp6 in the mount_options.
    kind: StorageClass
    apiVersion: storage.k8s.io/v1
    metadata:
    name: portworx-proxy-volume-volume
    provisioner: pxd.portworx.com
    parameters:
    proxy_endpoint: "nfs://<nfs-share-endpoint>"
    proxy_nfs_exportpath: "/<mount-path>"
    mount_options: "vers=<4.0>"
    allowVolumeExpansion: true
  2. Apply the spec:

    kubectl create -f <storageclass-name>.yaml
  3. Create the Portworx proxy volume PVC spec, specifying your own values for the following:

    • metadata.annotations.px/proxy-nfs-subpath: With the path to the sub-path directory. Volumes created from this PVC will only have access the sub-path, and none of the directories above it. If the sub-path does not exist, Portworx will create it in the NFS share.

      note

      From the external NFS share only the sub-path provided as the annotation will be accessible to this PVC. The parent NFS share or any other directories will not be accessible.

    • spec.accessModes: With the access mode you want to assign to your volumes.

    • spec.resources.requests.storage: With the amount of storage you want to allocate to a created volume.

    kind: PersistentVolumeClaim
    apiVersion: v1
    metadata:
    name: nfs-data
    annotations:
    px/proxy-nfs-subpath: "<path>/<sub-path>"
    labels:
    app: nginx
    spec:
    storageClassName: portworx-proxy-volume-volume
    accessModes:
    - <access-mode>
    resources:
    requests:
    storage: <storage-amount>
    note

    This PVC can only access the <sub-path> directory and its contents.

  4. Apply the spec:

    kubectl create -f <pvc-for-sub-path-name>.yaml
  5. Create a Deployment spec that uses the proxy-volume PVC you created in the step above:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
    name: nginx
    spec:
    replicas: 3
    selector:
    matchLabels:
    app: nginx
    template:
    metadata:
    labels:
    app: nginx
    spec:
    containers:
    - name: nginx
    image: bitnami/nginx
    ports:
    - containerPort: 80
    volumeMounts:
    - name: nginx-persistent-storage
    mountPath: /usr/share/nginx/html
    volumes:
    - name: nginx-persistent-storage
    persistentVolumeClaim:
    claimName: nfs-data
  6. Apply the spec:

    kubectl create -f <pod-name>.yaml