remove_label
Remove a specific label from Kubernetes resources such as pods, services, or deployments by specifying the resource type, name, label key, and namespace using the MCP Kubernetes Server.
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 |
|---|---|---|---|
| label_key | Yes | ||
| namespace | No | default | |
| resource_name | Yes | ||
| resource_type | Yes |
Implementation Reference
- kubernetes.py:297-313 (handler)The handler function for the 'remove_label' MCP tool. It is registered via the @mcp.tool() decorator and implements the logic to remove a label from a Kubernetes resource using the 'kubectl label' command with the label key suffixed by '-'.@mcp.tool() 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)}"}