在 Kubernetes 集群中部署 Sentry 错误监控系统。官方没有提供 K8s 部署文档,但我们可以使用社区的 Helm Chart

版本信息

  • App Version: 24.5.0
  • Chart Version: 23.1.0

核心配置

values.yaml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# 文件存储配置
filestore:
backend: filesystem
filesystem:
path: /var/lib/sentry/files
persistence:
accessMode: ReadWriteMany # 需要 ReadWriteMany 存储
enabled: true
persistentWorkers: true
size: 10Gi
storageClass: "efs" # 使用支持 RWX 的存储类

# Ingress 配置
nginx:
ingress:
enabled: true
hostname: sentry.company.com
ingressClassName: "alb" # 使用 AWS ALB
path: /
pathType: Prefix

# 数据库配置
postgresql:
postgresqlPassword: "examplePassword"
postgresqlPostgresPassword: "examplePassword"

# Source Maps 支持
sourcemaps:
enabled: true

# 初始管理员用户
user:
create: true
email: [email protected]
password: examplePassword

# Zookeeper 数据清理
zookeeper:
autopurge:
purgeInterval: 3
snapRetainCount: 3

配置说明

配置项 说明 注意事项
filestore 文件存储 必须使用 ReadWriteMany 存储类
postgresql 数据库密码 防止启动报错,详见 issue
nginx.ingress 入口配置 根据实际 Ingress Controller 调整
zookeeper.autopurge 自动清理 避免数据过大

ClickHouse 报错修复

问题现象

部署后 sentry-clickhouse Pod 一直处于 CrashLoopBackOff 状态:

1
2
snuba.clickhouse.errors.ClickhouseWriterError: Method write is not supported
by storage Distributed with more than one shard and no sharding key provided

原因分析

分布式表 metrics_raw_v2_dist 缺少 sharding key 配置。相关 issue:

解决步骤

进入 ClickHouse 容器重建表:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 进入容器
kubectl exec -it sentry-clickhouse-0 -- bash

# 连接 ClickHouse
clickhouse-client -h sentry-clickhouse

# 删除旧表
DROP TABLE default.metrics_raw_v2_dist ON CLUSTER 'sentry-clickhouse' SYNC;

# 创建新表(带 sharding key)
CREATE TABLE default.metrics_raw_v2_dist ON CLUSTER 'sentry-clickhouse'
(
`use_case_id` LowCardinality(String),
`org_id` UInt64,
`project_id` UInt64,
`metric_id` UInt64,
`timestamp` DateTime,
`tags.key` Array(UInt64),
`tags.value` Array(UInt64),
`metric_type` LowCardinality(String),
`set_values` Array(UInt64),
`count_value` Float64,
`distribution_values` Array(Float64),
`materialization_version` UInt8,
`retention_days` UInt16,
`partition` UInt16,
`offset` UInt64,
`timeseries_id` UInt32
)
ENGINE = Distributed('sentry-clickhouse', 'default', 'metrics_raw_v2_local',
sipHash64('timeseries_id')); -- 关键:添加 sharding key

执行后 Pod 会恢复正常。

替代方案

如果 Sentry 过于复杂,可以考虑 GlitchTip - 一个轻量级的 Sentry 替代品。

注意事项

  • 存储类必须支持 ReadWriteMany(如 EFS、NFS)
  • PostgreSQL 密码务必提前配置,否则可能导致初始化失败
  • ClickHouse 问题需要手动修复,Chart 未自动处理