0

Scenario

I have a PersistentVolume with volumeModeas Block. It is defined as:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: block-vol
spec:
  accessModes:
  - ReadWriteOnce
  capacity:
    storage: 1Gi
  local:
    path: /dev/sdb # this path on the host specified below is used as a device mount
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - <my-host>
  persistentVolumeReclaimPolicy: Retain
  storageClassName: block-storage
  volumeMode: Block

When I mount this on a statefulset with a VolumeClaimTemplate, I specify it's storage field as 1Gi. However, when exec'd in to the deployed pod, I see that the block size more than 1Gi (It is the actual size of that device on physical machine)

StatefulSet YAML:


apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: nginx
spec:
  selector:
    matchLabels:
      app: nginx
  serviceName: "nginx"
  replicas: 1
  template:
    metadata:
      labels:
        app: nginx
    spec:
      terminationGracePeriodSeconds: 10
      containers:
      - name: nginx
        image: k8s.gcr.io/nginx-slim:0.8
        ports:
        - containerPort: 80
          name: web
        volumeDevices:
        - name: rawdev0
          devicePath: /dev/kdb0
  volumeClaimTemplates:
  - metadata:
      name: rawdev0
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: block-storage
      volumeMode: Block
      resources:
        requests:
          storage: 1Gi

I have used blockdev to find the size of block in bytes:

root@nginx-0:/# ls -lhrt /dev/kdb0 
brw-rw----. 1 root disk 8, 16 Jan 13 19:49 /dev/kdb0

root@nginx-0:/# blockdev --getsize64 /dev/kdb0 
536870912000 #size of block in bytes

Question

What does the storage field signify in this case?

S.Au.Ra.B.H
  • 457
  • 5
  • 9
  • Hey, do u need to know what does storage spec means on both examples? I think the meaning of storage is regarding to use local capacity you have available at the moment to request the block volume. Let me know if we are in the same page. – Hugo Lesta Jan 13 '21 at 20:24
  • @HugoLesta: I did not understand what you meant by - `I think the meaning of storage is regarding to use local capacity you have available at the moment to request the block volume`. Could you elaborate more? – S.Au.Ra.B.H Jan 13 '21 at 20:50

1 Answers1

2

Kubernetes can't do much about the storage size for local volumes. The admin that created the PersistentVolume must set a proper size, for granular sizing he/she should probably create its own partition instead of mapping the local volume to a directory.

The storage size in the PersistentVolumeClaim is a request so that the app at least get a volume of that size.

Jonas
  • 121,568
  • 97
  • 310
  • 388
  • Thanks for the answer. So, the physical block at `/dev/sdb` on the host should be tuned for storage. Is that right? – S.Au.Ra.B.H Jan 13 '21 at 20:44
  • yes, that partitions size should be reflected in the `PersistentVolume` to get a good match between `PersistentVolume` and a requesting `PersistentVolumeClaim` – Jonas Jan 13 '21 at 20:47
  • 1
    Usually when a device is used as local volume, the app can consume the whole volume. – Jonas Jan 13 '21 at 20:48
  • `Usually when a device is used as local volume, the app can consume the whole volume` - thanks. And specifying storage capacity in PV doesn't change this. Right? – S.Au.Ra.B.H Jan 13 '21 at 20:54
  • 1
    No, but it change what apps that can use the PV, only apps with a PVC that requests smaller or equal size than the PV can be scheduled to use it. – Jonas Jan 13 '21 at 20:56