쿠버네티스(EKS)에서 Sentry 배포하기
Datadog과 New Relic과 같은 툴은 종합적인 모니터링을 제공하지만 비용이 많이 들 수 있습니다. Bugsnag은 Sentry와 유사하지만, Sentry는 특히 클라이언트 오류 추적과 성능 모니터링에서 뛰어나며, 저비용의 오류 추적과 알림을 위해 Kubernetes에 배포하기에 적합합니다.
K8s에서 효율적인 모니터링
Loki: 서버 로그를 관리하고 Grafana로 쉽게 시각화할 수 있습니다.
Prometheus: 애플리케이션과 서버 성능 모니터링에 사용됩니다.
Grafana: Prometheus와 Loki 메트릭을 통합하여 비용을 절감하면서 CloudWatch 로깅을 최소화합니다.
Sentry: 저비용의 클라이언트 측 오류 모니터링을 위해 사용하며, Slack 또는 이메일로 알림을 전송합니다.
이 구성은 비싼 상용 도구를 사용하지 않고도 K8s에서 효율적인 인프라 및 애플리케이션 모니터링을 제공합니다.
이 가이드에서는 Amazon EFS를 사용한 지속 가능한 저장소 설정, Sentry 구성, 그리고 Express.js 애플리케이션과의 통합을 포함한 Sentry를 Kubernetes(EKS)에 배포하고 테스트하는 과정을 설명합니다.
1. Sentry Helm 리포지토리 추가
먼저, Sentry Helm 리포지토리를 추가하고 Sentry 네임스페이스를 생성합니다.
bash코드 복사helm repo add sentry https://sentry-kubernetes.github.io/charts
helm repo update
kubectl create ns sentry
2. EFS 스토리지 클래스 생성
Sentry의 저장소를 설정하기 위해 Amazon EFS를 사용할 것입니다.
2.1 EFS CSI 드라이버 설치
먼저, Amazon EFS와 상호 작용할 수 있도록 EFS CSI 드라이버를 설치합니다.
helm repo add aws-efs-csi-driver https://kubernetes-sigs.github.io/aws-efs-csi-driver/
helm repo update
helm upgrade -i aws-efs-csi-driver aws-efs-csi-driver/aws-efs-csi-driver \
--namespace kube-system \
--set image.repository=602401143452.dkr.ecr.ap-northeast-2.amazonaws.com/eks/aws-efs-csi-driver \
--set controller.serviceAccount.create=true \
--set controller.serviceAccount.name=efs-csi-controller-sa
2.2 PersistentVolume 및 PersistentVolumeClaim 생성
파일 시스템 ID 가져오기
file_system_id=$(aws efs describe-file-systems --query "FileSystems[*].FileSystemId" --output text)
echo $file_system_id
PersistentVolume 정의 및 적용
efs-pv를 사용하여 EFS와 연결되는 PersistentVolume(PV)을 생성합니다.
specs/pv.yaml:
apiVersion: v1
kind: PersistentVolume
metadata:
name: efs-pv
spec:
capacity:
storage: 100Gi
volumeMode: Filesystem
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
storageClassName: efs-sc
csi:
driver: efs.csi.aws.com
volumeHandle: $file_system_id
PV 적용:
kubectl apply -f specs/pv.yaml
PersistentVolumeClaim 정의 및 적용
efs-claim을 사용하여 PV를 사용할 PersistentVolumeClaim(PVC)을 생성합니다.
claim.yaml:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: efs-claim
spec:
accessModes:
- ReadWriteMany
storageClassName: efs-sc
resources:
requests:
storage: 5Gi
PVC 적용:
kubectl apply -f claim.yaml -n sentry
2.3 StorageClass 정의 및 적용
Amazon EFS를 위한 StorageClass를 정의합니다.
specs/storageclass.yaml:
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: efs-sc
provisioner: efs.csi.aws.com
StorageClass 적용:
kubectl apply -f specs/storageclass.yaml
3. Sentry 배포를 위한 값 업데이트
Sentry의 기본 설정 값을 가져와서 배포에 맞게 업데이트합니다.
기본 values.yaml 가져오기
helm show values sentry/sentry --version 25.10.0 > values.yaml
values.yaml에 필요한 구성 업데이트:
user:
create: true
email: admin@sentry.local
password: XXXXX
system:
url: "https://sentry.topzone.io/"
adminEmail: "devops@topzone.io"
mail:
backend: smtp
useTls: true
useSsl: false
username: "XXXXX"
password: "XXXXX"
port: 587
host: "email-smtp.ap-northeast-2.amazonaws.com"
from: "devops@topzone.io"
symbolicator:
enabled: true
api:
usedeployment: true
persistence:
enabled: true
accessModes: ["ReadWriteMany"]
storageClassName: "efs-sc"
google:
clientId: "XXXXX"
clientSecret: "XXXXX"
slack:
clientId: XXXXX
clientSecret: XXXXX
signingSecret: XXXXX
nginx:
enabled: false
ingress:
enabled: true
regexPathStyle: nginx
ingressClassName: nginx
alb:
httpRedirect: false
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/use-regex: "true"
cert-manager.io/cluster-issuer: "letsencrypt-prod"
nginx.ingress.kubernetes.io/proxy-body-size: 200m
nginx.ingress.kubernetes.io/proxy-buffers-number: "16"
nginx.ingress.kubernetes.io/proxy-buffer-size: "32k"
hostname: sentry.topzone.io
tls:
- hosts:
- sentry.topzone.io
secretName: sentry-ingress-tls
filestore:
backend: filesystem
filesystem:
path: /var/lib/sentry/files
persistence:
enabled: true
storageClass: "efs-sc"
accessMode: ReadWriteMany
existingClaim: "sentry-data-pvc"
persistentWorkers: true
4. Sentry 설치
업데이트된 설정으로 Sentry를 Helm을 사용하여 설치합니다.
helm upgrade --debug -install sentry sentry/sentry \
-n sentry -f values.yaml --wait --timeout=1000s --version 25.10.0
5. 설치 후: 새 프로젝트 설정
Sentry를 설치한 후 애플리케이션 모니터링을 시작할 새로운 프로젝트를 생성합니다.
5.1 Sentry에서 프로젝트 생성
5.2 Express SDK 구성
Express 애플리케이션에 Sentry를 통합하여 오류를 캡처합니다.
npm install --save @sentry/node
Sentry 설정 (
src/instrument.js
):
const Sentry = require("@sentry/node");
Sentry.init({
dsn: "https://XXXXX@sentry.topzone.io/6",
tracesSampleRate: 1.0,
});
Express 애플리케이션에 오류 처리 추가 (
src/app.js
):
require("./instrument.js");
const Sentry = require("@sentry/node");
const express = require("express");
const app = express();
Sentry.setupExpressErrorHandler(app);
app.use(function onError(err, req, res, next) {
res.statusCode = 500;
res.end(res.sentry + "\n");
});
app.get("/", function rootHandler(req, res) {
res.end("Hello world!");
});
app.get("/error", function rootHandler(req, res) { // 오류가 Sentry에 캡처됩니다.
Sentry.captureException('Something went wrong!');
});
app.listen(3000);
6. 소스 맵 업로드
더 나은 JavaScript 오류 가시성을 위해 Sentry에 소스 맵을 업로드합니다.
curl -sL https://sentry.io/get-cli/ | sh
sentry-cli --url https://sentry.topzone.io/ login
npx @sentry/wizard@latest -i sourcemaps
7. Sentry 테스트
마지막으로, Sentry가 애플리케이션의 오류를 캡처하는지 확인합니다.
이 구성으로 EKS에서 Sentry를 사용하여 애플리케이션을 효과적으로 모니터링하고 디버깅할 수 있습니다.
댓글을 작성해보세요.