Skip to main content
Glama

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
NameRequiredDescriptionDefault
nameYesDeployment name
namespaceNoKubernetes 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.`;
    }
  • 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"],
      },
    },
  • The tool handler is routed to `rollbackDeployment` in the `handleKubernetesTool` function.
    case "k8s_rollback_deployment": return rollbackDeployment(a);

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/batu-sonmez/infraclaude'

If you have feedback or need assistance with the MCP directory API, please join our Discord server