Skip to main content
Glama

kubectl_scale

Scale Kubernetes deployments, replicasets, or statefulsets by adjusting replica counts to manage application capacity and resource allocation.

Instructions

Scale a Kubernetes deployment

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYesName of the deployment to scale
namespaceNoKubernetes namespacedefault
replicasYesNumber of replicas to scale to
resourceTypeNoResource type to scale (deployment, replicaset, statefulset)deployment
contextNoKubeconfig Context to use for the command (optional - defaults to null)

Implementation Reference

  • The main handler function that scales a Kubernetes resource (deployment, replicaset, statefulset) using the 'kubectl scale' command via execFileSync. Handles errors and returns structured content.
    export async function kubectlScale( k8sManager: KubernetesManager, input: { name: string; namespace?: string; replicas: number; resourceType?: string; context?: string; } ) { try { const namespace = input.namespace || "default"; const resourceType = input.resourceType || "deployment"; const context = input.context || ""; const command = "kubectl"; const args = [ "scale", resourceType, input.name, `--replicas=${input.replicas}`, `--namespace=${namespace}`, ]; // Add context if provided if (context) { args.push("--context", context); } // Execute the command try { const result = execFileSync(command, args, { encoding: "utf8", maxBuffer: getSpawnMaxBuffer(), env: { ...process.env, KUBECONFIG: process.env.KUBECONFIG }, }); return { content: [ { success: true, message: `Scaled ${resourceType} ${input.name} to ${input.replicas} replicas`, }, ], }; } catch (error: any) { throw new McpError( ErrorCode.InternalError, `Failed to scale ${resourceType}: ${error.message}` ); } } catch (error: any) { if (error instanceof McpError) { return { content: [ { success: false, message: error.message, }, ], }; } return { content: [ { success: false, message: `Failed to scale resource: ${error.message}`, }, ], }; } }
  • Input schema definition for the kubectl_scale tool, including parameters like name, replicas, namespace, resourceType, and context.
    export const kubectlScaleSchema = { name: "kubectl_scale", description: "Scale a Kubernetes deployment", annotations: { destructiveHint: true, }, inputSchema: { type: "object", properties: { name: { type: "string", description: "Name of the deployment to scale", }, namespace: namespaceParameter, replicas: { type: "number", description: "Number of replicas to scale to", }, resourceType: { type: "string", description: "Resource type to scale (deployment, replicaset, statefulset)", default: "deployment", }, context: contextParameter, }, required: ["name", "replicas"], }, };
  • src/index.ts:502-513 (registration)
    Tool handler registration and dispatch within the CallToolRequestSchema handler switch statement.
    case "kubectl_scale": { return await kubectlScale( k8sManager, input as { name: string; namespace?: string; replicas: number; resourceType?: string; context?: string; } ); }
  • src/index.ts:111-111 (registration)
    Tool schema registration in the allTools array used for ListToolsRequestSchema.
    kubectlScaleSchema,
  • src/index.ts:45-45 (registration)
    Import statement for the kubectlScale handler and schema.
    import { kubectlScale, kubectlScaleSchema } from "./tools/kubectl-scale.js";

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/Flux159/mcp-server-kubernetes'

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