kubernetes objects of Volume

Series catalog

Overview
Volume is an abstract of a variety of storage resources, and virtualization. For the management, control, use of storage resources to provide a unified interface. The volume Openstack provide storage for virtual machines, Docker is provided for the container storage volume. Because kubernetes smallest unit that can be deployed to run a pod, so kubernetes the volume provides storage for the pod. Of course, when deployed may not provide Volume pod, the pod in the container where the hard disk using the node, where reading and writing of data can be simultaneously read may be referred to as a layer. This storage is temporary storage container level, not the pod level. Its life cycle and the same container, if the container crash after a restart, that is, the old container is deleted and a new container starts, the old container is readable and writable layer are removed together with the container, on which the data is lost. Similarly if the pod scheduled migration between nodes, and the container layer may be read not migrate scheduling. Therefore, kubernetes need to provide pod-level volume, volume in this article refers specifically to kubernetes.

Volume Types
Volume is an abstraction, there are many specific implementation, each implemented with various objects, features, characteristics. Almost everything can be used as volume, type the following:

awsElasticBlockStore
azureDisk
azureFile
cephfs
configMap
csi
downwardAPI
emptyDir
fc (Fiber Channel)
Flocker
gcePersistentDisk
gitRepo (deprecated)
GlusterFS
hostPath
iscsi
local
nfs
persistentVolumeClaim
Projected
portworxVolume
quobyte
rbd
scaleIO
Secret
storageos
vsphereVolume
here does all of the above types introduced one by one, only the current that may be used local disk storage and distributed storage to make a brief description

Common storage type description and examples
cephfs
cephfs is an excellent, popular cloud storage solution, because it is open source, high availability, resilient and elastic, no special requirements for the operating system, hardware, users can easily set up, using its node no special requirements. It has all the features awsElasticBlockStore statements, and a single voluem plurality of nodes may be used simultaneously. The user first set up their own cephfs environment, and then configure the cluster kubernetes its butt, and finally use its volume provided in the pod, detailed reference here.

configMap
user first creates configMap save and create data which, when data is stored in the database kubernetes etcd in, volume does not yet exist. When a user references configMap created in the pod, the system first creates volume and saves the data on which node, this volume is occupied by the members account storage space. After that you can use it like a normal volume the same.

configMap kubernetes is an object type in the core is essentially based on the volume of the separate management mode configuration information to the pod in the container, it is not used to store persistent data. Detailed reference here.

downwardAPI
and configMap similar manner to transfer information to the volume of the pod in the container. configMap information is transmitted when creating objects by a user, and the information on downwardAPI pod from the object itself, downwardAPI need to create, which is a field in the Spec pod, the pod target content to other fields of the object itself, such as the pod Metadata, image and other information. When you create a pod system first point of the field extracted, and then create a volume and save the extracted field and mount the container can read these fields up.

downwardAPI a means for the purpose of the field information itself is transmitted as pod label, annotation, etc. to the container. Detailed reference here.

emptyDir
will create emptyDir volume when you run the pod instance on the node. It is the first node on an empty directory, the pod of any container can be used in the form of a volume used to mount it. If for some reason the container is deleted and restarted, emptyDir created will be deleted and will not be emptied. When the pod scheduled departure node instances to other nodes or a volume reduction is deleted because, emptyDir is deleted, but the data equivalent pod still lost. Example:

apiVersion: v1
kind: Pod
metadata:
name: test-pd
spec:
containers:

  • image: k8s.gcr.io/test-webserver
    name: test-container
    volumeMounts:
    • mountPath: /cache
      name: cache-volume
      volumes:
  • name: Cache-Volume
    emptyDir: {}
    GlusterFS
    and cephfs as the storage solution popular cloud environment, reference herein in detail, with reference to the example herein.

hostPath
apiVersion: v1
kind: Pod
metadata:
name: test-pd
spec:
containers:

  • image: k8s.gcr.io/test-webserver
    name: test-container
    volumeMounts:
    • mountPath: /test-pd
      name: test-volume
      volumes:
  • name: test-volume
    hostPath:

    directory location on host

    path: /data

    this field is optional

    of the type: Directory
    iscsi
    Internet Small Computer System Interface, which is characterized cheap. Referring to the example herein.

local
and emptyDir similar storage space it occupies node. The difference is that it is a type of object kubernetes, the user can manage like ordinary objects as manage it. emptyDir allocated at run-time open pod example, when deleting a node from the pod. local type of volume created by the user, the system for allocating resources in an appropriate node, scheduled pod on this node can mount it, leaving the pod when it will not disappear unless the user deletes. Example:

apiVersion: v1
kind: PersistentVolume
metadata:
name: example-pv
spec:
capacity:
storage: 100Gi

volumeMode field requires BlockVolume Alpha feature gate to be enabled.

volumeMode: Filesystem
accessModes:

  • ReadWriteOnce
    persistentVolumeReclaimPolicy: Delete
    storageClassName: local-storage
    local:
    path: /mnt/disks/ssd1
    nodeAffinity:
    required:
    nodeSelectorTerms:
    • matchExpressions:
      • key: kubernetes.io/hostname
        operator: In
        values:
        • Node-Example
          NFS
          NFS
          network file system, detailed reference herein.

persistentVolumeClaim
and flocker similar to shield different cloud, detailed reference herein.

projected
if a need to hang the container volume open, such as a plurality of existing Secret, ConfigMap, DownwardAPI the like, the original volume of each such type requires its own directory occupies a mount, and projected together they can, and just hang open to a directory, example:

apiVersion: v1
kind: Pod
metadata:
name: volume-test
spec:
containers:

  • name: container-test
    image: busybox
    volumeMounts:
    • name: all-in-one
      mountPath: “/projected-volume”
      readOnly: true
      volumes:
  • name: all-in-one
    projected:
    sources:
    • secret:
      name: mysecret
      items:
      - key: username
      path: my-group/my-username
    • downwardAPI:
      items:
      - path: “labels”
      fieldRef:
      fieldPath: metadata.labels
      - path: “cpu_limit”
      resourceFieldRef:
      containerName: container-test
      resource: limits.cpu
    • configMap:
      name: myconfigmap
      items:
      - Key: config
      path: My-Group / My-config
      Shenzhen site construction https://www.sz886.com

Guess you like

Origin blog.csdn.net/chenmh12/article/details/91411405