$npx -y skills add BagelHole/DevOps-Security-Agent-Skills --skill kustomizeCustomize Kubernetes manifests without templating using Kustomize. Create base configurations with environment overlays, manage configuration variants, and patch resources declaratively. Use when managing Kubernetes configurations across multiple environments without Helm.
| 1 | # Kustomize |
| 2 | |
| 3 | Customize Kubernetes resources declaratively without templating. |
| 4 | |
| 5 | ## When to Use This Skill |
| 6 | |
| 7 | Use this skill when: |
| 8 | - Managing Kubernetes configs across environments |
| 9 | - Patching existing manifests without modification |
| 10 | - Creating configuration variants from bases |
| 11 | - Customizing third-party manifests |
| 12 | - Preferring declarative over templating approach |
| 13 | |
| 14 | ## Prerequisites |
| 15 | |
| 16 | - kubectl 1.14+ (includes kustomize) |
| 17 | - Or standalone kustomize CLI |
| 18 | - Basic Kubernetes manifest knowledge |
| 19 | |
| 20 | ## Directory Structure |
| 21 | |
| 22 | ``` |
| 23 | myapp/ |
| 24 | ├── base/ |
| 25 | │ ├── kustomization.yaml |
| 26 | │ ├── deployment.yaml |
| 27 | │ ├── service.yaml |
| 28 | │ └── configmap.yaml |
| 29 | └── overlays/ |
| 30 | ├── development/ |
| 31 | │ ├── kustomization.yaml |
| 32 | │ └── replica-patch.yaml |
| 33 | ├── staging/ |
| 34 | │ ├── kustomization.yaml |
| 35 | │ └── namespace.yaml |
| 36 | └── production/ |
| 37 | ├── kustomization.yaml |
| 38 | ├── replica-patch.yaml |
| 39 | └── resource-patch.yaml |
| 40 | ``` |
| 41 | |
| 42 | ## Base Configuration |
| 43 | |
| 44 | ### kustomization.yaml |
| 45 | |
| 46 | ```yaml |
| 47 | # base/kustomization.yaml |
| 48 | apiVersion: kustomize.config.k8s.io/v1beta1 |
| 49 | kind: Kustomization |
| 50 | |
| 51 | resources: |
| 52 | - deployment.yaml |
| 53 | - service.yaml |
| 54 | - configmap.yaml |
| 55 | |
| 56 | commonLabels: |
| 57 | app: myapp |
| 58 | |
| 59 | commonAnnotations: |
| 60 | managed-by: kustomize |
| 61 | ``` |
| 62 | |
| 63 | ### Base Resources |
| 64 | |
| 65 | ```yaml |
| 66 | # base/deployment.yaml |
| 67 | apiVersion: apps/v1 |
| 68 | kind: Deployment |
| 69 | metadata: |
| 70 | name: myapp |
| 71 | spec: |
| 72 | replicas: 1 |
| 73 | selector: |
| 74 | matchLabels: |
| 75 | app: myapp |
| 76 | template: |
| 77 | metadata: |
| 78 | labels: |
| 79 | app: myapp |
| 80 | spec: |
| 81 | containers: |
| 82 | - name: myapp |
| 83 | image: myapp:latest |
| 84 | ports: |
| 85 | - containerPort: 8080 |
| 86 | resources: |
| 87 | requests: |
| 88 | memory: "64Mi" |
| 89 | cpu: "100m" |
| 90 | limits: |
| 91 | memory: "128Mi" |
| 92 | cpu: "200m" |
| 93 | ``` |
| 94 | |
| 95 | ## Overlays |
| 96 | |
| 97 | ### Development Overlay |
| 98 | |
| 99 | ```yaml |
| 100 | # overlays/development/kustomization.yaml |
| 101 | apiVersion: kustomize.config.k8s.io/v1beta1 |
| 102 | kind: Kustomization |
| 103 | |
| 104 | resources: |
| 105 | - ../../base |
| 106 | |
| 107 | namespace: myapp-dev |
| 108 | |
| 109 | namePrefix: dev- |
| 110 | |
| 111 | commonLabels: |
| 112 | environment: development |
| 113 | |
| 114 | images: |
| 115 | - name: myapp |
| 116 | newTag: dev-latest |
| 117 | ``` |
| 118 | |
| 119 | ### Production Overlay |
| 120 | |
| 121 | ```yaml |
| 122 | # overlays/production/kustomization.yaml |
| 123 | apiVersion: kustomize.config.k8s.io/v1beta1 |
| 124 | kind: Kustomization |
| 125 | |
| 126 | resources: |
| 127 | - ../../base |
| 128 | |
| 129 | namespace: myapp-prod |
| 130 | |
| 131 | namePrefix: prod- |
| 132 | |
| 133 | commonLabels: |
| 134 | environment: production |
| 135 | |
| 136 | replicas: |
| 137 | - name: myapp |
| 138 | count: 5 |
| 139 | |
| 140 | images: |
| 141 | - name: myapp |
| 142 | newName: registry.example.com/myapp |
| 143 | newTag: v2.0.0 |
| 144 | |
| 145 | patches: |
| 146 | - path: resource-patch.yaml |
| 147 | ``` |
| 148 | |
| 149 | ## Patching |
| 150 | |
| 151 | ### Strategic Merge Patch |
| 152 | |
| 153 | ```yaml |
| 154 | # overlays/production/resource-patch.yaml |
| 155 | apiVersion: apps/v1 |
| 156 | kind: Deployment |
| 157 | metadata: |
| 158 | name: myapp |
| 159 | spec: |
| 160 | template: |
| 161 | spec: |
| 162 | containers: |
| 163 | - name: myapp |
| 164 | resources: |
| 165 | requests: |
| 166 | memory: "256Mi" |
| 167 | cpu: "500m" |
| 168 | limits: |
| 169 | memory: "512Mi" |
| 170 | cpu: "1000m" |
| 171 | ``` |
| 172 | |
| 173 | ### JSON Patch |
| 174 | |
| 175 | ```yaml |
| 176 | # kustomization.yaml |
| 177 | patches: |
| 178 | - target: |
| 179 | kind: Deployment |
| 180 | name: myapp |
| 181 | patch: |- |
| 182 | - op: replace |
| 183 | path: /spec/replicas |
| 184 | value: 5 |
| 185 | - op: add |
| 186 | path: /spec/template/spec/containers/0/env |
| 187 | value: |
| 188 | - name: LOG_LEVEL |
| 189 | value: info |
| 190 | ``` |
| 191 | |
| 192 | ### Inline Patches |
| 193 | |
| 194 | ```yaml |
| 195 | # kustomization.yaml |
| 196 | patches: |
| 197 | - patch: |- |
| 198 | apiVersion: apps/v1 |
| 199 | kind: Deployment |
| 200 | metadata: |
| 201 | name: myapp |
| 202 | spec: |
| 203 | replicas: 3 |
| 204 | target: |
| 205 | kind: Deployment |
| 206 | name: myapp |
| 207 | ``` |
| 208 | |
| 209 | ## Configuration Generation |
| 210 | |
| 211 | ### ConfigMap Generator |
| 212 | |
| 213 | ```yaml |
| 214 | # kustomization.yaml |
| 215 | configMapGenerator: |
| 216 | - name: myapp-config |
| 217 | literals: |
| 218 | - APP_ENV=production |
| 219 | - LOG_LEVEL=info |
| 220 | files: |
| 221 | - config.yaml |
| 222 | envs: |
| 223 | - config.env |
| 224 | options: |
| 225 | disableNameSuffixHash: false |
| 226 | ``` |
| 227 | |
| 228 | ### Secret Generator |
| 229 | |
| 230 | ```yaml |
| 231 | # kustomization.yaml |
| 232 | secretGenerator: |
| 233 | - name: myapp-secrets |
| 234 | literals: |
| 235 | - api-key=secret123 |
| 236 | files: |
| 237 | - tls.crt |
| 238 | - tls.key |
| 239 | type: kubernetes.io/tls |
| 240 | ``` |
| 241 | |
| 242 | ## Image Transformations |
| 243 | |
| 244 | ```yaml |
| 245 | # kustomization.yaml |
| 246 | images: |
| 247 | # Change tag |
| 248 | - name: myapp |
| 249 | newTag: v2.0.0 |
| 250 | |
| 251 | # Change registry |
| 252 | - name: myapp |
| 253 | newName: registry.example.com/myapp |
| 254 | newTag: v2.0.0 |
| 255 | |
| 256 | # Use digest |
| 257 | - name: myapp |
| 258 | digest: sha256:abc123... |
| 259 | ``` |
| 260 | |
| 261 | ## Resource Transformations |
| 262 | |
| 263 | ### Name Prefix/Suffix |
| 264 | |
| 265 | ```yaml |
| 266 | # kustomization.yaml |
| 267 | namePrefix: prod- |
| 268 | nameSuffix: -v2 |
| 269 | ``` |
| 270 | |
| 271 | ### Namespace |
| 272 | |
| 273 | ```yaml |
| 274 | # kustomization.yaml |
| 275 | namespace: production |
| 276 | ``` |
| 277 | |
| 278 | ### Labels and Annotations |
| 279 | |
| 280 | ```yaml |
| 281 | # kustomization.yaml |
| 282 | commonLabels: |
| 283 | app.kubernetes.io/name: myapp |
| 284 | app.kubernetes.io/environment: production |
| 285 | |
| 286 | commonAnnotations: |
| 287 | example.com/owner: team-a |
| 288 | ``` |
| 289 | |
| 290 | ### Replicas |
| 291 | |
| 292 | ```yaml |
| 293 | # k |