ln-774-healthcheck-setup by levnikolaevich/claude-code-skills
npx skills add https://github.com/levnikolaevich/claude-code-skills --skill ln-774-healthcheck-setup类型: L3 Worker 类别: 7XX 项目引导 父级: ln-770-crosscutting-setup
为 Kubernetes 探针和监控配置健康检查端点。
| 方面 | 详情 |
|---|---|
| 输入 | 来自 ln-770 的上下文存储 |
| 输出 | 健康检查端点和 Kubernetes 探针配置 |
| 技术栈 | .NET (AspNetCore.Diagnostics.HealthChecks), Python (FastAPI 路由) |
接收上下文存储并扫描需要监控的依赖项。
必需上下文:
STACK: .NET 或 PythonPROJECT_ROOT: 项目目录路径广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
AddHealthChecks 或 MapHealthChecks/health 路由{ "status": "skipped" }依赖项检测:
| 依赖项 | .NET 检测 | Python 检测 |
|---|---|---|
| PostgreSQL | csproj 中的 Npgsql | requirements 中的 psycopg2 或 asyncpg |
| MySQL | csproj 中的 MySql.Data | requirements 中的 mysql-connector-python |
| Redis | csproj 中的 StackExchange.Redis | requirements 中的 redis |
| RabbitMQ | csproj 中的 RabbitMQ.Client | requirements 中的 pika 或 aio-pika |
| MongoDB | csproj 中的 MongoDB.Driver | requirements 中的 pymongo |
根据 Kubernetes 最佳实践定义三种类型的健康端点。
| 端点 | 探针类型 | 目的 | 检查项 |
|---|---|---|---|
/health/live | 存活探针 | 应用是否存活? | 应用响应(不检查依赖项) |
/health/ready | 就绪探针 | 应用能否处理流量? | 所有依赖项健康 |
/health/startup | 启动探针 (K8s 1.16+) | 应用是否初始化完成? | 初始预热完成 |
| 探针 | 失败操作 | Kubernetes 行为 |
|---|---|---|
| 存活探针 | 容器重启 | kubelet 重启容器 |
| 就绪探针 | 从服务中移除 | 停止流量,不重启 |
| 启动探针 | 延迟其他探针 | 暂停存活/就绪探针 |
使用 MCP 工具获取最新文档。
对于 .NET:
MCP ref: "ASP.NET Core health checks Kubernetes probes"
Context7: /dotnet/aspnetcore
对于 Python:
MCP ref: "FastAPI health check endpoint Kubernetes"
Context7: /tiangolo/fastapi
需要研究的关键模式:
根据应用特性确定探针时序。
| 参数 | 存活探针 | 就绪探针 | 启动探针 |
|---|---|---|---|
initialDelaySeconds | 10 | 5 | 0 |
periodSeconds | 10 | 5 | 5 |
timeoutSeconds | 5 | 3 | 3 |
failureThreshold | 3 | 3 | 30 |
successThreshold | 1 | 1 | 1 |
启动探针计算:
Max startup time = initialDelaySeconds + (periodSeconds × failureThreshold)
Default: 0 + (5 × 30) = 150 seconds
| 文件 | 用途 |
|---|---|
Extensions/HealthCheckExtensions.cs | 健康检查注册 |
HealthChecks/StartupHealthCheck.cs | 自定义启动检查 |
生成过程:
需要添加的包:
AspNetCore.HealthChecks.NpgSql (如果使用 PostgreSQL)AspNetCore.HealthChecks.Redis (如果使用 Redis)AspNetCore.HealthChecks.MySql (如果使用 MySQL)注册代码:
builder.Services.AddHealthCheckServices(builder.Configuration);
// ...
app.MapHealthCheckEndpoints();
| 文件 | 用途 |
|---|---|
routes/health.py | 健康检查路由器 |
services/health_checker.py | 依赖项健康检查 |
生成过程:
注册代码:
from routes.health import health_router
app.include_router(health_router)
生成用于 deployment.yaml 的片段:
livenessProbe:
httpGet:
path: /health/live
port: 5000
initialDelaySeconds: 10
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 3
readinessProbe:
httpGet:
path: /health/ready
port: 5000
initialDelaySeconds: 5
periodSeconds: 5
timeoutSeconds: 3
failureThreshold: 3
startupProbe:
httpGet:
path: /health/startup
port: 5000
periodSeconds: 5
failureThreshold: 30
验证步骤:
语法检查:
dotnet build --no-restorepython -m py_compile routes/health.py端点测试:
curl http://localhost:5000/health/live
curl http://localhost:5000/health/ready
curl http://localhost:5000/health/startup
验证响应格式:
{
"status": "Healthy",
"checks": {
"database": { "status": "Healthy", "duration": "00:00:00.0234" },
"redis": { "status": "Healthy", "duration": "00:00:00.0012" }
},
"totalDuration": "00:00:00.0250"
}
依赖项失败测试:
/health/ready 返回 503/health/live 仍然返回 200{
"status": "success",
"files_created": [
"Extensions/HealthCheckExtensions.cs",
"HealthChecks/StartupHealthCheck.cs"
],
"packages_added": [
"AspNetCore.HealthChecks.NpgSql"
],
"registration_code": "builder.Services.AddHealthCheckServices(configuration);",
"message": "Configured health checks with liveness, readiness, and startup probes"
}
/health/live、/health/ready、/health/startupAddHealthChecks/MapHealthChecks 或 /health 路由已存在,返回 status: "skipped"dotnet build 或 py_compile)版本: 2.0.0 最后更新: 2026-01-10
每周安装量
157
代码仓库
GitHub 星标数
245
首次出现
Jan 24, 2026
安全审计
安装于
cursor141
gemini-cli140
opencode140
codex140
claude-code139
github-copilot136
Type: L3 Worker Category: 7XX Project Bootstrap Parent: ln-770-crosscutting-setup
Configures health check endpoints for Kubernetes probes and monitoring.
| Aspect | Details |
|---|---|
| Input | Context Store from ln-770 |
| Output | Health check endpoints and Kubernetes probe configuration |
| Stacks | .NET (AspNetCore.Diagnostics.HealthChecks), Python (FastAPI routes) |
Accept Context Store and scan for dependencies to monitor.
Required Context:
STACK: .NET or PythonPROJECT_ROOT: Project directory pathIdempotency Check:
AddHealthChecks or MapHealthChecks/health route{ "status": "skipped" }Dependency Detection:
| Dependency | .NET Detection | Python Detection |
|---|---|---|
| PostgreSQL | Npgsql in csproj | psycopg2 or asyncpg in requirements |
| MySQL | MySql.Data in csproj | mysql-connector-python in requirements |
| Redis | StackExchange.Redis in csproj | redis in requirements |
Define three types of health endpoints per Kubernetes best practices.
| Endpoint | Probe Type | Purpose | Checks |
|---|---|---|---|
/health/live | Liveness | Is app alive? | App responds (no dependency checks) |
/health/ready | Readiness | Can app serve traffic? | All dependencies healthy |
/health/startup | Startup (K8s 1.16+) | Is app initialized? | Initial warmup complete |
| Probe | Failure Action | Kubernetes Behavior |
|---|---|---|
| Liveness | Container restart | kubelet restarts container |
| Readiness | Remove from service | Traffic stopped, no restart |
| Startup | Delay other probes | Liveness/Readiness paused |
Use MCP tools for current documentation.
For .NET:
MCP ref: "ASP.NET Core health checks Kubernetes probes"
Context7: /dotnet/aspnetcore
For Python:
MCP ref: "FastAPI health check endpoint Kubernetes"
Context7: /tiangolo/fastapi
Key Patterns to Research:
Determine probe timing based on application characteristics.
| Parameter | Liveness | Readiness | Startup |
|---|---|---|---|
initialDelaySeconds | 10 | 5 | 0 |
periodSeconds | 10 | 5 | 5 |
timeoutSeconds | 5 | 3 | 3 |
failureThreshold | 3 | 3 | 30 |
successThreshold |
Startup Probe Calculation:
Max startup time = initialDelaySeconds + (periodSeconds × failureThreshold)
Default: 0 + (5 × 30) = 150 seconds
| File | Purpose |
|---|---|
Extensions/HealthCheckExtensions.cs | Health check registration |
HealthChecks/StartupHealthCheck.cs | Custom startup check |
Generation Process:
Packages to Add:
AspNetCore.HealthChecks.NpgSql (if PostgreSQL)AspNetCore.HealthChecks.Redis (if Redis)AspNetCore.HealthChecks.MySql (if MySQL)Registration Code:
builder.Services.AddHealthCheckServices(builder.Configuration);
// ...
app.MapHealthCheckEndpoints();
| File | Purpose |
|---|---|
routes/health.py | Health check router |
services/health_checker.py | Dependency health checks |
Generation Process:
Registration Code:
from routes.health import health_router
app.include_router(health_router)
Generate for inclusion in deployment.yaml:
livenessProbe:
httpGet:
path: /health/live
port: 5000
initialDelaySeconds: 10
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 3
readinessProbe:
httpGet:
path: /health/ready
port: 5000
initialDelaySeconds: 5
periodSeconds: 5
timeoutSeconds: 3
failureThreshold: 3
startupProbe:
httpGet:
path: /health/startup
port: 5000
periodSeconds: 5
failureThreshold: 30
Validation Steps:
Syntax check:
dotnet build --no-restorepython -m py_compile routes/health.pyEndpoint test:
curl http://localhost:5000/health/live
curl http://localhost:5000/health/ready
curl http://localhost:5000/health/startup
Verify response format:
{
"status": "Healthy",
"checks": {
"database": { "status": "Healthy", "duration": "00:00:00.0234" },
"redis": { "status": "Healthy", "duration": "00:00:00.0012" }
},
"totalDuration": "00:00:00.0250"
}
Dependency failure test:
/health/ready returns 503{
"status": "success",
"files_created": [
"Extensions/HealthCheckExtensions.cs",
"HealthChecks/StartupHealthCheck.cs"
],
"packages_added": [
"AspNetCore.HealthChecks.NpgSql"
],
"registration_code": "builder.Services.AddHealthCheckServices(configuration);",
"message": "Configured health checks with liveness, readiness, and startup probes"
}
/health/live, /health/ready, /health/startup per Kubernetes best practicesAddHealthChecks/MapHealthChecks or /health route exists, return status: "skipped"dotnet build or py_compile)Version: 2.0.0 Last Updated: 2026-01-10
Weekly Installs
157
Repository
GitHub Stars
245
First Seen
Jan 24, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
cursor141
gemini-cli140
opencode140
codex140
claude-code139
github-copilot136
Azure 升级评估与自动化工具 - 轻松迁移 Functions 计划、托管层级和 SKU
90,800 周安装
NestJS最佳实践指南:40条规则提升架构、性能与安全性
10,500 周安装
Spring Boot 最佳实践指南:项目结构、依赖注入、配置、Web层与安全
10,600 周安装
iOS移动设计指南:掌握SwiftUI与HIG,构建原生精致Apple应用
10,700 周安装
GWS Gmail 发送邮件命令:通过命令行快速发送Gmail邮件(支持附件、HTML、草稿)
11,000 周安装
Gmail 收件箱快速处理工具 - gws-gmail-triage 命令使用指南 | Google Workspace CLI
11,100 周安装
Slack自动化指南:使用Vercel Labs Agent-Browser检查消息、提取数据与任务自动化
11,000 周安装
| RabbitMQ | RabbitMQ.Client in csproj | pika or aio-pika in requirements |
| MongoDB | MongoDB.Driver in csproj | pymongo in requirements |
| 1 |
| 1 |
| 1 |
/health/live still returns 200