Skip to main content
Glama

delete_namespace

Remove a Kubernetes namespace and all its resources using the k8s-pilot server. Specify context and namespace to clean up cluster resources.

Instructions

Delete a namespace and all resources within it.

Args: context_name: The Kubernetes context name namespace: The name of the namespace to delete

Returns: JSON string containing the result of the operation

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
context_nameYes
namespaceYes

Implementation Reference

  • Handler function implementing the delete_namespace MCP tool. Deletes the specified Kubernetes namespace using CoreV1Api after existence check. Includes decorators for tool registration (@mcp.tool()), context usage, and permission checks.
    @mcp.tool()
    @use_current_context
    @check_readonly_permission
    def delete_namespace(context_name: str, namespace: str):
        """
        Delete a namespace and all resources within it.
    
        Args:
            context_name: The Kubernetes context name
            namespace: The name of the namespace to delete
    
        Returns:
            JSON string containing the result of the operation
        """
        core_v1: CoreV1Api = get_api_clients(context_name)["core"]
    
        try:
            # Check if namespace exists
            try:
                core_v1.read_namespace(namespace)
            except ApiException as e:
                if e.status == 404:
                    return json.dumps({"error": f"Namespace '{namespace}' not found"})
                else:
                    return json.dumps({"error": f"API error: {str(e)}"})
    
            # Delete the namespace
            core_v1.delete_namespace(namespace)
    
            result = {
                "name": namespace,
                "status": "Deleting",
                "message": f"Namespace '{namespace}' is being deleted"
            }
    
            return json.dumps(result)
        except ApiException as e:
            return json.dumps({"error": f"Failed to delete namespace: {str(e)}"})

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/bourbonkk/k8s-pilot'

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