remove_annotation
Remove annotations from Kubernetes resources like pods, services, or deployments to clean up metadata or modify configurations.
Instructions
Remove an annotation 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 annotation from
annotation_key: Key of the annotation to remove
namespace: Namespace of the resource
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| resource_type | Yes | ||
| resource_name | Yes | ||
| annotation_key | Yes | ||
| namespace | No | default |
Implementation Reference
- kubernetes.py:261-277 (handler)The core handler function for the 'remove_annotation' tool. It is decorated with @mcp.tool(), which registers it with the MCP server. The function executes kubectl annotate command with the annotation key suffixed by '-' to remove the annotation from the specified Kubernetes resource.@mcp.tool() async def remove_annotation(resource_type: str, resource_name: str, annotation_key: str, namespace: str = "default") -> dict: """Remove an annotation 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 annotation from annotation_key: Key of the annotation to remove namespace: Namespace of the resource """ try: cmd = ["kubectl", "annotate", resource_type, resource_name, f"{annotation_key}-", "-n", namespace, "--overwrite"] result = subprocess.run(cmd, capture_output=True, text=True, check=True) return {"message": f"Annotation {annotation_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 annotation: {str(e)}"}