Application 기능으로 이해하기 - PVC/PV, Deployment, Service, HPA [미션4]

KIM HYUNMIN·2025년 6월 7일
0

1. PV,PVC

1- 1~4. local 동작 확인

파일생성

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

1) 컨테이너 임시 폴더 확인

kubectl exec -n anotherclass-123 -it pod/api-tester-1231-6cc9855bb9-4bvvz -- ls /usr/src/myapp/tmp

2) 컨테이너 영구저장 폴더 확인

kubectl exec -n anotherclass-123 -it pod/api-tester-1231-6cc9855bb9-4bvvz -- ls /usr/src/myapp/files/dev

3) 마스터노드 폴더 확인

ls /root/k8s-local-volume/1231

4) 파드 삭제

kubectl delete -n anotherclass-123 pod api-tester-1231-6cc9855bb9-4bvvz

5) 파일 조회
파드 재생성으로 임시 파일 찾을수 없음.

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

PVC(persistentVolumeClaim)삭제 -> hostPath 옵션 추가

파일 생성

curl http://192.168.56.30:31231/create-file-pod
curl http://192.168.56.30:31231/create-file-pv

1) 컨테이너 임시 폴더 확인

kubectl exec -n anotherclass-123  -it pod/api-tester-1231-69d9767cdf-xkglt -- ls /usr/src/myapp/tm

2) 컨테이너 영구저장 폴더 확인

kubectl exec -n anotherclass-123 -it pod/api-tester-1231-69d9767cdf-xkglt -- ls /usr/src/myapp/files/dev

3) 마스터노드 폴더 확인

ls /root/k8s-local-volume/1231

4) 파드 삭제

kubectl delete -n anotherclass-123 pod api-tester-1231-69d9767cdf-xkglt

5) 파일 조회

curl http://192.168.56.30:31231/list-file-pod
curl http://192.168.56.30:31231/list-file-pv

2. Deployment

2-1) 롤링업데이터

// 1) HPA minReplica 2로 바꾸기 (이전 강의에서 minReplicas를 1로 바꿔놨었음)
kubectl patch -n anotherclass-123 hpa api-tester-1231-default -p '{"spec":{"minReplicas":2}}'

// 1) 그외 Deployment scale 명령
kubectl scale -n anotherclass-123 deployment api-tester-1231 --replicas=2
// 1) edit로 모드로 직접 수정
kubectl edit -n anotherclass-123 deployment api-tester-1231

// 2) 지속적으로 Version호출 하기 (업데이트 동안 리턴값 관찰)
while true; do curl http://192.168.56.30:31231/version; sleep 2; echo ''; done; 

// 3) 별도의 원격 콘솔창을 열어서 업데이트 실행 
kubectl set image -n anotherclass-123 deployment/api-tester-1231 api-tester-1231=1pro/api-tester:v2.0.0
kubectl set image -n anotherclass-123 deployment/api-tester-1231

// update 실행 포맷 
// kubectl set image -n <namespace> deployment/<deployment-name> <container-name>=<image-name>:<tag>

2-2) 롤링업데이트(maxUnavailalbe 0%, maxSurage 100%)

결과
무중단 운영 가능


2-3) Recreate

결과
새로 적용 시키면 다운타임 발생

3. Service

1) 파드 내부에서 Service명으로 API 호출

kubectl exec -n anotherclass-123 -it pod/api-tester-1231-5b7f7d7dd5-k2bng -- curl http://api-tester-1231:80/version

2) Deployment에서 Pod ports 전체 삭제, Service targetPort를 http-> 8080 변경

결과


ports 항목을 삭제해도 연결은 잘된다
containerPort는 명시용

4. HPA

1) 부하 발생

http://192.168.56.30:31231/cpu-load?min=3

41 -> 106% 로 상승
결과

2) [behavior] 미사용으로 적용

결과
대기시간 없이 바로 증가 3->4개

profile
Linux,Window,Network,docker,kubernets

0개의 댓글