2. SKILL.md 格式
2.1 基本结构
markdown
---
name: deployment
description: Deploy applications to production using Docker and Kubernetes
triggers:
- deploy
- deployment
- production
- k8s
- kubernetes
version: 1.0.0
author: team@example.com
---
# Deployment Skill
## When to Use
Use this skill when you need to:
- Deploy applications to production
- Update existing deployments
- Rollback deployments
- Check deployment status
## Prerequisites
- Docker installed
- kubectl configured
- Access to production cluster
- CI/CD pipeline passing
## Workflow
### 1. Pre-deployment Checks
\`\`\`bash
# Run tests
npm test
# Check linting
npm run lint
# Build locally to verify
npm run build
\`\`\`
### 2. Build Docker Image
\`\`\`bash
# Build image
docker build -t myapp:${VERSION} .
# Tag for registry
docker tag myapp:${VERSION} registry.example.com/myapp:${VERSION}
# Push to registry
docker push registry.example.com/myapp:${VERSION}
\`\`\`
### 3. Update Kubernetes Deployment
\`\`\`bash
# Update deployment
kubectl set image deployment/myapp myapp=registry.example.com/myapp:${VERSION}
# Wait for rollout
kubectl rollout status deployment/myapp
# Verify pods
kubectl get pods -l app=myapp
\`\`\`
### 4. Post-deployment Verification
\`\`\`bash
# Check health endpoint
curl https://myapp.example.com/health
# Check logs
kubectl logs -l app=myapp --tail=50
# Run smoke tests
npm run test:smoke
\`\`\`
## Rollback Procedure
If deployment fails:
\`\`\`bash
# Rollback to previous version
kubectl rollout undo deployment/myapp
# Verify rollback
kubectl rollout status deployment/myapp
\`\`\`
## Common Issues
### Issue: Image pull error
**Symptom**: Pods stuck in ImagePullBackOff
**Solution**:
1. Verify image exists: `docker pull registry.example.com/myapp:${VERSION}`
2. Check registry credentials: `kubectl get secret regcred`
3. Verify image tag is correct
### Issue: Health check failing
**Symptom**: Pods restarting repeatedly
**Solution**:
1. Check application logs: `kubectl logs <pod-name>`
2. Verify environment variables: `kubectl describe pod <pod-name>`
3. Test health endpoint locally
## References
- [Kubernetes Deployment Guide](./references/k8s-deployment.md)
- [Docker Best Practices](./references/docker-best-practices.md)
- [Rollback Procedures](./references/rollback-procedures.md)2.2 YAML Frontmatter 详解
yaml
---
# 必需字段
name: skill-name # 唯一标识符,kebab-case
description: Short description # 简短描述,用于自动检测
# 触发器(可选但推荐)
triggers: # 关键词列表
- keyword1
- keyword2
- phrase with spaces
# 元数据(可选)
version: 1.0.0 # 语义化版本
author: email@example.com # 作者
tags: # 标签
- deployment
- kubernetes
- production
# 依赖(可选)
dependencies: # 依赖的其他 skills
- docker-skill
- testing-skill
# 权限(可选)
permissions: # 需要的权限
- network
- git_write
# 配置(可选)
config: # 可配置项
registry: registry.example.com
cluster: production
---