Create PVCs

Objective

This guide provides instructions on how to create and manage Persistent Volume Claim (PVC) for applications running on  F5® Distributed Cloud Services vK8s deployments. A PVC provides access to storage resources whose lifecycle is independent of the lifecycle of pods and the applications.

Kubernetes supports the provisioning and consumption of storage resources called as Persistent Volumes (PV) by means of storage classes. The PVC is used by pods to consume the PVs. For more information on PVCs and PVs, see Persistent Volumes.

Note: In case of multi-node CE sites and RE sites, the PVs are not replicated across nodes. Therefore, in case of a node failure, the data in the PV is lost. Applications such as such as Cassandra and MongoDB may not be impacted due to this as they support replication the application level.

The following image shows the operational view of PV creation and consumption using a PVC.

PvcOps
Figure: PVC Operational View

Using the instructions provided in this guide, you can create and manage a PVC for an application deployed using the F5® Distributed Cloud Console.

Note: For an application to consume storage resources, it needs to be provisioned by the cluster administrator.


Prerequisites

The following prerequisites apply:

  • An application deployed using F5 vK8s.
  • Note: See vK8s Deployment guide to deploy your applications on F5 edge cloud.

Configuration

You can create a PVC and use it in your application deployment using one of the following methods:

  • Create a PVC and add it to your deployment in the F5 Console.

  • Download the kubeconfig of your vK8s deployment from the F5 Console and use kubectl to apply PVC and deployment.

Note: In both methods, it is required that first you create vK8s in the F5 Console..

Configuration Sequence

Creating PVC and using it in the deployment requires you to perform the following sequence of actions.

Phase Description
Create PVC Create a PVC object specifying the storage requirement and access mode.
Create Deployment Create a vK8s deployment applying the PVC.

Note: You can also update an existing deployment to use a created PVC.


Create PVC and Deployment in VoltConsole

Features can be viewed, and managed in multiple services.

This example shows PVCs setup in Distributed Apps.

Step 1: Log into F5® Distributed Cloud Console, change to a desired namespace or create one where your application needs to be deployed.
  • Open F5® Distributed Cloud Console > select Distributed Apps box.

Note: Homepage is role based, and your homepage may look different due to your role customization. Select All Services drop-down menu to discover all options. Customize Settings: Administration > Personal Management > My Account > Edit work domain & skills button > Advanced box > check Work Domain boxes > Save changes button.

NEW HOME PAGE C
Figure: Homepage

  • Select the Namespace drop-down where your vK8s object is created under Distributed Apps.

Note: Confirm Namespace feature is in correct namespace, drop-down selector located in upper-left corner. Not available in all services.

  • Select Applications in left-menu > select Virtual K8s.

Note: If options are not showing available, select Show link in Advanced nav options visible in bottom left corner. If needed, select Hide to minimize options from Advanced nav options mode.

  • Select PVCs.

  • Select + Add PersistantVolumeClaim button.

PVC
Figure: User Management

Step 2: Select Applications from the configuration menu, and Virtual K8s from the options pane. Select on the vK8s object to open its dashboard.
  • Select Applications in Distributed Apps service window.

  • Select Virtual K8s.

  • Select on the vK8s object to open its dashboard.

Note: In case vK8s object is not already created, the Add virtual K8s option will be available to create vK8s. See vK8s Deployment guides for more information.

Step 3: Select the PVCs tab, select Add PersistentVolumeClaim.

The PVC creation form gets loaded.

Step 4: Enter the PVC configuration in the JSON or YAML format.

This example shows a sample PVC configuration.

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mongodb-pvc          *# The name of your claim—you’ll need this later when using the claim as the pod’s volume.*
  namespace: vk8s-pvc
spec:
  accessModes:
    - ReadWriteOnce          *# You want the storage to support a single
client (performing both reads and writes)*
  resources:
    requests:
      storage: 100Mi        *# Requesting 100M of storage*
  volumeMode: Filesystem

Step 5: Select Save to create the PVC object.

PvcUI
Figure: Create PVC in the F5 Console

Step 6: Select the Deployments tab, select Add Deployment to load the deployment creation form.

Note: You can also edit an existing deployment by selecting the ... > Edit option against that deployment.

Step 7: Enter the deployment configuration referencing the PVC created in Step 6. Select Save to create deployment.

