Exercise 8.4: Using a ResourceQuota to Limit PVC Count and Usage
CP 노드에 연결된 터미널로 이동
이전 실습에서 생성했던 리소스 삭제
{ kubectl delete deploy nginx-nfs kubectl delete pvc pvc-one kubectl delete pv nfs }Namespace 생성
kubectl create ns small생성한 Namespace 상세 내용 확인
kubectl describe ns smallPV 생성
cat <<EOF | kubectl create -n small -f - apiVersion: v1 kind: PersistentVolume metadata: name: nfs spec: capacity: storage: 1Gi accessModes: - ReadWriteMany persistentVolumeReclaimPolicy: Retain nfs: path: /data server: mynfs readOnly: false EOFPVC 생성
cat <<EOF | kubectl create -n small -f - apiVersion: v1 kind: PersistentVolumeClaim metadata: name: pvc-one spec: accessModes: - ReadWriteMany resources: requests: storage: 200Mi EOFResourceQuota 생성
cat <<EOF | kubectl apply -n small -f - apiVersion: v1 kind: ResourceQuota metadata: name: storagequota spec: hard: persistentvolumeclaims: "10" requests.storage: "500Mi" EOF위에서 생성한 Namespace에 ResourceQuota가 반영됐는지 확인
kubectl describe ns smallDeployment 생성
cat <<EOF | kubectl create -n small -f - apiVersion: apps/v1 kind: Deployment metadata: labels: run: nginx name: nginx-nfs spec: selector: matchLabels: run: nginx template: metadata: labels: run: nginx spec: containers: - image: nginx imagePullPolicy: Always name: nginx volumeMounts: - name: nfs-vol mountPath: /opt ports: - containerPort: 80 protocol: TCP volumes: - name: nfs-vol persistentVolumeClaim: claimName: pvc-one EOF생성된 Pod 확인
kubectl get pod -l run=nginx -n small생성된 Pod 상세 내용 확인
kubectl describe pod POD_NAME -n smallOR
kubectl describe pod $(kubectl get pod -l run=nginx -n small -o=jsonpath='{.items[0].metadata.name}') -n smallResourceQuota 확인
kubectl describe ns smallNFS 노드에 연결된 터미널로 이동
/data/디렉토리에 300MB 크기의 파일 생성sudo dd if=/dev/zero of=/data/bigfile bs=1M count=300CP 노드에 연결된 터미널로 이동
ResourceQuota에 수동으로 생성한 파일이 반영되는지 확인
kubectl describe ns smallDeployment 삭제
kubectl delete deploy nginx-nfs -n smallResourceQuota 확인
kubectl describe ns smallPVC 삭제
kubectl delete pvc pvc-one -n smallResourceQuota 확인
kubectl describe ns smallPV 상태 및 ReclaimPolicy 확인
kubectl get pv nfsPV 삭제
kubectl delete pv nfsPV 재생성 - spec.persistentVolumeReclaimPolicy 값을 Delete로 지정
cat <<EOF | kubectl create -f - apiVersion: v1 kind: PersistentVolume metadata: name: nfs spec: capacity: storage: 1Gi accessModes: - ReadWriteMany persistentVolumeReclaimPolicy: Delete nfs: path: /data/ server: mynfs readOnly: false EOFResourceQuota 확인
kubectl describe ns smallPVC 생성
cat <<EOF | kubectl create -n small -f - apiVersion: v1 kind: PersistentVolumeClaim metadata: name: pvc-one spec: accessModes: - ReadWriteMany resources: requests: storage: 200Mi EOFResourceQuota 확인
kubectl describe ns smallResourceQuota 변경 - requests.storage 값을 100Mi로 지정
cat <<EOF | kubectl apply -n small -f - apiVersion: v1 kind: ResourceQuota metadata: name: storagequota spec: hard: persistentvolumeclaims: "10" requests.storage: "100Mi" EOFResourceQuota 확인
kubectl describe ns smallDeployment 생성
cat <<EOF | kubectl create -n small -f - apiVersion: apps/v1 kind: Deployment metadata: labels: run: nginx name: nginx-nfs spec: selector: matchLabels: run: nginx template: metadata: labels: run: nginx spec: containers: - image: nginx imagePullPolicy: Always name: nginx volumeMounts: - name: nfs-vol mountPath: /opt ports: - containerPort: 80 protocol: TCP volumes: - name: nfs-vol persistentVolumeClaim: claimName: pvc-one EOFPod가 생성되었는지 확인
kubectl get pod -l run=nginx -n smallDeployment 및 PVC 삭제
{ kubectl delete deploy nginx-nfs -n small kubectl delete pvc pvc-one -n small }PV가 삭제되었는지 확인
kubectl get pv nfsPV에 발생한 Event 확인
kubectl describe pv nfsPV 삭제
kubectl delete pv nfsLimitRange 생성
cat <<EOF | kubectl -n small apply -f - apiVersion: v1 kind: LimitRange metadata: name: storagelimits spec: limits: - type: PersistentVolumeClaim max: storage: 2Gi min: storage: 1Gi EOFLimitRagne 및 ResourceQuota 확인
kubectl describe ns smallPV 재생성 -
spec.persistentVolumeReclaimPolicy값을 Recycle로 지정cat <<EOF | kubectl create -f - apiVersion: v1 kind: PersistentVolume metadata: name: nfs spec: capacity: storage: 1Gi accessModes: - ReadWriteMany persistentVolumeReclaimPolicy: Recycle nfs: path: /data server: mynfs readOnly: false EOFPV의 ReclaimPolicy 확인
kubectl get pv nfsPVC 생성 시도
cat <<EOF | kubectl create -n small -f - apiVersion: v1 kind: PersistentVolumeClaim metadata: name: pvc-one spec: accessModes: - ReadWriteMany resources: requests: storage: 200Mi EOFLimitRange 변경
cat <<EOF | kubectl -n small apply -f - apiVersion: v1 kind: LimitRange metadata: name: storagelimits spec: limits: - type: PersistentVolumeClaim max: storage: 2Gi min: storage: 100Mi EOFPVC 생성 시도
cat <<EOF | kubectl create -n small -f - apiVersion: v1 kind: PersistentVolumeClaim metadata: name: pvc-one spec: accessModes: - ReadWriteMany resources: requests: storage: 200Mi EOFResourceQuota의 requests.storage 값을 500Mi로 변경
cat <<EOF | kubectl apply -n small -f - apiVersion: v1 kind: ResourceQuota metadata: name: storagequota spec: hard: persistentvolumeclaims: "10" requests.storage: "500Mi" EOFPVC 생성
cat <<EOF | kubectl create -n small -f - apiVersion: v1 kind: PersistentVolumeClaim metadata: name: pvc-one spec: accessModes: - ReadWriteMany resources: requests: storage: 200Mi EOFDeployment 생성
cat <<EOF | kubectl create -n small -f - apiVersion: apps/v1 kind: Deployment metadata: labels: run: nginx name: nginx-nfs spec: selector: matchLabels: run: nginx template: metadata: labels: run: nginx spec: containers: - image: nginx imagePullPolicy: Always name: nginx volumeMounts: - name: nfs-vol mountPath: /opt ports: - containerPort: 80 protocol: TCP volumes: - name: nfs-vol persistentVolumeClaim: claimName: pvc-one EOFPod가 생성되었는지 확인
kubectl get pod -l run=nginx -n smallNFS 서버에 생성한 파일이 보이는지 확인
kubectl -n small exec deploy/nginx-nfs -- cat /opt/hello.txtDeployment 삭제
kubectl delete deploy nginx-nfs -n smallPVC 및 PV 상태 확인
{ kubectl get pvc -n small kubectl get pv }PVC 삭제
kubectl delete pvc pvc-one -n smallPV 상태 확인
kubectl get pvPV에 발생한 Event 확인
kubectl describe pv nfsNFS 노드에 연결된 터미널로 이동
NFS 서버에 생성했던 파일이 존재하는지 확인
ls /data/CP 노드에 연결된 터미널로 이동
PV 삭제
kubectl delete pv nfsNamespace 삭제
kubectl delete ns small
Last updated