k8s_rollback_deployment
Rollback a Kubernetes deployment to its previous revision to address issues or restore stability after problematic updates.
Instructions
Rollback a deployment to the previous revision
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Deployment name | |
| namespace | No | Kubernetes namespace (default: 'default') |
Implementation Reference
- The handler function `rollbackDeployment` implements the rollback logic by patching the deployment's template with a `restartedAt` annotation to trigger a rollout.
export async function rollbackDeployment(args: Record<string, unknown>): Promise<string> { const api = getAppsV1Api(); const namespace = (args.namespace as string) || "default"; const name = args.name as string; if (!name) throw new Error("Deployment name is required"); // Rollback by patching the deployment to restart // In modern K8s, rollback is done via revision in rollout history const patch = { spec: { template: { metadata: { annotations: { "kubectl.kubernetes.io/restartedAt": new Date().toISOString(), }, }, }, }, }; await api.patchNamespacedDeployment( name, namespace, patch, undefined, undefined, undefined, undefined, undefined, { headers: { "Content-Type": "application/strategic-merge-patch+json" } } ); return `Deployment '${name}' in namespace '${namespace}' has been rolled back (restarted). Use k8s_rollout_status to monitor progress.`; } - src/tools/kubernetes/index.ts:115-125 (registration)The tool `k8s_rollback_deployment` is registered here with its input schema.
name: "k8s_rollback_deployment", description: "Rollback a deployment to the previous revision", inputSchema: { type: "object" as const, properties: { name: { type: "string", description: "Deployment name" }, namespace: { type: "string", description: "Kubernetes namespace (default: 'default')" }, }, required: ["name"], }, }, - src/tools/kubernetes/index.ts:205-205 (registration)The tool handler is routed to `rollbackDeployment` in the `handleKubernetesTool` function.
case "k8s_rollback_deployment": return rollbackDeployment(a);