Deploy an Application
This document explains how to deploy an application that uses OpenEBS Local Persistent Volumes (PV) backed by Hostpath. It walks through deploying a Pod that consumes a PersistentVolumeClaim (PVC) and verifying that the storage is dynamically provisioned and attached to the application.
Before You Begin
- Install OpenEBS by following the Installation guide.
- Create the
local-hostpath-pvcPVC by following Create PersistentVolumeClaim. The PVC remains inPendingstate until a Pod that uses it is scheduled, which is expected.
Create a Pod to Consume OpenEBS Local PV Hostpath Storage
-
Save the following Pod definition as
local-hostpath-pod.yaml.apiVersion: v1kind: Podmetadata:name: hello-local-hostpath-podspec:volumes:- name: local-storagepersistentVolumeClaim:claimName: local-hostpath-pvccontainers:- name: hello-containerimage: busyboxcommand:- sh- -c- 'while true; do echo "`date` [`hostname`] Hello from OpenEBS Local PV." >> /mnt/store/greet.txt; sleep $(($RANDOM % 5 + 300)); done'volumeMounts:- mountPath: /mnt/storename: local-storagenoteThe Local PV StorageClasses use
WaitForFirstConsumer. Do not usenodeNamein the Pod spec to select a node. If you do, the PVC remains inPendingstate. Refer to the issue #2915 for more details. -
Create the Pod.
kubectl apply -f local-hostpath-pod.yaml
Verify the Deployment
-
Verify that the container in the Pod is running.
Command
kubectl get pod hello-local-hostpath-pod -
Verify that the data is being written to the volume.
Command
kubectl exec hello-local-hostpath-pod -- cat /mnt/store/greet.txt -
Verify that the container is using the Local PV Hostpath.
Command
kubectl describe pod hello-local-hostpath-podThe output shows the node that the Pod is running on and the persistent volume provided by
local-hostpath-pvc.Sample Output
Name: hello-local-hostpath-podNamespace: defaultPriority: 0Node: gke-user-helm-default-pool-3a63aff5-1tmf/10.128.0.28Start Time: Thu, 16 Apr 2020 17:56:04 +0000...Volumes:local-storage:Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)ClaimName: local-hostpath-pvcReadOnly: false... -
Check the PVC again to see the dynamically provisioned Local PV.
Command
kubectl get pvc local-hostpath-pvcThe
STATUSis nowBound, and a new PV is listed underVOLUME.Sample Output
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGElocal-hostpath-pvc Bound pvc-864a5ac8-dd3f-416b-9f4b-ffd7d285b425 5Gi RWO openebs-hostpath 28m -
Look at the PV details to see where the data is stored. Replace the PV name with the one displayed in the previous step.
Command
kubectl get pv pvc-864a5ac8-dd3f-416b-9f4b-ffd7d285b425 -o yamlThe output shows that the PV was provisioned in response to the PVC request
spec.claimRef.name: local-hostpath-pvc.Sample Output
apiVersion: v1kind: PersistentVolumemetadata:name: pvc-864a5ac8-dd3f-416b-9f4b-ffd7d285b425annotations:pv.kubernetes.io/provisioned-by: openebs.io/local...spec:accessModes:- ReadWriteOncecapacity:storage: 5GiclaimRef:apiVersion: v1kind: PersistentVolumeClaimname: local-hostpath-pvcnamespace: default...local:fsType: ""path: /var/openebs/local/pvc-864a5ac8-dd3f-416b-9f4b-ffd7d285b425nodeAffinity:required:nodeSelectorTerms:- matchExpressions:- key: kubernetes.io/hostnameoperator: Invalues:- gke-user-helm-default-pool-3a63aff5-1tmfpersistentVolumeReclaimPolicy: DeletestorageClassName: openebs-hostpathvolumeMode: Filesystemstatus:phase: Bound
The output shows the following characteristics of an OpenEBS Local PV:
spec.nodeAffinityspecifies the Kubernetes node where the Pod that uses the Hostpath volume is scheduled.spec.local.pathspecifies the unique subdirectory under theBasePathdefined in the StorageClass. The defaultBasePathis/var/openebs/local.
Cleanup
Delete the Pod and the PersistentVolumeClaim that you created.
kubectl delete pod hello-local-hostpath-pod
kubectl delete pvc local-hostpath-pvc
Verify that the PV that was dynamically created is also deleted.
kubectl get pv
Support
If you encounter issues or have a question, file a Github issue, or talk to us on the #openebs channel on the Kubernetes Slack server.