SuperAPI AI Directory

kubernetes-orchestration

Deployment & operations

View repository

Updated 10-16 09:30

About this skill

Kubernetes Orchestration

References: Kubernetes official documentation, Helm documentation, ArgoCD documentation, CNCF best practices, Production Kubernetes (Josh Rosso).

Applicable Scenarios

  • Deploying applications to a Kubernetes cluster
  • Writing and managing Helm Charts
  • Designing GitOps workflows (ArgoCD / Flux)
  • Configuring autoscaling (HPA / VPA / KEDA)
  • High availability and disaster recovery (PDB / Pod Anti-Affinity)
  • Tuning resource requests and limits
  • Service mesh integration (Istio / Linkerd)

Core Principles

1. 声明式管理
   所有资源 YAML 在 Git 中
   kubectl apply,不 kubectl edit

2. GitOps 单一真相源
   Git 仓库 = 集群期望状态
   ArgoCD / Flux 自动同步

3. 资源限制必设
   requests = 保证资源
   limits = 上限(防止 noisy neighbor)

4. 高可用默认
   replicas >= 2
   PDB 保证滚动更新不中断
   Pod Anti-Affinity 分散节点

5. 健康检查三件套
   livenessProbe:进程存活
   readinessProbe:可接收流量
   startupProbe:慢启动保护

6. 标签规范
   app.kubernetes.io/name
   app.kubernetes.io/version
   app.kubernetes.io/component

7. Namespace 隔离
   按团队 / 环境 / 服务域划分
   RBAC 按 namespace 授权

Workflow

1. 设计资源清单
   - Deployment / StatefulSet / DaemonSet
   - Service(ClusterIP / NodePort / LoadBalancer)
   - Ingress / IngressRoute
   - ConfigMap / Secret
   - HPA / PDB

2. 编写 Helm Chart
   - Chart.yaml(元数据)
   - values.yaml(默认值)
   - templates/(资源模板)
   - 环境 override(values-prod.yaml)

3. 配置健康检查
   - livenessProbe(HTTP / TCP / exec)
   - readinessProbe(HTTP /health/ready)
   - startupProbe(慢启动应用)

4. 资源调优
   - 压测确定 requests
   - limits = 2x requests(初始)
   - VPA 推荐后调整

5. 自动伸缩
   - HPA:CPU / Memory / 自定义指标
   - KEDA:基于队列深度 / 请求数
   - 设置 min / max replicas

6. GitOps 部署
   - ArgoCD Application 定义
   - 自动同步 / 手动同步
   - 同步窗口(生产限制时段)

7. 可观测性
   - ServiceMonitor(Prometheus)
   - 日志标签(结构化)
   - 分布式追踪注入

8. 安全加固
   - NetworkPolicy 限制流量
   - PodSecurityStandard
   - ServiceAccount 最小权限

Resource Configuration Reference

Resource Type Key Configuration Notes
Deployment replicas / strategy / resources Rolling update maxSurge / maxUnavailable
Service type / port / targetPort ClusterIP is the default
Ingress host / path / TLS Annotations vary by controller
HPA min / max / metrics Cooldown period avoids flapping
PDB minAvailable / maxUnavailable Ensures availability during rolling updates
NetworkPolicy ingress / egress rules Default deny all

Helm Chart Structure

charts/my-app/
├── Chart.yaml
├── values.yaml              ← 默认值
├── values-staging.yaml      ← staging 覆盖
├── values-production.yaml   ← production 覆盖
├── templates/
│   ├── _helpers.tpl         ← 模板函数
│   ├── deployment.yaml
│   ├── service.yaml
│   ├── ingress.yaml
│   ├── hpa.yaml
│   ├── pdb.yaml
│   ├── configmap.yaml
│   └── serviceaccount.yaml
└── README.md

Quality Self-Check

□ 所有 Pod 设置 resources.requests 和 limits
□ livenessProbe + readinessProbe 已配置
□ replicas >= 2(生产环境)
□ PDB 已配置(minAvailable >= 1)
□ Pod Anti-Affinity 分散节点
□ 滚动更新策略合理(maxSurge / maxUnavailable)
□ HPA 已配置(CPU + 自定义指标)
□ NetworkPolicy 限制不必要流量
□ Secrets 不硬编码在 YAML 中
□ 标签规范(app / version / component)
□ Namespace 隔离
□ Helm values 按环境分离
□ ArgoCD 同步策略已配置
□ RBAC 最小权限

Common Pitfalls

  1. No resource limits set——A single Pod consumes all node resources
  2. replicas=1——Single point of failure, updates cause interruption
  3. No PDB——All evicted during node maintenance
  4. Missing readinessProbe——Traffic received before ready, 502
  5. liveness = readiness identical——Killed when dependencies are unavailable
  6. Single HPA metric——Only CPU monitored, memory OOM
  7. Not using Helm values for per-environment config——Production configuration hardcoded
  8. kubectl edit modifications——GitOps drift
  9. latest tag——Cannot roll back
  10. No terminationGracePeriodSeconds set——Forced kill drops requests
  11. Secrets in plaintext in Git——Security incident
  12. Ingress without rate limit——DDoS breaks through

Supporting Templates

  • templates/k8s-deployment-template.md — Complete template for Deployment + Service + Ingress + HPA + PDB

Collaboration with Other Skills

上游:
  containerization → 镜像产物
  infrastructure-as-code → 集群基础设施(EKS / GKE)
  ci-cd-pipeline → 构建触发部署

下游:
  networking-gateway → Ingress / Service Mesh
  monitoring-alerting → ServiceMonitor / 告警规则
  release-strategy → 金丝雀 / 蓝绿部署
  secrets-config → K8s Secrets / External Secrets