Skip to main content
Glama
abhijeetka
by abhijeetka

update_deployment

Modify a Kubernetes deployment by adjusting replica count or updating container images to scale applications or deploy new versions.

Instructions

Update a Kubernetes deployment with new replicas count and/or image

Args:
    name: Name of the deployment to update
    namespace: Namespace of the deployment
    replicas: New number of replicas (optional)
    image: New container image (optional)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYes
namespaceNodefault
replicasNo
imageNo

Implementation Reference

  • Handler function for the 'update_deployment' tool, decorated with @mcp.tool() for automatic registration. Updates Kubernetes deployment replicas and/or image using kubectl commands.
    @mcp.tool()
    async def update_deployment(name: str, namespace: str = "default", replicas: int = None, image: str = None) -> dict:
        """Update a Kubernetes deployment with new replicas count and/or image
        
        Args:
            name: Name of the deployment to update
            namespace: Namespace of the deployment
            replicas: New number of replicas (optional)
            image: New container image (optional)
        """
        try:
            if replicas is None and image is None:
                return {"error": "Must specify either replicas or image to update"}
                
            updates = []
            if replicas is not None:
                cmd = ["kubectl", "scale", "deployment", name,
                      "--replicas", str(replicas),
                      "-n", namespace]
                result = subprocess.run(cmd, capture_output=True, text=True, check=True )
                updates.append(f"Scaled replicas to {replicas}")
                
            if image is not None:
                cmd = ["kubectl", "set", "image", f"deployment/{name}",
                      f"{name}={image}",
                      "-n", namespace]
                result = subprocess.run(cmd, capture_output=True, text=True, check=True )
                updates.append(f"Updated image to {image}")
                
            return {
                "message": f"Deployment {name} updated successfully in namespace {namespace}",
                "updates": updates,
                "details": result.stdout
            }
        except subprocess.CalledProcessError as e:
            return {"error": f"Failed to update deployment: {str(e)}"}
  • kubernetes.py:316-316 (registration)
    Registration of the 'update_deployment' tool via FastMCP decorator.
    @mcp.tool()

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/abhijeetka/mcp-k8s-server'

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