$ oc new-project workshop-pvc-demo-YourName
10 Using Persistent Storage
Prerequisites
-
You have access to OpenShift Web Console URL. Ask your workshop coordinator for URL if you don’t have one.
-
You have credentials to login. Ask your workshop coordinator for credentials to log onto the OpenShift cluster
Introduction
With OpenShift files that live on the container instance are ephemeral. This means that once the pod is destroyed or reinstantiated any changes to the files or data storage on the container is destoryed.
PersistentVolume (PV) is an API object, which represents a piece of existing storage in the cluster that was either statically provisioned by the cluster administrator or dynamically provisioned using a StorageClass object. It is a resource in the cluster just like a node is a cluster resource.
Types of PVs
PersistentVolume
plug-ins:-
AWS Elastic Block Store (EBS)
-
Azure Disk
-
Azure File
-
Cinder
-
Fibre Channel
-
GCE Persistent Disk
-
HostPath
-
iSCSI
-
Local volume
-
NFS
-
Red Hat OpenShift Container Storage
-
VMware vSphere
Bij de NPO ondersteunen wij Red Hat OpenShift Container Storage of AWS Elastic Block Store (EBS)
Volume Plug-in | ReadWriteOnce | ReadOnlyMany | ReadWriteMany |
---|---|---|---|
AWS EBS |
√ |
- |
- |
Azure File |
√ |
√ |
√ |
Azure Disk |
√ |
- |
- |
Cinder |
√ |
- |
- |
Fibre Channel |
√ |
√ |
- |
GCE Persistent Disk |
√ |
- |
- |
HostPath |
√ |
- |
- |
iSCSI |
√ |
√ |
- |
Local volume |
√ |
- |
- |
NFS |
√ |
√ |
√ |
Red Hat OpenShift Container Storage |
√ |
- |
√ |
vSphere |
√ |
- |
- |
PersistentVolumeClaim is an API Object, which represents a request for storage by a developer. It is similar to a Pod in that Pods consume node resources and PVCs consume PV resources. A PVC provides an abstraction layer to underlying storage. An administrator could create a number of static persistent volumes (PVs) that can later be bound to one or more persistent volume claims.
Exercise
Prepare Exercise
-
Login to OpenShift
-
Create new project
Change userXX to your username provided by your workshop coordinator. |
Create a Persistent Volume Claim
-
Create a pv definition file.
cat >myclaim-YourName-pvc.yml<<EOF
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: myclaim-YourName
namespace: workshop-pvc-demo-YourName
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
EOF
-
Create the persistent volume claim.
oc create -f myclaim-YourName-pvc.yml
-
Get pvc status*
oc get pvc
-
Mount your pv to a pod by deploying sample app
cat >deploy-pvc.yml<<EOF
apiVersion: apps/v1
kind: Deployment
metadata:
name: pv-deploy
labels:
app: mypv
spec:
replicas: 1
selector:
matchLabels:
app: mypv
template:
metadata:
labels:
app: mypv
spec:
containers:
- name: shell
image: centos:7
command:
- "bin/bash"
- "-c"
- "sleep 10000"
volumeMounts:
- name: mypd
mountPath: "/tmp/persistent"
volumes:
- name: mypd
persistentVolumeClaim:
claimName: myclaim-YourName
EOF
-
Deploy app
$ oc create -f deploy-pvc.yml
deployment.apps/pv-deploy created
-
Get pod name
$ oc get pods
NAME READY STATUS RESTARTS AGE
pv-deploy-f8d4f87f6-mlspk 1/1 Running 0 2m26s
-
Review pod configuration
Name: pv-deploy-6bd44744c4-6h5pk
Namespace: hens-tim-test
Priority: 0
Node: ip-10-1-156-6.eu-central-1.compute.internal/10.1.156.6
Start Time: Thu, 10 Sep 2020 16:18:38 +0200
Labels: app=mypv
pod-template-hash=6bd44744c4
Annotations: k8s.v1.cni.cncf.io/network-status:
[{
"name": "openshift-sdn",
"interface": "eth0",
"ips": [
"10.34.5.147"
],
"default": true,
"dns": {}
}]
k8s.v1.cni.cncf.io/networks-status:
[{
"name": "openshift-sdn",
"interface": "eth0",
"ips": [
"10.34.5.147"
],
"default": true,
"dns": {}
}]
kubernetes.io/limit-ranger: LimitRanger plugin set: cpu, memory request for container shell; cpu, memory limit for container shell
openshift.io/scc: restricted
Status: Running
IP: 10.34.5.147
IPs:
IP: 10.34.5.147
Controlled By: ReplicaSet/pv-deploy-6bd44744c4
Containers:
shell:
Container ID: cri-o://155c9d275677553b161148e392cf781ac6ae1f2b4604584f4e5f32b538233f34
Image: centos:7
Image ID: docker.io/library/centos@sha256:19a79828ca2e505eaee0ff38c2f3fd9901f4826737295157cc5212b7a372cd2b
Port: <none>
Host Port: <none>
Command:
bin/bash
-c
sleep 10000
State: Running
Started: Thu, 10 Sep 2020 16:18:54 +0200
Ready: True
Restart Count: 0
Limits:
cpu: 200m
memory: 128Mi
Requests:
cpu: 200m
memory: 128Mi
Environment: <none>
Mounts:
/tmp/persistent from mypd (rw)
/var/run/secrets/kubernetes.io/serviceaccount from default-token-5twqs (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
mypd:
Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName: myclaim
ReadOnly: false
default-token-5twqs:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-5twqs
Optional: false
QoS Class: Guaranteed
Node-Selectors: <none>
Tolerations: node.kubernetes.io/memory-pressure:NoSchedule
node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled <unknown> default-scheduler Successfully assigned hens-tim-test/pv-deploy-6bd44744c4-6h5pk to ip-10-1-156-6.eu-central-1.compute.internal
Normal SuccessfulAttachVolume 31s attachdetach-controller AttachVolume.Attach succeeded for volume "pvc-3850c078-85d8-474a-a85c-d4dbc9388e4b"
Normal AddedInterface 25s multus Add eth0 [10.34.5.147/23]
Normal Pulling 25s kubelet, ip-10-1-156-6.eu-central-1.compute.internal Pulling image "centos:7"
Normal Pulled 15s kubelet, ip-10-1-156-6.eu-central-1.compute.internal Successfully pulled image "centos:7"
Normal Created 15s kubelet, ip-10-1-156-6.eu-central-1.compute.internal Created container shell
Normal Started 15s kubelet, ip-10-1-156-6.eu-central-1.compute.internal Started container shell 3m8s kubelet, ip-10-0-159-218.us-east-2.compute.internal Started container shell
-
test mount
$ oc exec -i -t pv-deploy-f8d4f87f6-mlspk /bin/bash
bash-4.2$ df -h
Filesystem Size Used Avail Use% Mounted on
overlay 120G 51G 69G 43% /
tmpfs 64M 0 64M 0% /dev
tmpfs 16G 0 16G 0% /sys/fs/cgroup
shm 64M 0 64M 0% /dev/shm
tmpfs 16G 7.0M 16G 1% /etc/passwd
172.30.182.236:6789,172.30.214.140:6789,172.30.32.187:6789:/volumes/csi/csi-vol-6ffe84a1-f370-11ea-9354-0a580a210620/0a35e01d-4a0f-4e92-8f0a-49dd31633d11 1.0G 0 1.0G 0% /tmp/persistent
/dev/mapper/coreos-luks-root-nocrypt 120G 51G 69G 43% /etc/hosts
tmpfs 16G 32K 16G 1% /run/secrets/kubernetes.io/serviceaccount
tmpfs 16G 0 16G 0% /proc/acpi
tmpfs 16G 0 16G 0% /proc/scsi
tmpfs 16G 0 16G 0% /sys/firmware
bash-4.2$ cd /tmp/persistent
bash-4.2$ touch testfile
bash-4.2$ ls -lath
total 0
-rw-r--r--. 1 1001050000 1001050000 0 Sep 10 14:21 testfile
drwxrwsrwx. 2 root 1001050000 1 Sep 10 14:21 .
drwxrwxrwt. 1 root root 24 Sep 10 14:18 ..
bash-4.2$ exit
exit
-
Delete the deployment.
$ oc delete -f deploy-pvc.yml
-
Delete the persistent volume claim.
$ oc get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
myclaim-YourName Bound pvc-a4a724b1-b711-40a1-a7c9-f89b7db209c7 1Gi RWO gp2 10m
$ oc delete pvc myclaim-YourName
persistentvolumeclaim "myclaim-YourName" deleted
-
Delete Project
$ oc delete project workshop-pvc-demo-YourName
Summary
In this lab learned about persistent volumes and persistent volume claims. We then created a persistent volume claim and deployed an application.