404 Not Found
  • Introduction
  • Monitoring related
    • K8s cluster monitoring
    • Monitor Jenkins with G.A.P on K8s cluster
    • Monitoring tools | projects
      • Grafana
      • AlertManager
      • Prometheus
      • Wavefront
  • Logging related
    • BOSH logs
    • How to gather systemd log
    • K8s cluster logging
    • Logging tools | projects
      • vRealize Log Insight
      • Fluentd
      • syslog vs fluentd
  • Having fun with docker
    • Using docker-compose for redmine
    • Customize Fluentd docker image
  • K8S or Apache Mesos
  • K8S Related
    • Main Architecture
      • Master components
        • API Server
        • etcd
        • Controller Manager
        • Kube Scheduler
      • Worker components
        • kubelet
        • kube-proxy
    • K8S Storage
      • Volume Provisioning
      • Understand CSI
      • How to write CSI
      • VMware CNS
      • K8S storage e2e experiment under VMware vSphere
      • Experiment on Persistent Volume Access Mode
      • Design: Storage in Cluster-API architecture
    • K8S Networking
      • Ingress
      • Endpoints
    • K8S Policies
      • Resource Quotas
    • K8S Management Platform
    • K8S Tests Tool
    • K8S Extension
      • CRDs
        • Custom Resources
        • Custom Controllers
        • How to user code-generator
        • K8S Operators
        • Operators Development Tools
          • Kubebuilder
          • Metacontroller
          • Operator SDK
      • Custom API Server
    • K8S Resource CRUD Workflow
    • K8S Garbage Collection
  • K8S CONTROLLER RELATED
    • IsController: true
    • Controller clients
  • PKS RELATED
    • How to Access VMs and Databases related to PKS
    • PKS Basics
    • BOSH Director
    • Backup and Restore on Ent. PKS with Velero
  • CICD RELATED
    • Configure Jenkins to run on K8S
    • Customize Jenkins JNLP slave image
    • Jenkins global shared libs
  • Google Anthos
    • Google Anthos Day from KubeCon 2019 San Diego
    • Migrate for Anthos
    • Config Connector
  • SYSTEM DESIGN RELATED
    • Design Data Intensive Application - Notes
      • RSM
        • Reliability
        • Scalability
      • Data models and Query Languages
      • Storage and Retrieval
    • How Alibaba Ensure K8S Performance At Large Scale
  • Miscellaneous
    • Knative
    • Serverless
    • Service Mesh
    • gRPC
    • Local persistent volumes
    • ownerReferences in K8S
    • File(NAS) vs Block(SAN) vs Object storage
    • KubeVirt
    • Why K8S HA chooses 3 instead of 5..6..7 as the size of masters?
    • goroutine & go channel
    • How to make docker images smaller
Powered by GitBook
On this page
  • Static provisioning
  • Dynamic provisioning
  • Why dynamic provision
  • End to end workflow (Bottom up)

Was this helpful?

  1. K8S Related
  2. K8S Storage

Volume Provisioning

The first thing to make use of storage is to provision the volumes. And one might need to provision more than one volumes to fit different use cases. In K8S, there two ways to get a volume provisioned: Static provisioning and Dynamic provisioning.

Static provisioning

  • Provision the storage manually by following the instruction from the storage vendor.

If you are using VMware vSphere, you could create VMDK on your vSan datastore

* ssh to your esxi host
[root@esxi-dell-h:/vmfs/volumes/vsan:52fae366e94edb86-c6633d0af03e5aec] mkdir demo
[root@esxi-dell-h:/vmfs/volumes/vsan:52fae366e94edb86-c6633d0af03e5aec] cd demo
[root@esxi-dell-h:/vmfs/volumes/vsan:52fae366e94edb86-c6633d0af03e5aec/9cc4ef5c-370b-7eeb-876d-246e962c2408] vmkfstools -c 2G -d thin -W vsan demo.vmdk
Create: 100% done.
[root@esxi-dell-h:/vmfs/volumes/vsan:52fae366e94edb86-c6633d0af03e5aec/9cc4ef5c-370b-7eeb-876d-246e962c2408] ls
demo.vmdk
  • Next step is to create the PV which consumes the storage you just created.

