State Persistence - Volumes Flashcards
How can we specify a volume with Directory for data to be saved by a pod?
... kind: Pod ... spec: containers: - image: ... volumeMounts: - mountPath: /opt name: data-volume volumes: - name: data-volume hostPath: path: /data type: Directoy
-> data volume is mounted on the path /opt on the container
-> therefore /opt is on the /data volume/Directory on the host
What options do exist for volume types?
- data-volume: only useful with one node
- different third party solutions, like aws elastic block storage
What is the downside of regular volumes in large environment?
- every pod definition file defines its volume
- changes would need to be made to all pods
- a more centralized approach can be preffered
What is a persistent Volume?
- cluster-wide pool of storage volumes
- configured by an administrator
- to be used by users deploying applications on the cluster (via PVC)
How do you define a persistent Volume?
apiVersion: v1 kind: PersistentVolume metadata: name: pv-voll spec: accessModes: - ReadWriteOnce (// ReadOnlyMany//ReadWriteMany) capacity: storage: 1Gi hostPath: (not to be used in production, replaced by third party solution) path: /tmp/data persistentVolumeReclaimPolicy: Retain / Delete / Recycle
What are Persistent Volumes and Persistent Volume claims?
- separate objects in Kubernetes namespace
- admin creates set of persistent volumes
- user creates persistent volume claims to use the storage
- once pvcs are created, Kubernetes binds them to PVs based on the request and properties set on the volume
To how many PVs is a PVC bound?
- to only one
What request characteristics define whether a PVC and a PV are bound together?
- sufficient capacity
- Access Modes
- Volume Modes
- Storage Class
How can you select a specific type of PV, if all other characters match?
Using Selector and Labels
What happens if only larger then the PVC PVs are available
- both are bound together
- the remaining capacity of the PV is not used
- 1 to 1 relationship between PV and PVC
What happens if no fitting PV is available to a PVC
PVC remains in a pending state
How do you define a persistent volume claim?
apiVersion: kind: PersistentVolumeClaim metadata: name: myclaim spec: accessModes: - ReadWriteOnce resources: requests: storage: 500Mi
What happens to a PersistentVolume once a Claim gets deleted?
- configurable by Reclaim policy
- by default: Retain -> will remain till manually deleted by the admin, not available for reuse by any other claims
- Delete: deletes the PVs automatically
- Recycle: data in Data volume will be scrubbed before making it available to other claims
How can we use PVCs in pods?
pod.yaml
~~~
spec:
containers:
- name: myfrontend
image: nginx
volumeMounts:
- mountPath: “/var/www/html”
name: mypd
volumes:
- name: mypd
persistentVolumeClaim:
claimName: myclaim
~~~
What volume Type is used to store data in a Pod only as long as that Pod is running on that node?
- emptyDir