본문 바로가기
Kubernetes/Study

[K8s-1pro] pv, pvc 테스트 시나리오

by lumination 2025. 6. 20.

https://sunsh0602@github.com/sunsh0602/study.git

 

kubectl apply -f ./k8s-study/sprint1_anotherclass-123_ns.yaml

kubectl apply -f ./k8s-study/sprint1_anotherclass-123_configmap.yaml

kubectl apply -f ./k8s-study/sprint1_anotherclass-123_hpa.yaml

kubectl apply -f ./k8s-study/sprint1_anotherclass-123_secret.yaml

kubectl apply -f ./k8s-study/sprint1_anotherclass-123_svc.yaml

kubectl apply -f ./k8s-study/sprint1_anotherclass-123_pvc.yaml

kubectl apply -f ./k8s-study/sprint1_anotherclass-123_deploy.yaml

쿠버네티스 어나더 클래스

1~4. local 동작 확인

// 1번 API - 파일 생성
curl http://192.168.56.30:31231/create-file-pod
curl http://192.168.56.30:31231/create-file-pv

 

// 2번 - Container 임시 폴더 확인 (안 생김)

[root@k8s-master ~]# kubectl exec -n anotherclass-123 -it <pod-name> -- ls /usr/src/myapp/tmp


// 2번 - Container 영구저장 폴더 확인

[root@k8s-master ~]# kubectl exec -n anotherclass-123 -it <pod-name> -- ls /usr/src/myapp/files/dev


// 2번 - master node 폴더 확인

[root@k8s-master ~]# ls -al /root/k8s-local-volume/1231

// 3번 - Pod 삭제

[root@k8s-master ~]# kubectl delete -n anotherclass-123 pod <pod-name>

// 4번 API - 파일 조회
curl http://192.168.56.30:31231/list-file-pod
curl http://192.168.56.30:31231/list-file-pv

 

 

5. hostPath 동작 확인 - Deployment 수정 후 [1~4] 실행

apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: anotherclass-123
  name: api-tester-1231
spec:
  template:
    spec:
      nodeSelector:
        kubernetes.io/hostname: k8s-master
      containers:
        - name: api-tester-1231
          volumeMounts:
            - name: files
              mountPath: /usr/src/myapp/files/dev
            - name: secret-datasource
              mountPath: /usr/src/myapp/datasource
      volumes:
        - name: files
          persistentVolumeClaim:  // 삭제
            claimName: api-tester-1231-files  // 삭제
          // 아래 hostPath 추가
          hostPath: // 추가
            path: /root/k8s-local-volume/1231  // 추가
        - name: secret-datasource
          secret:
            secretName: api-tester-1231-postgresql

kubectl edit deployment api-tester-1231 -n anotherclass-123 

 

1-3. 레퍼런스

▶ nodeAffinity

https://kubernetes.io/ko/docs/tasks/configure-pod-container/assign-pods-nodes-using-node-affinity/