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 small
PV 생성
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 EOF
PVC 생성
cat <<EOF | kubectl create -n small -f - apiVersion: v1 kind: PersistentVolumeClaim metadata: name: pvc-one spec: accessModes: - ReadWriteMany resources: requests: storage: 200Mi EOF
ResourceQuota 생성
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 small
Deployment 생성
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 small
OR
kubectl describe pod $(kubectl get pod -l run=nginx -n small -o=jsonpath='{.items[0].metadata.name}') -n small
ResourceQuota 확인
kubectl describe ns small
NFS 노드에 연결된 터미널로 이동
/data/
디렉토리에 300MB 크기의 파일 생성sudo dd if=/dev/zero of=/data/bigfile bs=1M count=300
CP 노드에 연결된 터미널로 이동
ResourceQuota에 수동으로 생성한 파일이 반영되는지 확인
kubectl describe ns small
Deployment 삭제
kubectl delete deploy nginx-nfs -n small
ResourceQuota 확인
kubectl describe ns small
PVC 삭제
kubectl delete pvc pvc-one -n small
ResourceQuota 확인
kubectl describe ns small
PV 상태 및 ReclaimPolicy 확인
kubectl get pv nfs
PV 삭제
kubectl delete pv nfs
PV 재생성 - 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 EOF
ResourceQuota 확인
kubectl describe ns small
PVC 생성
cat <<EOF | kubectl create -n small -f - apiVersion: v1 kind: PersistentVolumeClaim metadata: name: pvc-one spec: accessModes: - ReadWriteMany resources: requests: storage: 200Mi EOF
ResourceQuota 확인
kubectl describe ns small
ResourceQuota 변경 - requests.storage 값을 100Mi로 지정
cat <<EOF | kubectl apply -n small -f - apiVersion: v1 kind: ResourceQuota metadata: name: storagequota spec: hard: persistentvolumeclaims: "10" requests.storage: "100Mi" EOF
ResourceQuota 확인
kubectl describe ns small
Deployment 생성
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
Deployment 및 PVC 삭제
{ kubectl delete deploy nginx-nfs -n small kubectl delete pvc pvc-one -n small }
PV가 삭제되었는지 확인
kubectl get pv nfs
PV에 발생한 Event 확인
kubectl describe pv nfs
PV 삭제
kubectl delete pv nfs
LimitRange 생성
cat <<EOF | kubectl -n small apply -f - apiVersion: v1 kind: LimitRange metadata: name: storagelimits spec: limits: - type: PersistentVolumeClaim max: storage: 2Gi min: storage: 1Gi EOF
LimitRagne 및 ResourceQuota 확인
kubectl describe ns small
PV 재생성 -
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 EOF
PV의 ReclaimPolicy 확인
kubectl get pv nfs
PVC 생성 시도
cat <<EOF | kubectl create -n small -f - apiVersion: v1 kind: PersistentVolumeClaim metadata: name: pvc-one spec: accessModes: - ReadWriteMany resources: requests: storage: 200Mi EOF
LimitRange 변경
cat <<EOF | kubectl -n small apply -f - apiVersion: v1 kind: LimitRange metadata: name: storagelimits spec: limits: - type: PersistentVolumeClaim max: storage: 2Gi min: storage: 100Mi EOF
PVC 생성 시도
cat <<EOF | kubectl create -n small -f - apiVersion: v1 kind: PersistentVolumeClaim metadata: name: pvc-one spec: accessModes: - ReadWriteMany resources: requests: storage: 200Mi EOF
ResourceQuota의 requests.storage 값을 500Mi로 변경
cat <<EOF | kubectl apply -n small -f - apiVersion: v1 kind: ResourceQuota metadata: name: storagequota spec: hard: persistentvolumeclaims: "10" requests.storage: "500Mi" EOF
PVC 생성
cat <<EOF | kubectl create -n small -f - apiVersion: v1 kind: PersistentVolumeClaim metadata: name: pvc-one spec: accessModes: - ReadWriteMany resources: requests: storage: 200Mi EOF
Deployment 생성
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
NFS 서버에 생성한 파일이 보이는지 확인
kubectl -n small exec deploy/nginx-nfs -- cat /opt/hello.txt
Deployment 삭제
kubectl delete deploy nginx-nfs -n small
PVC 및 PV 상태 확인
{ kubectl get pvc -n small kubectl get pv }
PVC 삭제
kubectl delete pvc pvc-one -n small
PV 상태 확인
kubectl get pv
PV에 발생한 Event 확인
kubectl describe pv nfs
NFS 노드에 연결된 터미널로 이동
NFS 서버에 생성했던 파일이 존재하는지 확인
ls /data/
CP 노드에 연결된 터미널로 이동
PV 삭제
kubectl delete pv nfs
Namespace 삭제
kubectl delete ns small
Last updated