Storage Red Hat build of MicroShift 4.18 Configuring and managing cluster storage Red Hat OpenShift Documentation Team

Commands:
apiVersion: v1 kind: Pod metadata: name: frontend spec: containers: - name: app image: images.my-company.example/app:v4 resources: requests: ephemeral-storage: "2Gi" 1 limits: ephemeral-storage: "4Gi" 2 volumeMounts: - name: ephemeral mountPath: "/tmp" - name: log-aggregator image: images.my-company.example/log-aggregator:v6 resources: requests: ephemeral-storage: "2Gi" limits: ephemeral-storage: "4Gi" volumeMounts: - name: ephemeral mountPath: "/tmp" volumes: - name: ephemeral emptyDir: {}
df -h /var/lib
Filesystem Size Used Avail Use% Mounted on /dev/disk/by-partuuid/4cd1448a-01 69G 32G 34G 49% /
kind: Pod apiVersion: v1 metadata: name: my-app spec: containers: - name: my-frontend image: busybox:1.28 volumeMounts: - mountPath: "/mnt/storage" name: data command: [ "sleep", "1000000" ] volumes: - name: data 1 ephemeral: volumeClaimTemplate: metadata: labels: type: my-app-ephvol spec: accessModes: [ "ReadWriteOnce" ] storageClassName: "topolvm-provisioner" resources: requests: storage: 1Gi
oc delete pv <pv-name>
oc get pv
NAME CAPACITY ACCESSMODES RECLAIMPOLICY STATUS CLAIM STORAGECLASS REASON AGE pvc-b6efd8da-b7b5-11e6-9d58-0ed433a7dd94 4Gi RWO Delete Bound default/claim1 manual 10s pvc-b95650f8-b7b5-11e6-9d58-0ed433a7dd94 4Gi RWO Delete Bound default/claim2 manual 6s pvc-bb3ca71d-b7b5-11e6-9d58-0ed433a7dd94 4Gi RWO Delete Bound default/claim3 manual 3s
oc patch pv <your-pv-name> -p '{"spec":{"persistentVolumeReclaimPolicy":"Retain"}}'
oc get pv
NAME CAPACITY ACCESSMODES RECLAIMPOLICY STATUS CLAIM STORAGECLASS REASON AGE pvc-b6efd8da-b7b5-11e6-9d58-0ed433a7dd94 4Gi RWO Delete Bound default/claim1 manual 10s pvc-b95650f8-b7b5-11e6-9d58-0ed433a7dd94 4Gi RWO Delete Bound default/claim2 manual 6s pvc-bb3ca71d-b7b5-11e6-9d58-0ed433a7dd94 4Gi RWO Retain Bound default/claim3 manual 3s
apiVersion: v1 kind: PersistentVolume metadata: name: pv0001 1 spec: capacity: storage: 5Gi 2 accessModes: - ReadWriteOnce 3 persistentVolumeReclaimPolicy: Retain 4 status:
oc get pv <pv-name> -o jsonpath='{.spec.claimRef.name}'
oc get pv <pv-name> -o json | jq '.status.lastPhaseTransitionTime' 1
apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: annotations: storageclass.kubernetes.io/is-default-class: "true" name: topolvm-provisioner mountOptions: - uid=1500 - gid=1500 parameters: csi.storage.k8s.io/fstype: xfs provisioner: topolvm.io reclaimPolicy: Delete volumeBindingMode: WaitForFirstConsumer allowVolumeExpansion: true
oc get pods -n <pod_name_a> -ojsonpath='{.spec.containers[ ].volumeMounts[ ].mountPath}' 1
/files /var/run/secrets/kubernetes.io/serviceaccount
oc get pods -n <pod_name_b> -ojsonpath='{.spec.containers[ ].volumeMounts[ ].mountPath}' 1
/files /var/run/secrets/kubernetes.io/serviceaccount
oc rsh <pod_name_a> ls -lZah <pvc_mountpoint> 1
total 12K dr-xr-xr-x. 1 root root system_u:object_r:container_file_t:s0:c398,c806 40 Feb 17 13:36 . dr-xr-xr-x. 1 root root system_u:object_r:container_file_t:s0:c398,c806 40 Feb 17 13:36 .. [...]
oc rsh <pod_name_b> ls -lZah <pvc_mountpoint> 1
total 12K dr-xr-xr-x. 1 root root system_u:object_r:container_file_t:s0:c15,c25 40 Feb 17 13:34 . dr-xr-xr-x. 1 root root system_u:object_r:container_file_t:s0:c15,c25 40 Feb 17 13:34 .. [...]
[...] securityContext:privileged seLinuxOptions:MustRunAs level: "s0:cXX,cYY" [...]
oc describe pod <pod_name_a> |grep -i scc 1
openshift.io/scc: restricted
oc describe pod <pod_name_b> |grep -i scc 1
openshift.io/scc: restricted
oc exec <pod_name_a> -- ls -laZ <pvc_mountpoint> 1
total 4 drwxrwsrwx. 2 root 1000670000 system_u:object_r:container_file_t:s0:c10,c26 19 Aug 29 18:17 . dr-xr-xr-x. 1 root root system_u:object_r:container_file_t:s0:c10,c26 61 Aug 29 18:16 .. -rw-rw-rw-. 1 1000670000 1000670000 system_u:object_r:container_file_t:s0:c10,c26 29 Aug 29 18:17 test1 [...]
oc exec <pod_name_b> -- ls -laZ <pvc_mountpoint> 1
total 4 drwxrwsrwx. 2 root 1000670000 system_u:object_r:container_file_t:s0:c10,c26 19 Aug 29 18:17 . dr-xr-xr-x. 1 root root system_u:object_r:container_file_t:s0:c10,c26 61 Aug 29 18:16 .. -rw-rw-rw-. 1 1000670000 1000670000 system_u:object_r:container_file_t:s0:c10,c26 29 Aug 29 18:17 test1 [...]
kind: PersistentVolumeClaim apiVersion: v1 metadata: name: myclaim 1 spec: accessModes: - ReadWriteOnce 2 resources: requests: storage: 8Gi 3 storageClassName: gold 4 status:
kind: Pod apiVersion: v1 metadata: name: mypod spec: containers: - name: myfrontend image: dockerfile/nginx volumeMounts: - mountPath: "/var/www/html" 1 name: mypd 2 volumes: - name: mypd persistentVolumeClaim: claimName: myclaim 3
securityContext: runAsUser: 1000 runAsGroup: 3000 fsGroup: 2000 fsGroupChangePolicy: "OnRootMismatch" 1
kind: PersistentVolumeClaim apiVersion: v1 metadata: name: ebs spec: storageClass: "storageClassWithFlagSet" accessModes: - ReadWriteOnce resources: requests: storage: 8Gi 1
oc describe pvc <pvc_name>
Warning ProvisioningFailed 3s (x2 over 5s) topolvm.cybozu.com_topolvm-controller-858c78d96c-xttzp_0fa83aef-2070-4ae2-bcb9-163f818dcd9f failed to provision volume with StorageClass "topolvm-provisioner": rpc error: code = ResourceExhausted desc = no enough space left on VG: free=(BYTES_INT), requested=(BYTES_INT)
storage: {} 1
sudo systemctl start microshift
storage driver: - "none" 1
sudo systemctl enable --now microshift
oc delete -n kube-system deployment.apps/snapshot-controller
deployment.apps "snapshot-controller" deleted
oc delete -n openshift-storage lvmclusters.lvm.topolvm.io/lvms
lvmcluster.lvm.topolvm.io "lvms" deleted
oc delete -n openshift-storage deployment.apps/lvms-operator
deployment.apps "lvms-operator" deleted
oc delete storageclasses.storage.k8s.io/topolvm-provisioner
storageclass.storage.k8s.io "topolvm-provisioner" deleted
sudo cp /etc/microshift/lvmd.yaml.default /etc/microshift/lvmd.yaml
socket-name: 1 device-classes: 2 - name: "default" 3 volume-group: "VGNAMEHERE" 4 spare-gb: 0 5 default: 6
cat <<EOF | oc apply -f - kind: PersistentVolumeClaim apiVersion: v1 metadata: name: my-lv-pvc spec: accessModes: - ReadWriteOnce resources: requests: storage: 1G --- apiVersion: v1 kind: Pod metadata: name: my-pod spec: containers: - name: nginx image: nginx command: ["/usr/bin/sh", "-c"] args: ["sleep", "1h"] volumeMounts: - mountPath: /mnt name: my-volume securityContext: allowPrivilegeEscalation: false capabilities: drop: - ALL runAsNonRoot: true seccompProfile: type: RuntimeDefault volumes: - name: my-volume persistentVolumeClaim: claimName: my-lv-pvc EOF
socket-name: /run/topolvm/lvmd.sock device-classes: - name: ssd volume-group: ssd-vg spare-gb: 0 1 default: true - name: hdd volume-group: hdd-vg spare-gb: 0 - name: thin spare-gb: 0 thin-pool: name: thin overprovision-ratio: 10 type: thin volume-group: ssd - name: striped volume-group: multi-pv-vg spare-gb: 0 stripe: 2 stripe-size: "64" lvcreate-options: 2
socket-name: 1 device-classes: 2 - name: thin 3 default: true spare-gb: 0 4 thin-pool: name: thin overprovision-ratio: 1 5 type: thin 6 volume-group: ssd 7
apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: annotations: storageclass.kubernetes.io/is-default-class: "true" 1 name: topolvm-provisioner parameters: "csi.storage.k8s.io/fstype": "xfs" 2 provisioner: topolvm.io 3 reclaimPolicy: Delete volumeBindingMode: WaitForFirstConsumer 4 allowVolumeExpansion: 5
apiVersion: snapshot.storage.k8s.io/v1 kind: VolumeSnapshotClass metadata: name: topolvm-snapclass annotations: snapshot.storage.kubernetes.io/is-default-class: "true" 1 driver: topolvm.io 2 deletionPolicy: Delete 3
oc apply -f - <<EOF apiVersion: v1 kind: PersistentVolumeClaim metadata: name: test-claim-thin spec: accessModes: - ReadWriteOnce resources: requests: storage: 1Gi storageClassName: topolvm-provisioner-thin --- apiVersion: v1 kind: Pod metadata: name: base spec: containers: - command: - nginx - -g - 'daemon off;' image: registry.redhat.io/rhel8/nginx-122@sha256:908ebb0dec0d669caaf4145a8a21e04fdf9ebffbba5fd4562ce5ab388bf41ab2 name: test-container securityContext: allowPrivilegeEscalation: false capabilities: drop: - ALL volumeMounts: - mountPath: /vol name: test-vol securityContext: runAsNonRoot: true seccompProfile: type: RuntimeDefault volumes: - name: test-vol persistentVolumeClaim: claimName: test-claim-thin EOF
oc delete my-pod
oc apply -f <<EOF apiVersion: snapshot.storage.k8s.io/v1 kind: VolumeSnapshot 1 metadata: name: <snapshot_name> 2 spec: volumeSnapshotClassName: topolvm-snapclass 3 source: persistentVolumeClaimName: test-claim-thin 4 EOF
oc wait volumesnapshot/<snapshot_name> --for=jsonpath\='{.status.readyToUse}=true'
oc get volumesnapshot -n <namespace> <snapshot_name> -o 'jsonpath={.status.volumeSnapshotContentName}' 1
oc get volumesnapshotcontent snapcontent-<retrieved_volume_identity> -o 'jsonpath={.status.snapshotHandle}' 1
sudo lvdisplay <retrieved_volume_identity> 1
--- Logical volume --- LV Path /dev/rhel/732e45ff-f220-49ce-859e-87ccca26b14c LV Name 732e45ff-f220-49ce-859e-87ccca26b14c VG Name rhel LV UUID 6Ojwc0-YTfp-nKJ3-F9FO-PvMR-Ic7b-LzNGSx LV Write Access read only LV Creation host, time rhel-92.lab.local, 2023-08-07 14:45:26 -0500 LV Pool name thinpool LV Thin origin name a2d2dcdc-747e-4572-8c83-56cd873d3b07 LV Status available open 0 LV Size 1.00 GiB Mapped size 1.04% Current LE 256 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:11
sudo mkdir /mnt/snapshot
sudo mount /dev/<retrieved_snapshot_handle> /mnt/snapshot 1
sudo cp -r /mnt/snapshot <destination> 1
oc apply -f <<EOF apiVersion: v1 kind: PersistentVolumeClaim metadata: name: snapshot-restore spec: accessModes: - ReadWriteOnce dataSource: apiGroup: snapshot.storage.k8s.io kind: VolumeSnapshot name: my-snap resources: requests: storage: 1Gi storageClassName: topolvm-provisioner-thin --- apiVersion: v1 kind: Pod metadata: name: base spec: containers: - command: - nginx - -g - 'daemon off;' image: registry.redhat.io/rhel8/nginx-122@sha256:908ebb0dec0d669caaf4145a8a21e04fdf9ebffbba5fd4562ce5ab388bf41ab2 name: test-container securityContext: allowPrivilegeEscalation: false capabilities: drop: - ALL volumeMounts: - mountPath: /vol name: test-vol securityContext: runAsNonRoot: true seccompProfile: type: RuntimeDefault volumes: - name: test-vol persistentVolumeClaim: claimName: snapshot-restore EOF
oc wait --for=condition=Ready pod/base
apiVersion: snapshot.storage.k8s.io/v1 kind: VolumeSnapshotClass metadata: name: csi-hostpath-snap driver: hostpath.csi.k8s.io deletionPolicy: Delete 1
oc delete volumesnapshot <volumesnapshot_name> 1
volumesnapshot.snapshot.storage.k8s.io "mysnapshot" deleted
oc delete volumesnapshotcontent <volumesnapshotcontent_name> 1
oc patch -n USDPROJECT volumesnapshot/USDNAME --type=merge -p '{"metadata": {"finalizers":null}}'
volumesnapshotclass.snapshot.storage.k8s.io "csi-ocs-rbd-snapclass" deleted
apiVersion: migration.k8s.io/v1alpha1 kind: StorageVersionMigration metadata: name: snapshot-v1 spec: resource: group: snapshot.storage.k8s.io resource: volumesnapshotclasses 1 version: v1 2