k8s-yaml-generator

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

K8s Generator

K8s 生成器

Overview

概述

This skill provides a complete workflow for generating Kubernetes YAML resources with built-in validation and intelligent CRD support. Generate production-ready manifests for any Kubernetes resource type, with automatic validation and version-aware documentation lookup for custom resources.
本技能提供了一套完整的工作流,用于生成Kubernetes YAML资源,内置验证功能并支持智能CRD处理。可为任何Kubernetes资源类型生成生产可用的清单,同时支持自动验证以及针对自定义资源的版本感知型文档查询。

When to Use This Skill

使用场景

Use this skill when:
  • Generating Kubernetes YAML manifests (Deployments, Services, ConfigMaps, etc.)
  • Creating custom resources (ArgoCD Applications, Istio VirtualServices, etc.)
  • Building production-ready Kubernetes configurations
  • Need to ensure YAML validity and K8s API compliance
  • Working with CRDs that require documentation lookup
在以下场景中使用本技能:
  • 生成Kubernetes YAML清单(Deployment、Service、ConfigMap等)
  • 创建自定义资源(ArgoCD Application、Istio VirtualService等)
  • 构建生产可用的Kubernetes配置
  • 需要确保YAML有效性和K8s API合规性
  • 处理需要查询文档的CRD

Core Workflow

核心工作流

Follow this workflow when generating Kubernetes YAML resources:
生成Kubernetes YAML资源时,请遵循以下工作流:

1. Understand Requirements

1. 明确需求

Gather information about:
  • Resource type (Deployment, Service, ConfigMap, CRD, etc.)
  • Target Kubernetes version (if specified)
  • Application requirements (replicas, ports, volumes, etc.)
  • Environment-specific needs (namespaces, labels, annotations)
  • Custom resource specifications (for CRDs)
For CRDs specifically:
  • Identify the CRD type and version (e.g., ArgoCD Application v1alpha1, Istio VirtualService v1beta1)
  • Determine if documentation is needed (complex CRDs, unfamiliar APIs)
收集以下信息:
  • 资源类型(Deployment、Service、ConfigMap、CRD等)
  • 目标Kubernetes版本(若已指定)
  • 应用需求(副本数、端口、卷等)
  • 环境特定需求(命名空间、标签、注解)
  • 自定义资源规格(针对CRD)
针对CRD的额外要求:
  • 确定CRD类型和版本(例如:ArgoCD Application v1alpha1、Istio VirtualService v1beta1)
  • 判断是否需要文档支持(复杂CRD、不熟悉的API)

2. Fetch CRD Documentation (if needed)

2. 获取CRD文档(若需要)

When dealing with Custom Resource Definitions (CRDs):
IMPORTANT: Always consider version compatibility when working with CRDs
Step 2a: Identify the CRD and Version
  • Extract the CRD's apiVersion and kind from the user request
  • Examples:
    • ArgoCD Application:
      apiVersion: argoproj.io/v1alpha1, kind: Application
    • Istio VirtualService:
      apiVersion: networking.istio.io/v1beta1, kind: VirtualService
    • Cert-Manager Certificate:
      apiVersion: cert-manager.io/v1, kind: Certificate
Step 2b: Resolve Library ID using Context7 MCP
Use the
mcp__context7__resolve-library-id
tool to find the correct library:
libraryName: "<project-name>"
Examples:
  • For ArgoCD:
    libraryName: "argo-cd"
  • For Istio:
    libraryName: "istio"
  • For Cert-Manager:
    libraryName: "cert-manager"
The tool will return:
  • A list of matching libraries with their Context7-compatible IDs (format:
    /org/project
    or
    /org/project/version
    )
  • Benchmark scores indicating documentation quality
  • Code snippet counts showing coverage
Select the most appropriate library based on:
  • Name match accuracy
  • Target version compatibility (if user specified a version)
  • Benchmark score (higher is better, 100 is highest)
  • Documentation coverage (code snippet count)