apiVersion: v1
kind: PersistentVolume
metadata:
  name: demo-pv
spec:
  storageClassName: demo
  capacity:
    storage: 2Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  vsphereVolume:
    volumePath: "[vsanDatastore] demo/demo.vmdk"
    fsType: ext4

storageClass: demois used to bind PVC to this PV. You could have no such StorageClass created before hand.

  • Next step is to create PVC which could consume PV for a pod.

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: demo-pvc
spec:
  storageClassName: demo
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 2Gi

If the storageClassName does not match the one you used for PV, your PVC will not bind to the PV you just created.

  • Use it in Pod or Deployment. The following YAML is just an example for Pod.

apiVersion: v1
kind: Pod
metadata:
  name: demo-pod
spec:
  containers:
  - name: busybox
    image: "k8s.gcr.io/busybox"
    volumeMounts:
    - name: demo-vol
      mountPath: "/demo"
    command: [ "sleep", "1000000" ]
  volumes:
    - name: demo-vol
      persistentVolumeClaim:
        claimName: demo-pvc

Above is the steps you would use to manually provision a storage/volume.

Dynamic provisioning

Why dynamic provision

  • Before dynamic provisioning, cluster administrators had to manually make calls to their cloud or storage provider to provision new storage volumes, and then create PersistentVolume objects to represent them in Kubernetes. With dynamic provisioning, these two steps are automated, eliminating the need for cluster administrators to pre-provision storage. Instead, the storage resources can be dynamically provisioned using the provisioner specified by the StorageClass object.

  • Better resource management ?

End to end workflow (Bottom up)

  • Create StorageClass

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: demo-sc-vsan
provisioner: kubernetes.io/vsphere-volume
parameters:
  storagePolicyName: gold
  datastore: vsanDatastore

The provisioner specifies what volume plugin to be used for dynamic provisioning. The volume plugin is in charge of create and setup the VMDK in the vSphere example, and also create the PV automatically. Differnt vendor has different implementations.

  • The provisioner has kubernetes.io as prefix is the in-tree volume plugin. Its implementation could be found at kubernetes/pkg/volume/vsphere_volume/vsphere_volume.go from https://github.com/kubernetes/kubernetes.git

  • Create PVC

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: demo-sc-pvc
spec:
  storageClassName: demo-sc-vsan
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 2Gi

Once the PVC is created, it will find the storageclass for dynamic provisioning. The storageClassName must match the StorageClass created in step #1.

  • Pod or Deployment uses the PVC

apiVersion: v1
kind: Pod
metadata:
  name: demo-sc-pod
spec:
  containers:
  - name: busybox
    image: "k8s.gcr.io/busybox"
    volumeMounts:
    - name: demo-vol
      mountPath: "/demo"
    command: [ "sleep", "1000000" ]
  volumes:
    - name: demo-vol
      persistentVolumeClaim:
        claimName: demo-sc-pvc

Other references:

PreviousK8S StorageNextUnderstand CSI

Last updated 5 years ago

Was this helpful?

vsphereVolume is the in-tree volume plugin supported by K8S. More details could be found

Follow the tutorial if you would like to use minikube to do some experiments.

The provisioner used above is the in-tree provisioner, more about provisioner for the external storage provisioner could be found .

What is CSI could be found .

The design of volume provisioning could be found .

here
here
here
here
here
Kubernetes Storage on vSphere 101 – StorageClass - CormacHogan.comCormacHogan.com
Dynamic Volume ProvisioningKubernetes
Logo
community/container-storage-interface.md at 1a5277642cef37dd83273236ddf93bde67c342e1 · kubernetes/communityGitHub
Logo
Logo