Skip to content

Latest commit

 

History

History
201 lines (144 loc) · 3.45 KB

Storage.md

File metadata and controls

201 lines (144 loc) · 3.45 KB

Storage (7%)

kubernetes.io > Documentation > Reference > kubectl CLI > kubectl Cheat Sheet

kubernetes.io > Documentation > Concepts > Storage > Volumes

kubernetes.io > Documentation > Concepts > Storage > Types of Volumes

kubernetes.io > Documentation > Concepts > Storage > Persistent Volumes

kubernetes.io > Documentation > Concepts > Storage > Persistent Volume Claims

Understand persistent volumes and know how to create them

show

$ cat persist-pod-volume.yaml

apiVersion: v1
kind: Pod
metadata: 
  name: persistent-pod
spec:
  containers:
  - name: alpine
    image: alpine
    command: ["/bin/sh","-c"]
    args: ["shuf -i 0-100 -n 1 >> /opt/number.out;"]
    volumeMounts:
    - mountPath: /opt
      name: data-volume
      
  volumes:
  - name: data-volume
    hostPath:
      path: /data
      type: Directory
      

$ cat persistent-volume.yaml

apiVersion: v1
kind: PersistentVolume
metadata: 
  name: pv-vol1
spec: 
  accessModes:
     - ReadWriteOnce
  capacity:
    storage: 1Gi
  hostPath:
    path: /tmp/data
    
$ kubectl get persistentvolumes

Understand access modes for volumes

show

ReadWriteOnce – the volume can be mounted as read-write by a single node
ReadOnlyMany – the volume can be mounted read-only by many nodes
ReadWriteMany – the volume can be mounted as read-write by many nodes

Understand persistent volume claims primitive

show

$ cat pvc.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: myclaim
spec:
  accessModes: 
  - ReadWriteOnce
  	persistentVolumeReclaimPolicy: Retain
  
  resources:
    requests:
      storage: 500Mi

Persistent Volume Reclaim Policies:

Retain: No other claims can claim this volume
Delete: Delete the volume 
Recycle: Scrap the data and make the volume available again 

$ kubectl get persistentvolumeclaim
$ kubectl delete persistentvolumeclaim myclaim

$ cat pvc-claim-pod.yaml

apiVersion: v1
kind: Pod
metadata: 
  name: webapp
spec:
  containers:
  - name: event-simulator
    image: kodecloud/event-simulator
    env:
    - name: Log_Handler
      value: file
    volumeMounts:
    - mountPath: /log
      name: log-volume
  volumes:
  - name: log-vol
    persistentVolumeClaim:
      claimName: claim-log-1

Understand Kubernetes storage objects

show

Kubernetes supports several types of Volumes:

    awsElasticBlockStore
    azureDisk
    azureFile
    cephfs
    cinder
    configMap
    csi
    downwardAPI
    emptyDir
    fc (fibre channel)
    flexVolume
    flocker
    gcePersistentDisk
    gitRepo (deprecated)
    glusterfs
    hostPath
    iscsi
    local
    nfs
    persistentVolumeClaim
    projected
    portworxVolume
    quobyte
    rbd
    scaleIO
    secret
    storageos
    vsphereVolume

Know how to configure applications with persistent storage

show

Create a persistent volume claim
Use persistent volume claim in pod