Skip to content

/devops

DevOps patterns: containerization, CI/CD, deployment strategies, monitoring. Use when containerizing apps, setting up pipelines, or deploying services.

From plugin
4919 skills8 agents44 commands20 hooks
shell
$ npx -y skills add xiaobei930/cc-best --skill devops --agent claude-code

How it fires

How this skill gets triggered: by you, by Claude, or both.

  • Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.
  • You can call itInvoke it directly when you want it.
  • Slash command/devops
How auto-invocation works

Context preview

The summary Claude sees to decide when to auto-load this skill.

DevOps patterns: containerization, CI/CD, deployment strategies, monitoring. Use when containerizing apps, setting up pipelines, or deploying services.

SKILL.md

devops.SKILL.md
name: devops
description: "DevOps patterns: containerization, CI/CD, deployment strategies, monitoring. Use when containerizing apps, setting up pipelines, or deploying services."
allowed-tools: Read, Write, Edit, Bash, Grep, Glob

DevOps 模式

本技能提供 DevOps 实践的最佳实践和模式,支持多平台按需加载。

触发条件

  • 容器化应用(Docker)
  • 配置 CI/CD 流水线
  • 部署服务到云平台
  • 设置监控和告警
  • 基础设施即代码

平台专属模式

根据项目需求,加载对应的平台专属文件:

| 平台 | 加载文件 | 内容 | | ------ | ----------- | ------------------------- | | Docker | `docker.md` | 容器化、Compose、镜像优化 | | CI/CD | `ci-cd.md` | GitHub Actions、GitLab CI |

**加载方式**: 检测项目中的 `Dockerfile`/`.github/workflows`/`k8s/` 等文件确定需求。

---

通用 DevOps 原则

12-Factor App 原则

┌─────────────────────────────────────────────────────────────┐
│                    12-Factor App 核心原则                     │
├─────────────────────────────────────────────────────────────┤
│  1. Codebase        一个代码库,多个部署                      │
│  2. Dependencies    显式声明依赖                             │
│  3. Config          配置存储在环境变量中                      │
│  4. Backing Services 将后端服务视为附加资源                   │
│  5. Build/Release/Run 严格分离构建、发布、运行                │
│  6. Processes       以无状态进程运行应用                      │
│  7. Port Binding    通过端口绑定导出服务                      │
│  8. Concurrency     通过进程模型扩展                         │
│  9. Disposability   快速启动和优雅终止                       │
│ 10. Dev/Prod Parity 保持开发、预发、生产环境尽量相似          │
│ 11. Logs            将日志视为事件流                         │
│ 12. Admin Processes 将管理任务作为一次性进程运行              │
└─────────────────────────────────────────────────────────────┘

环境管理

┌─────────────────────────────────────────────────────────────┐
│                      环境流转                                │
├─────────────────────────────────────────────────────────────┤
│  Development → Staging → Production                         │
│       ↓           ↓           ↓                             │
│   本地开发      预发验证      线上环境                        │
│   .env.local   .env.staging  .env.production                │
└─────────────────────────────────────────────────────────────┘

**环境变量管理**:

# .env.example(提交到 Git,作为模板)
DATABASE_URL=postgresql://user:password@localhost:5432/dbname
REDIS_URL=redis://localhost:6379
API_KEY=your-api-key-here

# .env.local(不提交,本地开发)
DATABASE_URL=postgresql://dev:dev@localhost:5432/myapp_dev

---

部署策略

| 策略 | 特点 | 适用场景 | | ------------ | ------------------------------------------ | -------------------- | | **蓝绿部署** | 双环境切换,零停机,回滚快 | 关键业务,零停机要求 | | **滚动部署** | 逐实例替换,maxSurge/maxUnavailable 控制 | 标准 K8s 部署 | | **金丝雀** | 5-10% 流量试验,渐进增量,监控错误率后全量 | 高风险功能发布 |

> 详细配置和流程图见 [docker.md](./docker.md) 和各云平台文档。

---

监控与可观测性

三大支柱