DeployUI
Figure: Create PVC in F5 Console

Note: The persistentVolumeClaim section of the deployment configuration references the PVC in the claimName field. Ensure you specify the appropriate PVC object name. For this example, the name of PVC object created in Step 6 is used.


Create PVC and Deployment Using Kubectl

Step 1: Log into the F5® Distributed Cloud Console, change to the namespace where your vK8s object is created.
  • Open F5® Distributed Cloud Console, select Distributed Apps box.

  • Select the Namespace drop-down where your vK8s object is created under Distributed Apps

Step 2: Select Applications from the configuration menu and Virtual K8s from the options pane.
  • Select Applications > Virtual K8s.

  • The vK8s object is displayed in the list.

Note: In case vK8s object is not already created, the Add virtual K8s option will be available to create vK8s. See vK8s Deployment guides for more information.

Step 3: Download Kubeconfig file for your vK8s object.
  • Select ... on Virtual K8s > select Kubeconfig to download file.

Note: Save file to your desktop.

  • Select date in drop-down menu in Please select credential expiry date pop-up window.

  • Select Download Credential button.

Note: Download is being prepared pop-up window will appear in bottom-right initiating file download.

vK8sKubecfg
Figure: Kubeconfig for the vK8s Object

Step 4: Create a PVC configuration file on your local machine in JSON or YAML format.

This example shows a sample PVC configuration.

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mongodb-pvc          *# The name of your claim—you’ll need this later when using the claim as the pod’s volume.*
  namespace: vk8s-pvc
spec:
  accessModes:
    - ReadWriteOnce          *# You want the storage to support a single
client (performing both reads and writes)*
  resources:
    requests:
      storage: 100Mi        *# Requesting 100M of storage*
  volumeMode: Filesystem

Step 5: Create a deployment configuration file on your local machine in JSON or YAML format.

This example shows a sample configuration.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mongodb
  namespace: vk8s-pvc
  annotations:
    ves.io/workload-flavor: medium
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mongodb
  template:
    metadata:
      labels:
        app: mongodb
    spec:
      containers:
      - image: mongo
        name: mongodb
        volumeMounts:
        - name: mongodb-data
          mountPath: /data/db
        ports:
        - containerPort: 27017
          protocol: TCP
      volumes:
      - name: mongodb-data
        persistentVolumeClaim:
          claimName: mongodb-pvc *# Referencing the PersistentVolumeClaim by name in the pod volume*

Step 6: Create and export the KUBECONFIG environment variable using the kubeconfig file downloaded in Step 3.

This example uses the kubeconfig file downloaded to the Downloads folder.

export KUBECONFIG=~/Downloads/ves_vk8s-pvc_vk8s1.yaml

Step 7: Create PVC and deployment objects using the configuration files created in Step 4 and Step 5 respectively.
kubectl apply -f pvc.yml
kubectl apply -f deployment.yml


Verify PVC Operation

Creating PVC creates the PV and PVC objects. Creating deployment creates a pod which uses pvc for its storage. You can verify the created objects and access the storage resource to execute operations such as read or write as per the configured access mode.

Step 1: Verify the PV information.
kubectl get pv
NAME                                       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                  STORAGECLASS   REASON   AGE
pvc-584c4a18-cf6f-4f4d-8f4a-53828ff2d999   1Gi        RWO            Delete           Bound    vk8s-pvc/mongodb-pvc   standard                3m46s

kubectl describe pv
Name:            pvc-584c4a18-cf6f-4f4d-8f4a-53828ff2d999
Labels:          <none>
Annotations:     pv.kubernetes.io/bound-by-controller: yes
                 pv.kubernetes.io/provisioned-by: kubernetes.io/azure-disk
                 volumehelper.VolumeDynamicallyCreatedByKey: azure-disk-dynamic-provisioner