Step 2c: Fetch Documentation using Context7 MCP
Use the
mcp__context7__get-library-docs
tool with the selected library ID:
context7CompatibleLibraryID: "/org/project/version"
topic: "specific CRD type or feature"
page: 1
Examples:
  • For ArgoCD Application CRD:
    context7CompatibleLibraryID: "/argoproj/argo-cd/v2.9.0", topic: "application crd spec", page: 1
  • For Istio VirtualService:
    context7CompatibleLibraryID: "/istio/istio/1.20.0", topic: "virtualservice", page: 1
If context is insufficient:
  • Increment the
    page
    parameter (page: 2, page: 3, etc.) with the same topic
  • Try different topic keywords
  • Maximum page number is 10
Step 2d: Fallback to Web Search
If context7 MCP fails or returns insufficient information:
  • Use the
    WebSearch
    tool with version-specific queries
  • Include the version in the search query:
    "<CRD-name> <version> spec documentation"
  • Examples:
    • "ArgoCD Application v1alpha1 spec documentation"
    • "Istio VirtualService v1beta1 configuration"
    • "cert-manager Certificate v1 spec fields"
CRITICAL: Always include version information in web searches to ensure compatibility
处理自定义资源定义(CRD)时:
重要提示:处理CRD时请始终考虑版本兼容性
步骤2a:识别CRD和版本
  • 从用户请求中提取CRD的apiVersion和kind
  • 示例:
    • ArgoCD Application:
      apiVersion: argoproj.io/v1alpha1, kind: Application
    • Istio VirtualService:
      apiVersion: networking.istio.io/v1beta1, kind: VirtualService
    • Cert-Manager Certificate:
      apiVersion: cert-manager.io/v1, kind: Certificate
步骤2b:使用Context7 MCP解析库ID
使用
mcp__context7__resolve-library-id
工具查找正确的库:
libraryName: "<项目名称>"
示例:
  • 针对ArgoCD:
    libraryName: "argo-cd"
  • 针对Istio:
    libraryName: "istio"
  • 针对Cert-Manager:
    libraryName: "cert-manager"