| 支柱 | 用途 | 工具 | | ----------- | ---------------- | ------------------- | | **Metrics** | 聚合的数值数据 | Prometheus, Datadog | | **Logs** | 离散的事件记录 | ELK, Loki | | **Traces** | 请求的分布式追踪 | Jaeger, Zipkin |

关键指标 (Golden Signals)

┌─────────────────────────────────────────────────────────────┐
│                   四个黄金信号                               │
├─────────────────────────────────────────────────────────────┤
│  Latency    响应时间 - p50, p95, p99                        │
│  Traffic    流量 - QPS, 请求数/秒                           │
│  Errors     错误率 - 5xx 比例, 失败请求                      │
│  Saturation 饱和度 - CPU, 内存, 磁盘使用率                   │
└─────────────────────────────────────────────────────────────┘

告警规则示例

# Prometheus 告警规则
groups:
  - name: application
    rules:
      # 高错误率告警
      - alert: HighErrorRate
        expr: rate(http_requests_total{status=~"5.."}[5m]) / rate(http_requests_total[5m]) > 0.05
        for: 5m
        labels:
          severity: critical
        annotations:
          summary: "高错误率: {{ $value | humanizePercentage }}"

      # 高延迟告警
      - alert: HighLatency
        expr: histogram_quantile(0.95, rate(http_request_duration_seconds_bucket[5m])) > 1
        for: 5m
        labels:
          severity: warning
        annotations:
          summary: "P95 延迟超过 1s"

---

基础设施即代码 (IaC)

| 工具 | 用途 | 关键原则 | | --------- | ------------ | ---------------------------- | | Terraform | 基础设施编排 | 声明式、模块化、环境隔离 | | Ansible | 配置管理 | 幂等性、Playbook 可复用 | | Scripts | 部署/回滚 | deploy.sh + rollback.sh 成对 |

> 目录结构和 Terraform 示例详见 [ci-cd.md](./ci-cd.md#基础设施即代码-iac-附录)。

---

安全最佳实践

镜像安全

# ✅ 使用特定版本,非 latest
FROM node:20-alpine

# ✅ 以非 root 用户运行
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
USER appuser

# ✅ 扫描漏洞
# docker scan myimage:tag

密钥管理

| 方案 | 适用场景 | 工具 | | ------------ | ------------- | -------------------------- | | 环境变量 | 开发/简单部署 | .env 文件 | | 密钥管理服务 | 生产环境 | AWS Secrets Manager, Vault | | K8s Secrets | Kubernetes | kubectl create secret |

# 创建 K8s Secret
kubectl create secret generic app-secrets \
  --from-literal=db-password=mysecretpassword \
  --from-literal=api-key=myapikey

网络安全

# 网络策略示例 - 只允许特定来源访问
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: api-network-policy
spec:
  podSelector:
    matchLabels:
      app: api
  ingress:
    - from:
        - podSelector:
            matchLabels:
              app: frontend
      ports:
        - port: 8080

---

日志管理

结构化日志

{
  "timestamp": "2025-01-23T10:00:00Z",
  "level": "info",
  "service": "user-service",
  "traceId": "abc123",
  "message": "用户登录成功",
  "userId": "user_456",
  "duration": 45,
  "environment": "production"
}

日志级别指南

| 级别 | 用途 | 生产环境 | | ----- | ------------ | -------- | | DEBUG | 详细调试信息 | 关闭 | | INFO | 正常操作事件 | 开启 | | WARN | 潜在问题 | 开启 | | ERROR | 错误但可恢复 | 开启 | | FATAL | 致命错误

Read more
Read it on GitHub ↗

Showing the first part of this file.

Ships withcc-best

Role-Driven Development Workflow for Claude Code Transform Claude into a complete development team. From product requirements to code review — one plugin, full workflow. Quick Start • Features • Workflow • Commands • FAQ

Get the whole plugin, auto-invoked
Stats
49
Stars
0
Views
3
Forks
Maintained
Maintenance
JavaScript
Language
MIT
License
1mo ago
Last commit
6mo ago
Created

Repo: xiaobei930/cc-best