remove_label
Remove a label from a Kubernetes resource to manage metadata and organize cluster objects. Specify resource type, name, label key, and namespace.
Instructions
Remove a label from a Kubernetes resource
Args:
resource_type: Type of the resource (e.g., pod, service, deployment)
resource_name: Name of the resource to remove the label from
label_key: Key of the label to remove
namespace: Namespace of the resource
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| resource_type | Yes | ||
| resource_name | Yes | ||
| label_key | Yes | ||
| namespace | No | default |
Implementation Reference
- kubernetes.py:298-313 (handler)The main handler function for the 'remove_label' MCP tool. It uses kubectl to remove a label from a Kubernetes resource by running 'kubectl label <resource_type> <resource_name> <label_key>- --overwrite'. The @mcp.tool() decorator registers it as a tool in FastMCP, with the function signature providing the input schema via type hints and defaults.async def remove_label(resource_type: str, resource_name: str, label_key: str, namespace: str = "default") -> dict: """Remove a label from a Kubernetes resource Args: resource_type: Type of the resource (e.g., pod, service, deployment) resource_name: Name of the resource to remove the label from label_key: Key of the label to remove namespace: Namespace of the resource """ try: cmd = ["kubectl", "label", resource_type, resource_name, f"{label_key}-", "-n", namespace, "--overwrite"] result = subprocess.run(cmd, capture_output=True, text=True, check=True) return {"message": f"Label {label_key} removed from resource {resource_type}/{resource_name} in namespace {namespace}", "details": result.stdout} except subprocess.CalledProcessError as e: return {"error": f"Failed to remove label: {str(e)}"}