Finalizers:      [kubernetes.io/pv-protection]
StorageClass:    standard
Status:          Bound
Claim:           vk8s-pvc/mongodb-pvc
Reclaim Policy:  Delete
Access Modes:    RWO
VolumeMode:      Filesystem
Capacity:        1Gi
Node Affinity:   <none>
Message:
Source:
    Type:         AzureDisk (an Azure Data Disk mount on the host and bind mount to the pod)
    DiskName:     kubernetes-dynamic-pvc-584c4a18-cf6f-4f4d-8f4a-53828ff2d999
    DiskURI:      /subscriptions/f68d94a5-1db7-4954-9a79-02b5711cb0a1/resourceGroups/demo-ce/providers/Microsoft.Compute/disks/kubernetes-dynamic-pvc-584c4a18-cf6f-4f4d-8f4a-53828ff2d999
    Kind:         Managed
    FSType:
    CachingMode:  ReadOnly
    ReadOnly:     false
Events:           <none>
Step 2: Verify the PVC information.
kubectl get pvc
NAME          STATUS   VOLUME   CAPACITY   ACCESS MODES   STORAGECLASS   AGE
mongodb-pvc   Bound                                                      4m16s
kubectl describe pvc
Name:          mongodb-pvc
Namespace:     vk8s-pvc
StorageClass:
Status:        Bound
Volume:
Labels:        <none>
Annotations:   <none>
Finalizers:    [kubernetes.io/pvc-protection]
Capacity:
Access Modes:
VolumeMode:    Filesystem
Mounted By:    mongodb-bcbf9745-6nkzz
Events:        <none>

Step 3: Verify the deployment and pod status.
kubectl get deployment
NAME      READY   UP-TO-DATE   AVAILABLE   AGE
mongodb   1/1     1            1           25m
kubectl get pod
NAME                     READY   STATUS    RESTARTS   AGE
mongodb-bcbf9745-6nkzz   2/2     Running   0          25m

Step 4: Access your application using the pod information obtained in Step 3.

This example opens the MongoDB shell.

kubectl exec -it mongodb-bcbf9745-6nkzz mongo
Defaulting container name to mongodb.
Use 'kubectl describe pod/mongodb-bcbf9745-6nkzz -n vk8s-pvc' to see all of the containers in this pod.
MongoDB shell version v4.2.3
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("c84807bb-c22b-41c6-9103-6f51f89cd3b2") }
MongoDB server version: 4.2.3
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
	http://docs.mongodb.org/
Questions? Try the support group
	http://groups.google.com/group/mongodb-user
...

>
Step 5: You can perform database operations to update data to the persistent storage.

This samples writes JSON documents to the MongoDB.

> use mystore
switched to db mystore
> db.foo.find()
> db.foo.insert({name:'foo'})
WriteResult({ "nInserted" : 1 })
> db.foo.insert({name:'test'})
WriteResult({ "nInserted" : 1 })
>

Verify the records from the MongoDB shell.

> db.foo.find()
{ "_id" : ObjectId("5e7761abf01f2bc511bd6b8a"), "name" : "foo" }
{ "_id" : ObjectId("5e7761b5f01f2bc511bd6b8b"), "name" : "test" }
>
> exit
bye

Step 6: Delete your deployment and recreate the deployment.
kubectl delete -f deployment.yml
deployment.apps "mongodb" deleted


kubectl get pods
No resources found in vk8s-pvc namespace.

kubectl apply -f deployment.yml
deployment.apps/mongodb created

kubectl get pods
NAME                     READY   STATUS    RESTARTS   AGE
mongodb-bcbf9745-g6vqv   2/2     Running   0          61s

Step 7: Access the MongoDB shell using the new pod name, and verify the records created in Step 5.

The records persist during the deployment or pod restarts.


Delete PVC

You can delete PVCs in using the kubectl delete command or from the F5 Console.

  • To delete using kubectl, specify the PVC either by file or by name.
kubectl delete -f <file.yaml>
kubectl delete pvc <pvc-name>

  • To delete from the F5 Console, change to the namespace where your application is deployed.

    • Select Applications from the configuration menu, and Virtual K8s from the options pane.

    • Select on the vK8s objects and select PVCs tab in the dashboard.

    • Select ... > Delete for your PVC and confirm deletion.

Delete_pvc_pvc
Figure: Delete PVC in the F5 Console

Note: If you delete a PVC that is in active use by a pod, the PVC is not removed immediately. PVC removal is postponed until the PVC is no longer actively used by any pods. Also, if an admin deletes a PV that is bound to a PVC, the PV is not removed immediately. PV removal is postponed until the PV is no longer bound to a PVC.


Concepts


API References