k8s-manifest-generator by wshobson/agents
npx skills add https://github.com/wshobson/agents --skill k8s-manifest-generator为创建生产就绪的 Kubernetes 清单提供分步指导,包括 Deployments、Services、ConfigMaps、Secrets 和 PersistentVolumeClaims。
此技能提供全面的指导,用于生成结构良好、安全且生产就绪的 Kubernetes 清单,遵循云原生最佳实践和 Kubernetes 约定。
在以下情况下使用此技能:
了解工作负载:
需要询问的问题:
遵循此结构:
apiVersion: apps/v1
kind: Deployment
metadata:
name: <app-name>
namespace: <namespace>
labels:
app: <app-name>
version: <version>
spec:
replicas: 3
selector:
matchLabels:
app: <app-name>
template:
metadata:
labels:
app: <app-name>
version: <version>
spec:
containers:
- name: <container-name>
image: <image>:<tag>
ports:
- containerPort: <port>
name: http
resources:
requests:
memory: "256Mi"
cpu: "250m"
limits:
memory: "512Mi"
cpu: "500m"
livenessProbe:
httpGet:
path: /health
port: http
initialDelaySeconds: 30
periodSeconds: 10
readinessProbe:
httpGet:
path: /ready
port: http
initialDelaySeconds: 5
periodSeconds: 5
env:
- name: ENV_VAR
value: "value"
envFrom:
- configMapRef:
name: <app-name>-config
- secretRef:
name: <app-name>-secret
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
应用的最佳实践:
:latest)参考: 查看 references/deployment-spec.md 获取详细的部署选项
选择合适的 Service 类型:
ClusterIP(仅内部):
apiVersion: v1
kind: Service
metadata:
name: <app-name>
namespace: <namespace>
labels:
app: <app-name>
spec:
type: ClusterIP
selector:
app: <app-name>
ports:
- name: http
port: 80
targetPort: 8080
protocol: TCP
LoadBalancer(外部访问):
apiVersion: v1
kind: Service
metadata:
name: <app-name>
namespace: <namespace>
labels:
app: <app-name>
annotations:
service.beta.kubernetes.io/aws-load-balancer-type: nlb
spec:
type: LoadBalancer
selector:
app: <app-name>
ports:
- name: http
port: 80
targetPort: 8080
protocol: TCP
参考: 查看 references/service-spec.md 获取服务类型和网络详细信息
用于应用程序配置:
apiVersion: v1
kind: ConfigMap
metadata:
name: <app-name>-config
namespace: <namespace>
data:
APP_MODE: production
LOG_LEVEL: info
DATABASE_HOST: db.example.com
# 用于配置文件
app.properties: |
server.port=8080
server.host=0.0.0.0
logging.level=INFO
最佳实践:
参考: 查看 assets/configmap-template.yaml 获取示例
用于敏感数据:
apiVersion: v1
kind: Secret
metadata:
name: <app-name>-secret
namespace: <namespace>
type: Opaque
stringData:
DATABASE_PASSWORD: "changeme"
API_KEY: "secret-api-key"
# 用于证书文件
tls.crt: |
-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----
tls.key: |
-----BEGIN PRIVATE KEY-----
...
-----END PRIVATE KEY-----
安全注意事项:
kubernetes.io/tls用于有状态应用程序:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: <app-name>-data
namespace: <namespace>
spec:
accessModes:
- ReadWriteOnce
storageClassName: gp3
resources:
requests:
storage: 10Gi
在 Deployment 中挂载:
spec:
template:
spec:
containers:
- name: app
volumeMounts:
- name: data
mountPath: /var/lib/app
volumes:
- name: data
persistentVolumeClaim:
claimName: <app-name>-data
存储注意事项:
向 Deployment 添加安全上下文:
spec:
template:
spec:
securityContext:
runAsNonRoot: true
runAsUser: 1000
fsGroup: 1000
seccompProfile:
type: RuntimeDefault
containers:
- name: app
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop:
- ALL
安全检查清单:
标准标签(推荐):
metadata:
labels:
app.kubernetes.io/name: <app-name>
app.kubernetes.io/instance: <instance-name>
app.kubernetes.io/version: "1.0.0"
app.kubernetes.io/component: backend
app.kubernetes.io/part-of: <system-name>
app.kubernetes.io/managed-by: kubectl
有用的注解:
metadata:
annotations:
description: "应用程序描述"
contact: "team@example.com"
prometheus.io/scrape: "true"
prometheus.io/port: "9090"
prometheus.io/path: "/metrics"
文件组织选项:
选项 1:使用 --- 分隔符的单个文件
# app-name.yaml
---
apiVersion: v1
kind: ConfigMap
...
---
apiVersion: v1
kind: Secret
...
---
apiVersion: apps/v1
kind: Deployment
...
---
apiVersion: v1
kind: Service
...
选项 2:单独的文件
manifests/
├── configmap.yaml
├── secret.yaml
├── deployment.yaml
├── service.yaml
└── pvc.yaml
选项 3:Kustomize 结构
base/
├── kustomization.yaml
├── deployment.yaml
├── service.yaml
└── configmap.yaml
overlays/
├── dev/
│ └── kustomization.yaml
└── prod/
└── kustomization.yaml
验证步骤:
# 客户端试运行验证
kubectl apply -f manifest.yaml --dry-run=client
# 服务器端验证
kubectl apply -f manifest.yaml --dry-run=server
# 使用 kubeval 验证
kubeval manifest.yaml
# 使用 kube-score 验证
kube-score score manifest.yaml
# 使用 kube-linter 检查
kube-linter lint manifest.yaml
测试清单:
使用场景: 标准的 Web API 或微服务
所需组件:
参考: 查看 assets/deployment-template.yaml
使用场景: 数据库或持久化存储应用程序
所需组件:
使用场景: 计划任务或批处理
所需组件:
使用场景: 带有边车容器的应用程序
所需组件:
以下模板可在 assets/ 目录中找到:
deployment-template.yaml - 包含最佳实践的标准部署service-template.yaml - 服务配置(ClusterIP、LoadBalancer、NodePort)configmap-template.yaml - 包含不同数据类型的 ConfigMap 示例secret-template.yaml - Secret 示例(用于生成,而非提交)pvc-template.yaml - PersistentVolumeClaim 模板references/deployment-spec.md - 详细的 Deployment 规范references/service-spec.md - 服务类型和网络详细信息Pod 无法启动:
kubectl describe pod <pod-name>kubectl get nodeskubectl get events --sort-by='.lastTimestamp'服务无法访问:
kubectl get endpoints <service-name>kubectl run debug --rm -it --image=busybox -- shConfigMap/Secret 未加载:
kubectl get configmap,secret创建清单后:
helm-chart-scaffolding - 用于模板化和打包gitops-workflow - 用于自动化部署k8s-security-policies - 用于高级安全配置每周安装数
3.4K
仓库
GitHub 星标数
32.2K
首次出现时间
2026 年 1 月 20 日
安全审计
安装于
claude-code2.6K
opencode2.6K
gemini-cli2.5K
codex2.4K
cursor2.4K
github-copilot2.1K
Step-by-step guidance for creating production-ready Kubernetes manifests including Deployments, Services, ConfigMaps, Secrets, and PersistentVolumeClaims.
This skill provides comprehensive guidance for generating well-structured, secure, and production-ready Kubernetes manifests following cloud-native best practices and Kubernetes conventions.
Use this skill when you need to:
Understand the workload:
Questions to ask:
Follow this structure:
apiVersion: apps/v1
kind: Deployment
metadata:
name: <app-name>
namespace: <namespace>
labels:
app: <app-name>
version: <version>
spec:
replicas: 3
selector:
matchLabels:
app: <app-name>
template:
metadata:
labels:
app: <app-name>
version: <version>
spec:
containers:
- name: <container-name>
image: <image>:<tag>
ports:
- containerPort: <port>
name: http
resources:
requests:
memory: "256Mi"
cpu: "250m"
limits:
memory: "512Mi"
cpu: "500m"
livenessProbe:
httpGet:
path: /health
port: http
initialDelaySeconds: 30
periodSeconds: 10
readinessProbe:
httpGet:
path: /ready
port: http
initialDelaySeconds: 5
periodSeconds: 5
env:
- name: ENV_VAR
value: "value"
envFrom:
- configMapRef:
name: <app-name>-config
- secretRef:
name: <app-name>-secret
Best practices to apply:
:latest)Reference: See references/deployment-spec.md for detailed deployment options
Choose the appropriate Service type:
ClusterIP (internal only):
apiVersion: v1
kind: Service
metadata:
name: <app-name>
namespace: <namespace>
labels:
app: <app-name>
spec:
type: ClusterIP
selector:
app: <app-name>
ports:
- name: http
port: 80
targetPort: 8080
protocol: TCP
LoadBalancer (external access):
apiVersion: v1
kind: Service
metadata:
name: <app-name>
namespace: <namespace>
labels:
app: <app-name>
annotations:
service.beta.kubernetes.io/aws-load-balancer-type: nlb
spec:
type: LoadBalancer
selector:
app: <app-name>
ports:
- name: http
port: 80
targetPort: 8080
protocol: TCP
Reference: See references/service-spec.md for service types and networking
For application configuration:
apiVersion: v1
kind: ConfigMap
metadata:
name: <app-name>-config
namespace: <namespace>
data:
APP_MODE: production
LOG_LEVEL: info
DATABASE_HOST: db.example.com
# For config files
app.properties: |
server.port=8080
server.host=0.0.0.0
logging.level=INFO
Best practices:
Reference: See assets/configmap-template.yaml for examples
For sensitive data:
apiVersion: v1
kind: Secret
metadata:
name: <app-name>-secret
namespace: <namespace>
type: Opaque
stringData:
DATABASE_PASSWORD: "changeme"
API_KEY: "secret-api-key"
# For certificate files
tls.crt: |
-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----
tls.key: |
-----BEGIN PRIVATE KEY-----
...
-----END PRIVATE KEY-----
Security considerations:
kubernetes.io/tls for TLS secretsFor stateful applications:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: <app-name>-data
namespace: <namespace>
spec:
accessModes:
- ReadWriteOnce
storageClassName: gp3
resources:
requests:
storage: 10Gi
Mount in Deployment:
spec:
template:
spec:
containers:
- name: app
volumeMounts:
- name: data
mountPath: /var/lib/app
volumes:
- name: data
persistentVolumeClaim:
claimName: <app-name>-data
Storage considerations:
Add security context to Deployment:
spec:
template:
spec:
securityContext:
runAsNonRoot: true
runAsUser: 1000
fsGroup: 1000
seccompProfile:
type: RuntimeDefault
containers:
- name: app
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop:
- ALL
Security checklist:
Standard labels (recommended):
metadata:
labels:
app.kubernetes.io/name: <app-name>
app.kubernetes.io/instance: <instance-name>
app.kubernetes.io/version: "1.0.0"
app.kubernetes.io/component: backend
app.kubernetes.io/part-of: <system-name>
app.kubernetes.io/managed-by: kubectl
Useful annotations:
metadata:
annotations:
description: "Application description"
contact: "team@example.com"
prometheus.io/scrape: "true"
prometheus.io/port: "9090"
prometheus.io/path: "/metrics"
File organization options:
Option 1: Single file with--- separator
# app-name.yaml
---
apiVersion: v1
kind: ConfigMap
...
---
apiVersion: v1
kind: Secret
...
---
apiVersion: apps/v1
kind: Deployment
...
---
apiVersion: v1
kind: Service
...
Option 2: Separate files
manifests/
├── configmap.yaml
├── secret.yaml
├── deployment.yaml
├── service.yaml
└── pvc.yaml
Option 3: Kustomize structure
base/
├── kustomization.yaml
├── deployment.yaml
├── service.yaml
└── configmap.yaml
overlays/
├── dev/
│ └── kustomization.yaml
└── prod/
└── kustomization.yaml
Validation steps:
# Dry-run validation
kubectl apply -f manifest.yaml --dry-run=client
# Server-side validation
kubectl apply -f manifest.yaml --dry-run=server
# Validate with kubeval
kubeval manifest.yaml
# Validate with kube-score
kube-score score manifest.yaml
# Check with kube-linter
kube-linter lint manifest.yaml
Testing checklist:
Use case: Standard web API or microservice
Components needed:
Reference: See assets/deployment-template.yaml
Use case: Database or persistent storage application
Components needed:
Use case: Scheduled tasks or batch processing
Components needed:
Use case: Application with sidecar containers
Components needed:
The following templates are available in the assets/ directory:
deployment-template.yaml - Standard deployment with best practicesservice-template.yaml - Service configurations (ClusterIP, LoadBalancer, NodePort)configmap-template.yaml - ConfigMap examples with different data typessecret-template.yaml - Secret examples (to be generated, not committed)pvc-template.yaml - PersistentVolumeClaim templatesreferences/deployment-spec.md - Detailed Deployment specificationreferences/service-spec.md - Service types and networking detailsPods not starting:
kubectl describe pod <pod-name>kubectl get nodeskubectl get events --sort-by='.lastTimestamp'Service not accessible:
kubectl get endpoints <service-name>kubectl run debug --rm -it --image=busybox -- shConfigMap/Secret not loading:
kubectl get configmap,secretAfter creating manifests:
helm-chart-scaffolding - For templating and packaginggitops-workflow - For automated deploymentsk8s-security-policies - For advanced security configurationsWeekly Installs
3.4K
Repository
GitHub Stars
32.2K
First Seen
Jan 20, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykFail
Installed on
claude-code2.6K
opencode2.6K
gemini-cli2.5K
codex2.4K
cursor2.4K
github-copilot2.1K
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
102,200 周安装