delete_resource
Remove specific Kubernetes resources by specifying type, name, and namespace. Simplify resource management tasks for streamlined cluster operations.
Instructions
Delete a Kubernetes resource
Args:
resource_type: Type of the resource (e.g., pod, service, deployment,configmap,secret,ingress,statefulset,replicaset,damonset,newtorkpolicy,rolebinding,role,serviceaccount,job,cronjob)
resource_name: Name of the resource to delete
namespace: Namespace of the resource
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| namespace | No | default | |
| resource_name | Yes | ||
| resource_type | Yes |
Implementation Reference
- kubernetes.py:353-369 (handler)The handler function for the 'delete_resource' MCP tool. It uses kubectl to delete the specified resource type and name in the given namespace. The @mcp.tool() decorator registers it with the FastMCP server.@mcp.tool() async def delete_resource(resource_type: str, resource_name: str, namespace: str = "default") -> dict: """Delete a Kubernetes resource Args: resource_type: Type of the resource (e.g., pod, service, deployment,configmap,secret,ingress,statefulset,replicaset,damonset,newtorkpolicy,rolebinding,role,serviceaccount,job,cronjob) resource_name: Name of the resource to delete namespace: Namespace of the resource """ try: cmd = ["kubectl", "delete", resource_type, resource_name, "-n", namespace] result = subprocess.run(cmd, capture_output=True, text=True, check=True) return {"message": f"Resource {resource_type}/{resource_name} deleted successfully in namespace {namespace}", "details": result.stdout} except subprocess.CalledProcessError as e: return {"error": f"Failed to delete resource: {str(e)}"}