안녕하세요, 이번 글에서는 Azure Kubernetes Service(AKS) 환경에 Spring Boot 애플리케이션을 배포하고, Prometheus + Grafana를 통해 JVM 및 애플리케이션 메트릭을 수집하고 시각화하는 전체 과정을 정리해보겠습니다.
1. 환경 구성
항목 | 내용 |
클라우드 환경 | Azure AKS (aks-cloudbiz-dev-cloudcoe) |
네임스페이스 | mvp-springboot-dev |
CI/CD 방식 | ArgoCD (※ CoE 팀 전용 인프라 사용) |
배포 방식 | Helm 차트 |
모니터링 도구 | Prometheus, Grafana (lgtm-prometheus, lgtm-grafana) |
2. Spring Boot 애플리케이션 구성
2.1 프로젝트 개요
- Java 17 + Spring Boot 3.x
- Micrometer + Actuator로 Prometheus 메트릭 노출
- 기본 REST API: /test/hello
- 초기 DB 구성용 data.sql 포함
2.2 주요 파일 구조
src/main/java/com/ktds/mvp/springboot/
├── SpringbootApplication.java // 앱 진입점
├── controller/TestController.java // REST API
├── config/ // 설정 파일 (향후 확장)
├── employee/ // 도메인 로직 (예정)
2.3 application.properties 주요 설정
server.port=8080
# H2 DB 및 콘솔 설정
spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2:mem:testdb;MODE=PostgreSQL;
spring.datasource.username=sa
# Actuator 엔드포인트 노출
management.endpoints.enabled-by-default=false
management.endpoints.web.exposure.include=info,health,prometheus,metrics
management.endpoint.prometheus.enabled=true
> /actuator/prometheus 경로에서 Prometheus가 수집 가능한 Micrometer 메트릭 제공
3. Kubernetes 리소스 정의
Service (ClusterIP)
apiVersion: v1
kind: Service
metadata:
name: mvp-springboot-jdk17
namespace: mvp-springboot-dev
spec:
selector:
app: mvp-springboot-jdk17
ports:
- name: http
port: 8080
targetPort: 8080
- Prometheus는 내부 DNS (<svc>.<ns>.svc.cluster.local)를 통해 접근
- static_configs에 해당 주소 지정
4. 모니터링 구성
4.1 Prometheus 수집 설정
ConfigMap 수정 (lgtm-prometheus-server)
- job_name: 'springboot-k8s-app'
metrics_path: '/actuator/prometheus'
static_configs:
- targets: ['mvp-springboot-jdk17.mvp-springboot-dev.svc.cluster.local:8080']
확인: Prometheus UI > Status > Targets 에서 UP 상태
4.2 Grafana 대시보드 구성
- Dashboard ID: 10280
- 이름: Microservices / Spring Boot 2.1
매핑 변수 설정
job | springboot-k8s-app |
instance | mvp-springboot-jdk17.mvp-springboot-dev.svc.cluster.local:8080 |
5. 수집된 주요 메트릭 항목
카테고리 | 메트릭 이름 | 설명 |
CPU 사용률 | system_cpu_usage | 전체 시스템 CPU 사용률 |
JVM 프로세스 | process_cpu_usage | 애플리케이션 JVM의 CPU 사용률 |
메모리 | jvm_memory_used_bytes | Heap 및 Non-Heap 메모리 사용량 |
GC | jvm_gc_pause_seconds_max | GC로 인한 최대 일시중지 시간 |
스레드 | jvm_threads_live | 현재 활성 스레드 수 |
요청 처리 | http_server_requests_seconds_count | HTTP 요청 수 |
응답 시간 | http_server_requests_seconds_max | 최대 응답 시간 |
DB 커넥션 | hikaricp_connections_active | 활성 커넥션 수 |
결과
- /actuator/prometheus 경로에서 Micrometer 메트릭 정상 노출
- Prometheus에서 JVM/GC/HTTP/HikariCP 등 다양한 메트릭 수집 확인
- Grafana에서 실시간 시각화 성공 (Dashboard ID: 10280 사용)
Spring Boot와 Prometheus + Grafana를 연동하면 매우 손쉽게 애플리케이션 성능을 모니터링할 수 있습니다. 특히 AKS와 GitOps 기반 배포 구조에서 Micrometer + Actuator 연동은 필수적인 구성 요소로, 보안성과 효율성을 함께 챙길 수 있습니다.
'Kubernetes' 카테고리의 다른 글
KubeVirt VM 로그 수집 및 시각화 구성 (Promtail → Loki → Grafana) (1) | 2025.07.02 |
---|---|
FastAPI 애플리케이션을 AKS에 배포하고 Prometheus + Grafana로 모니터링 하기 (0) | 2025.06.09 |
Slack Smart Bot 구축기 (LangChain + Prometheus 연동) (0) | 2025.04.25 |
Multi Cluster 환경 구축 : dev / com 클러스터 연동 및 Grafana 통합 시각화 (0) | 2025.04.21 |
AKS 환경에서 Promtail → Loki → Grafana 기반 로그 수집 (0) | 2025.04.14 |