---
name: kubernetes-deployment-refactoring-tool
description: "Rewrites a working Deployment manifest to current best practice in the areas you pick, keeping behavior identical and listing every change so the diff is reviewable. Use when an existing Deployment YAML works but needs resource limits, pinned images, security contexts, or probes brought up to best practice without changing behavior. Do not use for documenting a manifest or producing a pass or fail validation report. Related topics: coding, kubernetes."
---

# Kubernetes Deployment Refactoring Tool

Rewrites a working Deployment manifest to current best practice in the areas you pick, keeping behavior identical and listing every change so the diff is reviewable.

## When to use

Use this skill when an existing Deployment YAML works but needs resource limits, pinned images, security contexts, or probes brought up to best practice without changing behavior. Do not use it for documenting a manifest or producing a pass or fail validation report.

## Workflow

1. Ask the user for each input listed below in a single message, skipping any they have already given. Where options are listed, offer them, but accept other answers too.
2. Read the manifest and list which of the selected focus areas it already satisfies, so only real gaps get touched.
3. Apply the fix for each selected area in turn, keeping the selector identical to the template labels and using only fields the target version supports.
4. Pin every image to a tag or digest and add requests and limits to every container when those areas are selected, stating the values chosen.
5. Re-read the result against the original to confirm nothing outside the focus areas changed and comments survived when requested.
6. Deliver the manifest in the chosen format followed by a change list that names each field and its reason.

## Inputs

- **Current Deployment YAML** (longer free text)
- **Target Kubernetes version** (choose one: 1.24, 1.25, 1.26, 1.27)
- **Refactoring focus** (choose any: Resource limits, Image tags, Labels & annotations, Security contexts, Probes, Replica strategy)
- **Preserve comments** (choose one: Yes, No)
- **Output format** (choose one: YAML, JSON)

## Output

Two blocks: the refactored manifest as a single YAML or JSON code block, then a markdown bullet list with one entry per change naming the field, the old value, the new value, and the reason.

## Prompt template

Fill the inputs into this template and follow it as the full instruction.

### Kubernetes Deployment Refactoring Tool

Refactor my Deployment manifest without changing what it does.

- Current Deployment YAML: {{Current Deployment YAML}}
- Target Kubernetes version: {{Target Kubernetes version}}
- Refactoring focus: {{Refactoring focus}}
- Preserve comments: {{Preserve comments}}
- Output format: {{Output format}}

Work through the selected focus areas only; leave everything else as written, since an unrequested change is the one that breaks the rollout. For resource limits, add requests and limits to every container and keep requests at or below limits. For image tags, replace latest and floating tags with a pinned tag or digest and say which you chose. For labels and annotations, apply the recommended app.kubernetes.io set and keep the selector matching the template labels, because a selector change is immutable on an existing Deployment. For security contexts, drop root, set readOnlyRootFilesystem where the container can run that way, and drop all capabilities before adding back the ones needed. For probes, give liveness and readiness probes distinct endpoints and sensible timings. For replica strategy, set maxSurge and maxUnavailable to match the replica count. Use only API fields that exist in the target version. When comments must be preserved, keep them next to the lines they describe. Return the refactored manifest in the chosen format as one code block, then a markdown list of changes, each naming the field and the reason.

## Pitfalls

- Changing spec.selector on an existing Deployment, which the API rejects because the selector is immutable after creation.
- Setting resource requests from guesswork and starving the pod, when a conservative request plus a note to measure is safer.
- Fixing things outside the selected focus areas, so the reviewer cannot tell intended changes from accidental ones.
- Adding a readinessProbe that hits an endpoint which calls downstream services, so one dependency outage removes every pod from the Service.
