关于 runbook-generator
用于编写运维操作、事件响应和系统维护手册的技能。它提供标准化结构,涵盖前置条件、执行验证、回滚、故障排查和联系信息。
主要功能
- 01提供标准化手册结构
- 02列出前置条件与检查项
- 03记录命令及预期结果
- 04包含验证和回滚步骤
- 05补充故障排查与联系人
适用场景
- 01编写生产环境部署手册
- 02整理事件响应操作流程
- 03记录系统维护和回滚步骤
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ dengineproblem/ agents-monorepo --skill runbook-generator安装后在 Claude Code 中输入/runbook-generator确认已加载。
详细介绍
运维手册生成器
擅长为运维流程、事件响应和系统维护任务编写全面、标准化的运维手册。
运维手册结构
runbook_template:
metadata:
title: "Runbook title"
version: "1.0"
last_updated: "2024-01-15"
owner: "Team/Person"
reviewers: ["Name 1", "Name 2"]
overview:
purpose: "What this runbook accomplishes"
scope: "Systems/services affected"
audience: "Who should use this"
prerequisites:
access:
- "AWS Console access"
- "SSH key for production servers"
- "Database credentials"
tools:
- "kubectl configured"
- "AWS CLI installed"
- "jq for JSON parsing"
knowledge:
- "Basic Kubernetes concepts"
- "Understanding of service architecture"
execution:
estimated_time: "15-30 minutes"
risk_level: "Medium"
requires_change_ticket: true
requires_approval: true
can_be_automated: true
steps: [] # Detailed steps below
verification: [] # How to confirm success
rollback: [] # How to undo changes
troubleshooting: [] # Common issues
contacts:
primary_oncall: "PagerDuty"
escalation: "Engineering Manager"
subject_experts: ["DBA Team", "Platform Team"]
标准运维手册模板
# [Runbook Title]
**Version:** 1.0
**Last Updated:** YYYY-MM-DD
**Owner:** Team Name
**Risk Level:** Low | Medium | High | Critical
## Overview
### Purpose
Brief description of what this runbook accomplishes.
### When to Use
- Trigger condition 1
- Trigger condition 2
- Alert: "Alert Name" fires
### Scope
Systems and services affected:
- Service A
- Database B
- External dependency C
## Prerequisites
### Required Access
- [ ] Production AWS Console
- [ ] Kubernetes cluster access
- [ ] Database read/write permissions
### Required Tools
```bash
# Verify kubectl
kubectl version --client
# Verify AWS CLI
aws sts get-caller-identity
# Verify database connectivity
psql -h $DB_HOST -U $DB_USER -c "SELECT 1"
必备知识
- Kubernetes Pod 管理
- 服务架构概览
- 事件响应流程
执行前检查清单
- 已创建变更工单:CHG-XXXXX
- 已获得以下人员的批准:[Name]
- 已验证备份(如适用)
- 已通知相关方
- 已安排维护窗口(如适用)
执行步骤
步骤 1:[操作名称]
目的: 说明此步骤的必要性
命令:
kubectl get pods -n production -l app=myservice
预期输出:
NAME READY STATUS RESTARTS AGE
myservice-abc123-xyz 1/1 Running 0 2d
myservice-def456-uvw 1/1 Running 0 2d
验证: 确认所有 Pod 的 STATUS 均为 Running
如有异常: 请参阅“故障排查”部分
步骤 2:[下一步操作]
目的: 描述
命令:
# Command with explanation
kubectl scale deployment myservice --replicas=3 -n production
预期输出:
deployment.apps/myservice scaled
验证:
# Verify new replicas are running
kubectl get pods -n production -l app=myservice -w
等待: 所有 3 个 Pod 均显示 Running 状态(通常需要 2-5 分钟)
执行后验证
验证服务运行状况
# Check deployment status
kubectl rollout status deployment/myservice -n production
# Check service endpoints
kubectl get endpoints myservice -n production
# Verify application health
curl -s https://api.example.com/health | jq .
预期结果:
{
"status": "healthy",
"version": "1.2.3",
"uptime": "2h30m"
}
验证指标
- 错误率已恢复正常(<0.1%)
- 延迟符合 SLA(<200ms p99)
- 没有触发新的警报
回滚流程
回滚条件
- 错误率超过 1%
- 延迟超过 500ms p99
- 关键功能失效
回滚步骤
# Rollback to previous deployment
kubectl rollout undo deployment/myservice -n production
# Verify rollback
kubectl rollout status deployment/myservice -n production
# Confirm previous version
kubectl get deployment myservice -n production -o jsonpath='{.spec.template.spec.containers[0].image}'
故障排查
| 症状 | 可能原因 | 解决方法 |
|---|---|---|
| Pod 卡在 Pending 状态 | 资源限制 | 检查节点容量:kubectl describe nodes |
| CrashLoopBackOff | 应用程序错误 | 检查日志:kubectl logs -f <pod> |
| ImagePullBackOff | 镜像仓库身份验证问题 | 验证密钥:kubectl get secret regcred |
| 连接被拒绝 | 服务尚未就绪 | 等待就绪探针,检查端点 |
常见问题
问题:部署超时
# Check pod events
kubectl describe pod <pod-name> -n production
# Check resource limits
kubectl top pods -n production
问题:数据库连接失败
# Verify database connectivity
kubectl exec -it <pod> -n production -- psql -h $DB_HOST -c "SELECT 1"
# Check connection pool
kubectl logs <pod> -n production | grep -i "connection"
紧急联系人
| 角色 | 联系方式 | 何时联系 |
|---|---|---|
| 值班工程师 | PagerDuty | 任何问题 |
| 数据库团队 | #dba-oncall | 数据库问题 |
| 平台团队 | #platform-oncall | 基础设施问题 |
| 工程经理 | [Name] | 升级处理 |
变更日志
| 版本 | 日期 | 作者 | 变更 |
|---|---|---|---|
| 1.0 | 2024-01-15 | Author | 初始版本 |
相关文档
## Runbook Types
### Incident Response Runbook
```yaml
incident_runbook:
sections:
detection:
alert_name: "High Error Rate - Payment Service"
threshold: "Error rate > 5% for 5 minutes"
severity: "P1"
immediate_actions:
- step: "Acknowledge alert"
command: "In PagerDuty, acknowledge incident"
time: "< 5 min"
- step: "Assess impact"
command: |
# Check error rate
curl -s "https://metrics.example.com/api/v1/query?query=rate(http_errors[5m])"
time: "< 2 min"
- step: "Notify stakeholders"
action: "Post in #incident-channel"
template: |
🚨 INCIDENT: Payment Service High Errors
Severity: P1
Status: Investigating
Impact: Payment processing affected
IC: @oncall
investigation:
- "Check recent deployments"
- "Review error logs"
- "Check dependent services"
- "Review infrastructure metrics"
mitigation:
options:
- name: "Rollback deployment"
when: "Error started after deploy"
command: "kubectl rollout undo deployment/payment -n prod"
- name: "Scale up"
when: "Load-related errors"
command: "kubectl scale deployment/payment --replicas=10 -n prod"
- name: "Enable circuit breaker"
when: "Downstream dependency failing"
command: "Toggle feature flag: payment.circuit_breaker=true"
resolution:
checklist:
- "[ ] Error rate < 0.1%"
- "[ ] No P1 alerts"
- "[ ] Stakeholders notified"
- "[ ] Incident documented"
部署运维手册
deployment_runbook:
pre_deployment:
checklist:
- "[ ] Code review approved"
- "[ ] CI/CD pipeline passed"
- "[ ] Staging tested"
- "[ ] Change ticket approved"
- "[ ] Rollback plan documented"
verification:
- step: "Verify staging health"
command: |
curl -s https://staging.example.com/health
- step: "Check deployment queue"
command: |
kubectl get pods -n staging -l app=myservice
deployment:
- step: "Apply deployment"
command: |
kubectl apply -f k8s/production/deployment.yaml
- step: "Monitor rollout"
command: |
kubectl rollout status deployment/myservice -n production --timeout=10m
- step: "Verify new version"
command: |
kubectl get deployment myservice -n production \
-o jsonpath='{.spec.template.spec.containers[0].image}'
post_deployment:
- step: "Smoke test"
command: |
./scripts/smoke-test.sh production
- step: "Monitor metrics"
duration: "15 minutes"
watch:
- "Error rate"
- "Latency p99"
- "Request rate"
- step: "Update ticket"
action: "Mark CHG ticket as completed"
维护运维手册
maintenance_runbook:
log_rotation:
schedule: "Weekly, Sunday 02:00 UTC"
steps:
- step: "Connect to server"
command: |
ssh [email protected]
- step: "Rotate logs"
command: |
sudo logrotate -f /etc/logrotate.d/application
- step: "Verify rotation"
command: |
ls -la /var/log/application/
# Should see rotated files with date suffix
- step: "Clean old logs"
command: |
# Remove logs older than 30 days
find /var/log/application/ -name "*.log.*" -mtime +30 -delete
- step: "Verify disk space"
command: |
df -h /var/log
# Should show > 20% free
database_maintenance:
schedule: "Monthly, first Sunday 03:00 UTC"
steps:
- step: "Check table sizes"
command: |
psql -c "
SELECT tablename,
pg_size_pretty(pg_total_relation_size(tablename::text))
FROM pg_tables
WHERE schemaname = 'public'
ORDER BY pg_total_relation_size(tablename::text) DESC
LIMIT 10;
"
- step: "Run VACUUM ANALYZE"
command: |
psql -c "VACUUM ANALYZE;"
- step: "Reindex if needed"
command: |
psql -c "REINDEX DATABASE mydb;"
编写指南
principles:
clarity:
- "Use active voice"
- "Be explicit, never assume"
- "One action per step"
completeness:
- "Include all commands"
- "Show expected output"
- "Document verification"
safety:
- "Test in non-prod first"
- "Include rollback steps"
- "Document risks"
formatting:
commands:
- "Use code blocks with language"
- "Include full paths"
- "Add comments for complex commands"
steps:
- "Number sequentially"
- "Include purpose"
- "Show expected result"
- "Note time estimate"
variables:
format: "$VARIABLE_NAME or <placeholder>"
document: "List all variables at start"
质量检查清单
validation:
structure:
- "[ ] Clear title and metadata"
- "[ ] Prerequisites listed"
- "[ ] Steps numbered and clear"
- "[ ] Expected outputs included"
- "[ ] Verification steps present"
- "[ ] Rollback documented"
- "[ ] Troubleshooting section"
- "[ ] Contacts listed"
testing:
- "[ ] All commands tested"
- "[ ] Outputs verified"
- "[ ] Rollback tested"
- "[ ] Time estimates accurate"
maintenance:
- "[ ] Version number updated"
- "[ ] Change log maintained"
- "[ ] Quarterly review scheduled"
- "[ ] Owner assigned"
最佳实践
- 测试所有内容 — 每条命令都应经过验证
- 展示预期输出 — 用户应清楚自己将看到什么
- 包含回滚方案 — 始终准备回滚计划
- 保持更新 — 每季度进行一次审查
- 版本控制 — 将运维手册纳入 git
- 尽可能自动化 — 自动化重复流程
评论
支持 Markdown