Volumes,Persistent Volumes and PVC Flashcards
What are volumes ?
when a container restarts the state of application is reset. To keep some state we require volume concept .
Also when sharing files between two containers in a POD , we use volumes
ex:- awsElasticBlockStore ; azureDisk ;
configMap (after u create a confiMap object , you can use configMap
type in POD to consume the configuration inside a container )
what is persistent volume ?
PersistentVolume (PV) is a piece of storage in the cluster that has been provisioned by an administrator or dynamically provisioned using Storage Classes
persistent volume claim - volume type
A persistentVolumeClaim volume is used to mount a PersistentVolume into a Pod. PersistentVolumeClaims are a way for users to “claim” durable storage (such as a GCE PersistentDisk or an iSCSI volume) without knowing the details of the particular cloud environment.
what is persistent volume claim ?
PersistentVolumeClaim (PVC) is a request for storage by a user
secret
volume
A secret volume is used to pass sensitive information, such as passwords, to Pods. You can store secrets in the Kubernetes API and mount them as files for use by Pods without coupling to Kubernetes directly. secret volumes are backed by tmpfs (a RAM-backed filesystem) so they are never written to non-volatile storage
imperative commands for pv, pvc
$ alias k=kubectl
$ k create -f pv.yaml [if declarative
$ k get pv , pvc
declarative
persistent volumes
apiVersion: v1 kind: PersistentVolume metadata: name: pv0003 spec: capacity: storage: 5Gi volumeMode: Filesystem accessModes: - ReadWriteOnce persistentVolumeReclaimPolicy: Recycle mountOptions: - hard - nfsvers=4.1 nfs: path: /tmp server: 172.17.0.2
persitent volume claims ? write declarative
- every persistentvolumeclaim binds to one persistentvolume
- you can also customize to bind to a particular PersistentVolume by using labels and selectors
also - claimRef tag is used on PV to bind to PVC , volumeName can be used to bing PVC to PV
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: myclaim spec: accessModes: - ReadWriteOnce resources: requests: storage: 3Gi
…
how to check if persistent volume is there on pod or not
$ kubectl describe po pod-name
and check for Volumes: in it
check the logs in a container
POD: webapp
log path : /log/app.log
$ kubectl exec -it webapp – cat /log/app.log
volumeMount Vs volumes field
volumeMounts:
- mountPath: /var/log
it is the path inside a container where you want to mount a volume
volumes:
- name: vol-log
hostpath:
path: /log/app
volumes ( 23+ types )
different types of volumes are present .
for example hostpath is the path from underlying host (node) which can be mounted to a container
create PV for hostpath
path: /app/log
storage: 5Gi
apiVersion: v1 kind: PersistentVolume metadata: name: pv0003 spec: capacity: storage: 5Gi volumeMode: Filesystem accessModes: - ReadWriteMany hostpath: path: /var/log
when access modes differ for Persistent volume and Persistent volume claim , does pvc bind to pv
NO
when does a PVC get stuck in TERMINATING state
when the PVC is being used by a POD