ㅁ We have deployed a POD. Inspect the POD and wait for it to start running. In the current(default) namespace.
kubectl get pod
ㅁ The application stores logs at location /log/app.log. View the logs.
You can exec in to the container and open the file:
kubectl exec webapp -- cat /log/app.log
ㅁ If the POD was to get deleted now, would you be able to view these logs.
apiVersion: v1
kind: Pod
metadata:
name: webapp
namespace: default
spec:
containers:
- image: kodekloud/event-simulator
name: webapp
volumeMounts:
- mountPath: /log
name: webapp-log
volumes:
- name: webapp-log
hostPath:
path: /var/log/webapp
type: Directory
ㅁ Create a persistent Volume with the given specification.
- Volume Name: pv-log
- Storage: 100Mi
- Access Modes: ReadWriteMany
- Host Path: /pv/log
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-log
spec:
storageClassName: ""
capacity:
storage: 100Mi
volumeMode: Filesystem
accessModes:
- ReadWriteMany
hostPath:
path: /pv/log
ㅁ Let us claim some of that storage for our application. Create a Persistent Volume Claim with the given specification
- Volume Name: claim-log-1
- Storage Request: 50Mi
- Access Modes: ReadWriteOnce
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: claim-log-1
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 50Mi
ㅁ What is the state of the Persistent Volume Claim?
$ kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
claim-log-1 Pending 109s
ㅁ What is the state of the Persistent Volume?
$ kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
pv-log 100Mi RWX Retain Available 5m22s
ㅁ Why is the claim not bound to the available Persitent Volume?
[Reclaim Policy not set correctly]
[Capacity Mismatch]
[Access Modes Mismatch]
[PV and PVC name mismatch]
ㅁ You requested for 50Mi, how much capacity is now available to the PVC?
$ kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
claim-log-1 Bound pv-log 100Mi RWX 6s
ㅁ Update the Access Mode on the claim to bind it to the PV
아래와 같이 yaml 수정 후 재배포(delete and create)
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: claim-log-1
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 50Mi
$ kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
claim-log-1 Bound pv-log 100Mi RWX 7s
ㅁ Update the webapp pod to use the persistent volume claim as its storage. Replace hostPath configured earlier with the newly created PersistentVolumeClaim.
- Name: webapp
- Image NAme: kodekloud/event-simulator
- Volume: PersistentVolumeClaim=claim-log-1
- Volume Mount: /log
apiVersion: v1
kind: Pod
metadata:
name: webapp
spec:
containers:
- name: webapp
image: kodekloud/event-simulator
volumeMounts:
- mountPath: /log
name: webapp-log
volumes:
- name: webapp-log
persistentVolumeClaim:
claimName: claim-log-1
$ touch /pv/log/pvc-test
$ kubectl exec webapp -- ls /log
app.log
pvc-test
ㅁ What is the Reclaim Policy set on the Persistent Volume pv-log?
$ kubectl describe pv pv-log
Name: pv-log
Labels: <none>
Annotations: pv.kubernetes.io/bound-by-controller: yes
Finalizers: [kubernetes.io/pv-protection]
StorageClass:
Status: Bound
Claim: default/claim-log-1
Reclaim Policy: Retain
Access Modes: RWX
VolumeMode: Filesystem
Capacity: 100Mi
Node Affinity: <none>
Message:
Source:
Type: HostPath (bare host directory volume)
Path: /pv/log
HostPathType:
Events: <none>
ㅁ Try deleting the PVC and notice what happens
$ kubectl delete pvc claim-log-1
[The PVC is delete]
[The PVC is stuck in 'terminating' state]
ㅁ Why is the PVC stuck in Terminating state?
[The PVC is being used by a POD]
[The PVC is wating for the PV to be deleted]
[The PVC is in the process of scrubbing]
ㅁ Let us now delete the webapp Pod. Once deleted, wait for the pod to fully terminate.
kubectl delete pod webapp
ㅁ What is the state of the PVC now?
kubectl get pvc
[Deleted]
ㅁ What is the state of the Persistent Volume now?
kubectl get pv
[Release]
'CKA &. CKAD > Storage' 카테고리의 다른 글
Storage Class (0) | 2021.03.30 |
---|---|
Volumes and Persistent Volume (0) | 2021.03.30 |
Container Storage Interface (0) | 2021.03.30 |
Docker storage and Volume (0) | 2021.03.30 |