delete_namespace
Remove a Kubernetes namespace and all its resources using the specified context. Simplifies cleanup and cluster management.
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
| Name | Required | Description | Default |
|---|---|---|---|
| context_name | Yes | ||
| namespace | Yes |
Implementation Reference
- tools/namespace.py:113-151 (handler)The handler function implementing the 'delete_namespace' tool logic. It uses the Kubernetes API to delete the specified namespace after verifying its existence. Registered via @mcp.tool() decorator.@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)}"})