728x90
반응형
Practice Test - Persistent Volume Claims
hostPath
$ alias k=kubectl
$ k edit po webapp
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: "2023-06-12T10:46:35Z"
name: webapp
namespace: default
resourceVersion: "674"
uid: 382c1ae3-0641-4107-9105-eb1ec05b028e
spec:
containers:
- env:
- name: LOG_HANDLERS
value: file
image: kodekloud/event-simulator
imagePullPolicy: Always
name: event-simulator
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: kube-api-access-d299x
readOnly: true
- mountPath: /log
name: host-path-volume
...
volumes:
- name: host-path-volume
hostPath:
path: /var/log/webapp
type: Directory
...
$ k replace -f /tmp/kubectl-edit-430428576.yaml --force
PV & PVC
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-log
spec:
capacity:
storage: 100Mi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
hostPath:
path: "/pv/log"
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: claim-log-1
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 50Mi
상태 확인
$ k get pv,pvc
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
persistentvolume/pv-log 100Mi RWX Retain Available 2m52s
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
persistentvolumeclaim/claim-log-1 Pending
pvc 수정
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: claim-log-1
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 50Mi
$ k replace -f pvc.yaml --force
persistentvolumeclaim "claim-log-1" deleted
persistentvolumeclaim/claim-log-1 replaced
$ k get pv,pvc
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
persistentvolume/pv-log 100Mi RWX Retain Bound default/claim-log-1 4m12s
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
persistentvolumeclaim/claim-log-1 Bound pv-log 100Mi RWX
pod 수정(pvc 연결)
$ k edit po webapp
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: "2023-06-12T10:57:15Z"
name: webapp
namespace: default
resourceVersion: "1514"
uid: 02b2de96-2c8c-4681-8b22-d445196c4828
spec:
containers:
- env:
- name: LOG_HANDLERS
value: file
image: kodekloud/event-simulator
imagePullPolicy: Always
name: event-simulator
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: kube-api-access-d299x
readOnly: true
- mountPath: /log
name: pvc-volume
...
volumes:
- name: pvc-volume
persistentVolumeClaim:
claimName: claim-log-1
...
$ k replace -f /tmp/kubectl-edit-2965563831.yaml --force
Practice Test - Storage Class
$ k get sc
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
local-path (default) rancher.io/local-path Delete WaitForFirstConsumer false 7m23s
local-storage kubernetes.io/no-provisioner Delete WaitForFirstConsumer false 4s
portworx-io-priority-high kubernetes.io/portworx-volume Delete Immediate false 4s
$ k get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
local-pv 500Mi RWO Retain Available local-storage 3m18s
PVC 생성
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: local-pvc
spec:
accessModes:
- ReadWriteOnce
volumeMode: Filesystem
resources:
requests:
storage: 500Mi
storageClassName: local-storage
$ k describe pvc local-pvc
Name: local-pvc
Namespace: default
StorageClass: local-storage
Status: Pending
Volume:
Labels: <none>
Annotations: <none>
Finalizers: [kubernetes.io/pvc-protection]
Capacity:
Access Modes:
VolumeMode: Filesystem
Used By: <none>
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal WaitForFirstConsumer 6s (x3 over 33s) persistentvolume-controller waiting for first consumer to be created before binding
Pod 생성
$ k run nginx --image=nginx:alpine --dry-run=client -o yaml > pod.yaml
$ vi pod.yaml
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: nginx
name: nginx
spec:
containers:
- image: nginx:alpine
name: nginx
resources: {}
volumeMounts:
- mountPath: "/var/www/html"
name: local-pv
dnsPolicy: ClusterFirst
restartPolicy: Always
volumes:
- name: local-pv
persistentVolumeClaim:
claimName: local-pvc
status: {}
$ k apply -f pod.yaml
$ k get po,pvc,pv
NAME READY STATUS RESTARTS AGE
pod/nginx 1/1 Running 0 50s
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
persistentvolumeclaim/local-pvc Bound local-pv 500Mi RWO local-storage 8m9s
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
persistentvolume/local-pv 500Mi RWO Retain Bound default/local-pvc local-storage 13m
Storage Class 생성
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: delayed-volume-sc
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
참고) https://kubernetes.io/docs/concepts/storage/storage-classes/#local
728x90
'기타 > 자격증' 카테고리의 다른 글
[CKA][실습] 9. Networking (0) | 2023.06.19 |
---|---|
[CKA][실습] 8. Install (0) | 2023.06.19 |
[CKA][실습] 6. Security (4) (2) | 2023.05.14 |
[CKA][실습] 6. Security (3) (1) | 2023.05.11 |
[CKA][실습] 6. Security (0) | 2023.03.06 |