$npx -y skills add ancoleman/ai-design-components --skill operating-kubernetesOperating production Kubernetes clusters effectively with resource management, advanced scheduling, networking, storage, security hardening, and autoscaling. Use when deploying workloads to Kubernetes, configuring cluster resources, implementing security policies, or troubleshoot
| 1 | # Kubernetes Operations |
| 2 | |
| 3 | ## Purpose |
| 4 | |
| 5 | Operating Kubernetes clusters in production requires mastery of resource management, scheduling patterns, networking architecture, storage strategies, security hardening, and autoscaling. This skill provides operations-first frameworks for right-sizing workloads, implementing high-availability patterns, securing clusters with RBAC and Pod Security Standards, and systematically troubleshooting common failures. |
| 6 | |
| 7 | Use this skill when deploying applications to Kubernetes, configuring cluster resources, implementing NetworkPolicies for zero-trust security, setting up autoscaling (HPA, VPA, KEDA), managing persistent storage, or diagnosing operational issues like CrashLoopBackOff or resource exhaustion. |
| 8 | |
| 9 | ## When to Use This Skill |
| 10 | |
| 11 | **Common Triggers:** |
| 12 | - "Deploy my application to Kubernetes" |
| 13 | - "Configure resource requests and limits" |
| 14 | - "Set up autoscaling for my pods" |
| 15 | - "Implement NetworkPolicies for security" |
| 16 | - "My pod is stuck in Pending/CrashLoopBackOff" |
| 17 | - "Configure RBAC with least privilege" |
| 18 | - "Set up persistent storage for my database" |
| 19 | - "Spread pods across availability zones" |
| 20 | |
| 21 | **Operations Covered:** |
| 22 | - Resource management (CPU/memory, QoS classes, quotas) |
| 23 | - Advanced scheduling (affinity, taints, topology spread) |
| 24 | - Networking (NetworkPolicies, Ingress, Gateway API) |
| 25 | - Storage operations (StorageClasses, PVCs, CSI) |
| 26 | - Security hardening (RBAC, Pod Security Standards, policies) |
| 27 | - Autoscaling (HPA, VPA, KEDA, cluster autoscaler) |
| 28 | - Troubleshooting (systematic debugging playbooks) |
| 29 | |
| 30 | ## Resource Management |
| 31 | |
| 32 | ### Quality of Service (QoS) Classes |
| 33 | |
| 34 | Kubernetes assigns QoS classes based on resource requests and limits: |
| 35 | |
| 36 | **Guaranteed (Highest Priority):** |
| 37 | - Requests equal limits for CPU and memory |
| 38 | - Never evicted unless exceeding limits |
| 39 | - Use for critical production services |
| 40 | |
| 41 | ```yaml |
| 42 | resources: |
| 43 | requests: |
| 44 | memory: "512Mi" |
| 45 | cpu: "500m" |
| 46 | limits: |
| 47 | memory: "512Mi" # Same as request |
| 48 | cpu: "500m" |
| 49 | ``` |
| 50 | |
| 51 | **Burstable (Medium Priority):** |
| 52 | - Requests less than limits (or only requests set) |
| 53 | - Can burst above requests |
| 54 | - Evicted under node pressure |
| 55 | - Use for web servers, most applications |
| 56 | |
| 57 | ```yaml |
| 58 | resources: |
| 59 | requests: |
| 60 | memory: "256Mi" |
| 61 | cpu: "250m" |
| 62 | limits: |
| 63 | memory: "512Mi" # 2x request |
| 64 | cpu: "500m" |
| 65 | ``` |
| 66 | |
| 67 | **BestEffort (Lowest Priority):** |
| 68 | - No requests or limits set |
| 69 | - First to be evicted under pressure |
| 70 | - Use only for development/testing |
| 71 | |
| 72 | ### Decision Framework: Which QoS Class? |
| 73 | |
| 74 | | Workload Type | QoS Class | Configuration | |
| 75 | |---------------|-----------|---------------| |
| 76 | | Critical API/Database | Guaranteed | requests == limits | |
| 77 | | Web servers, services | Burstable | limits 1.5-2x requests | |
| 78 | | Batch jobs | Burstable | Low requests, high limits | |
| 79 | | Dev/test environments | BestEffort | No limits | |
| 80 | |
| 81 | ### Resource Quotas and LimitRanges |
| 82 | |
| 83 | Enforce multi-tenancy with ResourceQuotas (namespace limits) and LimitRanges (per-container defaults): |
| 84 | |
| 85 | ```yaml |
| 86 | # ResourceQuota: Namespace-level limits |
| 87 | apiVersion: v1 |
| 88 | kind: ResourceQuota |
| 89 | metadata: |
| 90 | name: team-quota |
| 91 | namespace: team-alpha |
| 92 | spec: |
| 93 | hard: |
| 94 | requests.cpu: "10" |
| 95 | requests.memory: "20Gi" |
| 96 | limits.cpu: "20" |
| 97 | limits.memory: "40Gi" |
| 98 | pods: "50" |
| 99 | ``` |
| 100 | |
| 101 | For detailed resource management patterns including Vertical Pod Autoscaler (VPA), see `references/resource-management.md`. |
| 102 | |
| 103 | ## Advanced Scheduling |
| 104 | |
| 105 | ### Node Affinity |
| 106 | |
| 107 | Control which nodes pods schedule on with required (hard) or preferred (soft) constraints: |
| 108 | |
| 109 | ```yaml |
| 110 | affinity: |
| 111 | nodeAffinity: |
| 112 | requiredDuringSchedulingIgnoredDuringExecution: |
| 113 | nodeSelectorTerms: |
| 114 | - matchExpressions: |
| 115 | - key: node.kubernetes.io/instance-type |
| 116 | operator: In |
| 117 | values: |
| 118 | - g4dn.xlarge # GPU instance |
| 119 | ``` |
| 120 | |
| 121 | ### Taints and Tolerations |
| 122 | |
| 123 | Reserve nodes for specific workloads (inverse of affinity): |
| 124 | |
| 125 | ```bash |
| 126 | # Taint GPU nodes to prevent non-GPU workloads |
| 127 | kubectl taint nodes gpu-node-1 workload=gpu:NoSchedule |
| 128 | ``` |
| 129 | |
| 130 | ```yaml |
| 131 | # Pod tolerates GPU taint |
| 132 | tolerations: |
| 133 | - key: "workload" |
| 134 | operator: "Equal" |
| 135 | value: "gpu" |
| 136 | effect: "NoSchedule" |
| 137 | ``` |
| 138 | |
| 139 | ### Topology Spread Constraints |
| 140 | |
| 141 | Distribute pods evenly across failure domains (zones, nodes): |
| 142 | |
| 143 | ```yaml |
| 144 | topologySpreadConstraints: |
| 145 | - maxSkew: 1 # Max difference in pod count |
| 146 | topologyKey: topology.kubernetes.io/zone |
| 147 | whenUnsatisfiable: DoNotSchedule |
| 148 | labelSelector: |
| 149 | matchLabels: |
| 150 | app: critical-app |
| 151 | ``` |
| 152 | |
| 153 | For advanced scheduling patterns including pod priority and preemption, see `references/scheduling-patterns.md`. |
| 154 | |
| 155 | ## Networking |
| 156 | |
| 157 | ### NetworkPolicies (Zero-Trust Security) |
| 158 | |
| 159 | Implement default-deny security with NetworkPolicies: |
| 160 | |
| 161 | ```yaml |
| 162 | # Default deny all traffic |
| 163 | apiVersion: networki |