工具将返回:
  • 匹配的库列表及其Context7兼容ID(格式:
    /org/project
    /org/project/version
  • 表示文档质量的基准评分
  • 显示覆盖范围的代码片段数量
根据以下条件选择最合适的库:
  • 名称匹配准确度
  • 目标版本兼容性(若用户指定了版本)
  • 基准评分(分数越高越好,最高为100)
  • 文档覆盖范围(代码片段数量)
步骤2c:使用Context7 MCP获取文档
使用
mcp__context7__get-library-docs
工具并传入选定的库ID:
context7CompatibleLibraryID: "/org/project/version"
topic: "特定CRD类型或功能"
page: 1
示例:
  • 针对ArgoCD Application CRD:
    context7CompatibleLibraryID: "/argoproj/argo-cd/v2.9.0", topic: "application crd spec", page: 1
  • 针对Istio VirtualService:
    context7CompatibleLibraryID: "/istio/istio/1.20.0", topic: "virtualservice", page: 1
若上下文信息不足:
  • 增加
    page
    参数(page: 2, page: 3等)并保持主题不变
  • 尝试不同的主题关键词
  • 最大页码为10
步骤2d:回退到网页搜索
若Context7 MCP失败或返回信息不足:
  • 使用
    WebSearch
    工具并传入带版本的查询词
  • 在搜索查询中包含版本:
    "<CRD名称> <版本> spec 文档"
  • 示例:
    • "ArgoCD Application v1alpha1 spec documentation"
    • "Istio VirtualService v1beta1 configuration"
    • "cert-manager Certificate v1 spec fields"
关键提示:网页搜索时请始终包含版本信息以确保兼容性

3. Generate YAML Resource

3. 生成YAML资源

Apply Kubernetes best practices:
General Best Practices:
  • Use explicit API versions (avoid deprecated versions)
  • Include meaningful labels for organization and selection (use Kubernetes recommended labels):
    yaml
    labels:
      app.kubernetes.io/name: myapp
      app.kubernetes.io/instance: myapp-abc123
      app.kubernetes.io/version: "1.0.0"
      app.kubernetes.io/component: frontend
      app.kubernetes.io/part-of: myplatform
      app.kubernetes.io/managed-by: claude-code
  • Add annotations for metadata and tooling:
    yaml
    annotations:
      description: "Purpose of this resource"
      contact: "team@example.com"
  • Specify resource requests and limits (for Pods):
    yaml
    resources:
      requests:
        memory: "64Mi"
        cpu: "250m"
      limits:
        memory: "128Mi"
        cpu: "500m"
  • Use namespaces for multi-tenancy
  • Implement health checks (livenessProbe, readinessProbe)
  • Follow naming conventions (lowercase, hyphens, descriptive)
Security Best Practices:
  • Never run containers as root (use
    securityContext
    )
  • Implement Pod Security Standards
  • Use least-privilege RBAC
  • Store secrets in Secret objects, not ConfigMaps
  • Use
    imagePullPolicy: Always
    or
    IfNotPresent
    appropriately
For CRDs:
  • Reference the fetched documentation for accurate spec fields
  • Include all required fields
  • Use appropriate defaults for optional fields
  • Add comments explaining complex configurations
Common Resource Templates:
Deployment:
yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
  namespace: default
  labels:
    app.kubernetes.io/name: myapp
    app.kubernetes.io/instance: myapp-prod
    app.kubernetes.io/version: "1.0.0"
    app.kubernetes.io/component: backend
    app.kubernetes.io/part-of: myplatform
    app.kubernetes.io/managed-by: claude-code
spec:
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: myapp
      app.kubernetes.io/instance: myapp-prod
  template:
    metadata:
      labels:
        app.kubernetes.io/name: myapp
        app.kubernetes.io/instance: myapp-prod
        app.kubernetes.io/version: "1.0.0"
        app.kubernetes.io/component: backend
        app.kubernetes.io/part-of: myplatform
        app.kubernetes.io/managed-by: claude-code
    spec:
      containers:
      - name: myapp
        image: myapp:1.0.0
        ports:
        - containerPort: 8080
        resources:
          requests:
            memory: "64Mi"
            cpu: "250m"
          limits:
            memory: "128Mi"
            cpu: "500m"
        livenessProbe:
          httpGet:
            path: /health
            port: 8080
          initialDelaySeconds: 30
          periodSeconds: 10
        readinessProbe:
          httpGet:
            path: /ready
            port: 8080
          initialDelaySeconds: 5
          periodSeconds: 5
Service:
yaml
apiVersion: v1
kind: Service
metadata:
  name: myapp-service
  namespace: default
  labels:
    app.kubernetes.io/name: myapp
    app.kubernetes.io/instance: myapp-prod
    app.kubernetes.io/component: backend
    app.kubernetes.io/part-of: myplatform
    app.kubernetes.io/managed-by: claude-code
spec:
  type: ClusterIP  # or LoadBalancer, NodePort
  selector:
    app.kubernetes.io/name: myapp
    app.kubernetes.io/instance: myapp-prod
  ports:
  - protocol: TCP
    port: 80
    targetPort: 8080
    name: http
ConfigMap:
yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: myapp-config
  namespace: default
  labels:
    app.kubernetes.io/name: myapp
    app.kubernetes.io/instance: myapp-prod
    app.kubernetes.io/component: config
    app.kubernetes.io/part-of: myplatform
    app.kubernetes.io/managed-by: claude-code
data:
  app.properties: |
    key1=value1
    key2=value2
  config.json: |
    {
      "setting": "value"
    }
遵循Kubernetes最佳实践:
通用最佳实践:
  • 使用明确的API版本(避免已弃用的版本)
  • 添加有意义的标签以便组织和选择(使用Kubernetes推荐标签):
    yaml
    labels:
      app.kubernetes.io/name: myapp
      app.kubernetes.io/instance: myapp-abc123
      app.kubernetes.io/version: "1.0.0"
      app.kubernetes.io/component: frontend
      app.kubernetes.io/part-of: myplatform
      app.kubernetes.io/managed-by: claude-code
  • 添加注解以提供元数据和工具相关信息:
    yaml
    annotations:
      description: "该资源的用途"
      contact: "team@example.com"
  • 为Pod指定资源请求和限制:
    yaml
    resources:
      requests:
        memory: "64Mi"
        cpu: "250m"
      limits:
        memory: "128Mi"
        cpu: "500m"
  • 使用命名空间实现多租户
  • 配置健康检查(livenessProbe、readinessProbe)
  • 遵循命名规范(小写、连字符、描述性名称)
安全最佳实践:
  • 不要以root用户运行容器(使用
    securityContext
  • 实施Pod安全标准
  • 使用最小权限RBAC
  • 将密钥存储在Secret对象中,而非ConfigMap
  • 合理使用
    imagePullPolicy: Always
    IfNotPresent
针对CRD的最佳实践:
  • 参考获取的文档以确保spec字段的准确性
  • 包含所有必填字段
  • 为可选字段设置合适的默认值
  • 添加注释解释复杂配置
常见资源模板:
Deployment:
yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
  namespace: default
  labels:
    app.kubernetes.io/name: myapp
    app.kubernetes.io/instance: myapp-prod
    app.kubernetes.io/version: "1.0.0"
    app.kubernetes.io/component: backend
    app.kubernetes.io/part-of: myplatform
    app.kubernetes.io/managed-by: claude-code
spec:
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: myapp
      app.kubernetes.io/instance: myapp-prod
  template:
    metadata:
      labels:
        app.kubernetes.io/name: myapp
        app.kubernetes.io/instance: myapp-prod
        app.kubernetes.io/version: "1.0.0"
        app.kubernetes.io/component: backend
        app.kubernetes.io/part-of: myplatform
        app.kubernetes.io/managed-by: claude-code
    spec:
      containers:
      - name: myapp
        image: myapp:1.0.0
        ports:
        - containerPort: 8080
        resources:
          requests:
            memory: "64Mi"
            cpu: "250m"
          limits:
            memory: "128Mi"
            cpu: "500m"
        livenessProbe:
          httpGet:
            path: /health
            port: 8080
          initialDelaySeconds: 30
          periodSeconds: 10
        readinessProbe:
          httpGet:
            path: /ready
            port: 8080
          initialDelaySeconds: 5
          periodSeconds: 5
Service:
yaml
apiVersion: v1
kind: Service
metadata:
  name: myapp-service
  namespace: default
  labels:
    app.kubernetes.io/name: myapp
    app.kubernetes.io/instance: myapp-prod
    app.kubernetes.io/component: backend
    app.kubernetes.io/part-of: myplatform
    app.kubernetes.io/managed-by: claude-code
spec:
  type: ClusterIP  # 或LoadBalancer、NodePort
  selector:
    app.kubernetes.io/name: myapp
    app.kubernetes.io/instance: myapp-prod
  ports:
  - protocol: TCP
    port: 80
    targetPort: 8080
    name: http
ConfigMap:
yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: myapp-config
  namespace: default
  labels:
    app.kubernetes.io/name: myapp
    app.kubernetes.io/instance: myapp-prod
    app.kubernetes.io/component: config
    app.kubernetes.io/part-of: myplatform
    app.kubernetes.io/managed-by: claude-code
data:
  app.properties: |
    key1=value1
    key2=value2
  config.json: |
    {
      "setting": "value"
    }

4. Validate Generated YAML

4. 验证生成的YAML

CRITICAL: Always validate generated YAML using the devops-skills:k8s-yaml-validator skill
After generating the YAML resource, immediately invoke the devops-skills:k8s-yaml-validator skill:
Use the Skill tool:
Skill: devops-skills:k8s-yaml-validator
The devops-skills:k8s-yaml-validator skill will:
  1. Validate YAML syntax using
    yamllint
  2. Validate Kubernetes API compliance using
    kubeconform
  3. Check for best practices and common issues
  4. For CRDs: Automatically detect custom resources and fetch documentation if needed
  5. Perform dry-run validation against the cluster (if available)
Wait for validation results and address any issues:
  • Syntax errors: Fix YAML formatting issues
  • Schema errors: Correct field names, types, or structure
  • Best practice violations: Update according to recommendations
  • CRD validation errors: Re-fetch documentation and correct spec fields
If validation fails:
  • Review the error messages carefully
  • Update the YAML to address the issues
  • Re-run validation
  • Repeat until validation passes
关键提示:请始终使用devops-skills:k8s-yaml-validator技能验证生成的YAML
生成YAML资源后,立即调用devops-skills:k8s-yaml-validator技能:
使用Skill工具:
Skill: devops-skills:k8s-yaml-validator
devops-skills:k8s-yaml-validator技能将执行以下操作:
  1. 使用
    yamllint
    验证YAML语法
  2. 使用
    kubeconform
    验证Kubernetes API合规性
  3. 检查最佳实践和常见问题
  4. 针对CRD:自动检测自定义资源并在需要时获取文档
  5. 针对集群执行试运行验证(若可用)
等待验证结果并解决所有问题:
  • 语法错误:修复YAML格式问题
  • 架构错误:修正字段名称、类型或结构
  • 最佳实践违规:根据建议更新配置
  • CRD验证错误:重新获取文档并修正spec字段
若验证失败:
  • 仔细查看错误信息
  • 更新YAML以解决问题
  • 重新运行验证
  • 重复直到验证通过

5. Deliver the Resource

5. 交付资源

Once validation passes:
  • Present the validated YAML to the user
  • Include a summary of what was generated
  • Highlight any important configuration choices
  • Suggest next steps (kubectl apply, customization, etc.)
Format:
yaml
undefined
验证通过后:
  • 向用户展示已验证的YAML
  • 包含生成内容的摘要
  • 突出显示重要的配置选择
  • 建议后续步骤(kubectl apply、自定义等)
格式:
yaml
undefined

Generated and validated Kubernetes resource

已生成并验证的Kubernetes资源

Resource: <Type>

资源类型: <Type>

Namespace: <namespace>

命名空间: <namespace>

Validation: Passed

验证状态: 通过

<YAML content here> ```
Suggest next steps:
bash
undefined
<YAML内容>

**建议后续步骤:**
```bash

Apply the resource

应用资源

kubectl apply -f <filename>.yaml
kubectl apply -f <文件名>.yaml

Verify the resource

验证资源

kubectl get <resource-type> <name> -n <namespace>
kubectl get <资源类型> <名称> -n <命名空间>

Check status

检查状态

kubectl describe <resource-type> <name> -n <namespace>
undefined
kubectl describe <资源类型> <名称> -n <命名空间>
undefined

Advanced Features

高级功能

Multi-Resource Generation

多资源生成

When generating multiple related resources:
  1. Create each resource following the core workflow
  2. Use consistent labels across resources for grouping
  3. Consider resource dependencies (create ConfigMaps before Deployments)
  4. Validate each resource individually with devops-skills:k8s-yaml-validator
  5. Optionally combine into a single multi-document YAML file using
    ---
    separator
Example multi-document YAML:
yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: myapp-config
  labels:
    app.kubernetes.io/name: myapp
    app.kubernetes.io/instance: myapp-prod
    app.kubernetes.io/part-of: myplatform
data:
  key: value
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
  labels:
    app.kubernetes.io/name: myapp
    app.kubernetes.io/instance: myapp-prod
    app.kubernetes.io/part-of: myplatform
spec:
  # deployment spec with matching labels
---
apiVersion: v1
kind: Service
metadata:
  name: myapp-service
  labels:
    app.kubernetes.io/name: myapp
    app.kubernetes.io/instance: myapp-prod
    app.kubernetes.io/part-of: myplatform
spec:
  # service spec with matching selector
生成多个相关资源时:
  1. 遵循核心工作流创建每个资源
  2. 在资源间使用一致的标签以便分组
  3. 考虑资源依赖关系(先创建ConfigMap再创建Deployment)
  4. 使用devops-skills:k8s-yaml-validator分别验证每个资源
  5. 可选择使用
    ---
    分隔符将多个资源合并为单个多文档YAML文件
多文档YAML示例:
yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: myapp-config
  labels:
    app.kubernetes.io/name: myapp
    app.kubernetes.io/instance: myapp-prod
    app.kubernetes.io/part-of: myplatform
data:
  key: value
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
  labels:
    app.kubernetes.io/name: myapp
    app.kubernetes.io/instance: myapp-prod
    app.kubernetes.io/part-of: myplatform
spec:
  # 带匹配标签的deployment spec
---
apiVersion: v1
kind: Service
metadata:
  name: myapp-service
  labels:
    app.kubernetes.io/name: myapp
    app.kubernetes.io/instance: myapp-prod
    app.kubernetes.io/part-of: myplatform
spec:
  # 带匹配选择器的service spec

Version-Specific Generation

特定版本生成

When targeting specific Kubernetes versions:
  • Use appropriate API versions (check deprecations)
  • Reference version-specific features
  • Note any version-specific caveats
  • Example: Ingress moved from
    extensions/v1beta1
    to
    networking.k8s.io/v1
    in K8s 1.19+
针对特定Kubernetes版本时:
  • 使用合适的API版本(检查弃用情况)
  • 参考特定版本的功能
  • 注意任何版本特定的注意事项
  • 示例:Ingress在K8s 1.19+中从
    extensions/v1beta1
    迁移到
    networking.k8s.io/v1

Namespace Management

命名空间管理

Best practices for namespace handling:
  • Always specify namespace in metadata (except for cluster-scoped resources)
  • Use namespaces for environment separation (dev, staging, prod)
  • Consider namespace-scoped resources vs cluster-scoped
  • Include namespace creation YAML if needed
命名空间处理的最佳实践:
  • 始终在元数据中指定命名空间(集群范围资源除外)
  • 使用命名空间实现环境隔离(dev、staging、prod)
  • 考虑命名空间范围资源与集群范围资源的区别
  • 若需要,包含命名空间创建YAML

Common CRDs and Examples

常见CRD及示例

ArgoCD Application

ArgoCD Application

yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: myapp
  namespace: argocd
  labels:
    app.kubernetes.io/name: myapp
    app.kubernetes.io/instance: myapp-prod
    app.kubernetes.io/part-of: myplatform
    app.kubernetes.io/managed-by: argocd
spec:
  project: default
  source:
    repoURL: https://github.com/org/repo
    targetRevision: HEAD
    path: manifests
  destination:
    server: https://kubernetes.default.svc
    namespace: myapp
  syncPolicy:
    automated:
      prune: true
      selfHeal: true
yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: myapp
  namespace: argocd
  labels:
    app.kubernetes.io/name: myapp
    app.kubernetes.io/instance: myapp-prod
    app.kubernetes.io/part-of: myplatform
    app.kubernetes.io/managed-by: argocd
spec:
  project: default
  source:
    repoURL: https://github.com/org/repo
    targetRevision: HEAD
    path: manifests
  destination:
    server: https://kubernetes.default.svc
    namespace: myapp
  syncPolicy:
    automated:
      prune: true
      selfHeal: true

Istio VirtualService

Istio VirtualService

yaml
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: myapp
  labels:
    app.kubernetes.io/name: myapp
    app.kubernetes.io/instance: myapp-prod
    app.kubernetes.io/component: networking
    app.kubernetes.io/part-of: myplatform
spec:
  hosts:
  - myapp.example.com
  gateways:
  - myapp-gateway
  http:
  - route:
    - destination:
        host: myapp-service
        port:
          number: 8080
yaml
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: myapp
  labels:
    app.kubernetes.io/name: myapp
    app.kubernetes.io/instance: myapp-prod
    app.kubernetes.io/component: networking
    app.kubernetes.io/part-of: myplatform
spec:
  hosts:
  - myapp.example.com
  gateways:
  - myapp-gateway
  http:
  - route:
    - destination:
        host: myapp-service
        port:
          number: 8080

Cert-Manager Certificate

Cert-Manager Certificate

yaml
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: myapp-tls
  namespace: default
  labels:
    app.kubernetes.io/name: myapp
    app.kubernetes.io/instance: myapp-prod
    app.kubernetes.io/component: tls
    app.kubernetes.io/part-of: myplatform
spec:
  secretName: myapp-tls-secret
  issuerRef:
    name: letsencrypt-prod
    kind: ClusterIssuer
  dnsNames:
  - myapp.example.com
yaml
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: myapp-tls
  namespace: default
  labels:
    app.kubernetes.io/name: myapp
    app.kubernetes.io/instance: myapp-prod
    app.kubernetes.io/component: tls
    app.kubernetes.io/part-of: myplatform
spec:
  secretName: myapp-tls-secret
  issuerRef:
    name: letsencrypt-prod
    kind: ClusterIssuer
  dnsNames:
  - myapp.example.com

Troubleshooting

故障排除

CRD Documentation Not Found

CRD文档未找到

  • Issue: Context7 MCP cannot find the CRD documentation
  • Solution:
    • Try alternative search terms (project name variations)
    • Use WebSearch as fallback with version-specific queries
    • Check the official project documentation directly
  • 问题:Context7 MCP无法找到CRD文档
  • 解决方案
    • 尝试替代搜索词(项目名称变体)
    • 使用带版本的查询词回退到网页搜索
    • 直接查看官方项目文档

Validation Failures

验证失败

  • Issue: devops-skills:k8s-yaml-validator reports errors
  • Solution:
    • Read error messages carefully
    • Check field names and types against documentation
    • Verify API version compatibility
    • Ensure required fields are present
  • 问题:devops-skills:k8s-yaml-validator报告错误
  • 解决方案
    • 仔细阅读错误信息
    • 根据文档检查字段名称和类型
    • 验证API版本兼容性
    • 确保必填字段已存在

Version Mismatches

版本不匹配

  • Issue: Generated YAML uses wrong API version
  • Solution:
    • Confirm target Kubernetes version with user
    • Check API deprecation status
    • Update apiVersion field to correct version
    • Re-validate
  • 问题:生成的YAML使用了错误的API版本
  • 解决方案
    • 与用户确认目标Kubernetes版本
    • 检查API弃用状态
    • 将apiVersion字段更新为正确版本
    • 重新验证

Integration with Other Skills

与其他技能的集成

This skill works seamlessly with:
  • devops-skills:k8s-yaml-validator: Automatic validation of generated resources
  • k8s-debug: Troubleshooting deployed resources
  • helm-validator: Validating Helm charts that use these resources
本技能可与以下技能无缝协作:
  • devops-skills:k8s-yaml-validator:自动验证生成的资源
  • k8s-debug:排查已部署资源的问题
  • helm-validator:验证使用这些资源的Helm Chart

Summary

总结

The k8s-generator skill provides:
  1. ✅ Intelligent YAML generation for any Kubernetes resource
  2. ✅ Automatic validation via devops-skills:k8s-yaml-validator
  3. ✅ Version-aware CRD documentation lookup via context7 MCP
  4. ✅ Fallback web search for CRD specifications
  5. ✅ Best practices and security considerations
  6. ✅ Production-ready configurations
Always follow the core workflow: Understand → Fetch CRD Docs (if needed) → Generate → Validate → Deliver
k8s-generator技能提供:
  1. ✅ 针对任何Kubernetes资源的智能YAML生成
  2. ✅ 通过devops-skills:k8s-yaml-validator实现自动验证
  3. ✅ 通过Context7 MCP实现版本感知型CRD文档查询
  4. ✅ CRD规格的回退网页搜索
  5. ✅ 最佳实践和安全考量
  6. ✅ 生产可用的配置
请始终遵循核心工作流:理解需求 → 获取CRD文档(若需要)→ 生成 → 验证 → 交付