annotate_resource
Add custom annotations to Kubernetes resources such as pods, services, or deployments, specifying a key-value pair and resource namespace for improved metadata management.
Instructions
Annotate a Kubernetes resource with the specified annotation
Args:
resource_type: Type of the resource (e.g., pod, service, deployment)
resource_name: Name of the resource to annotate
annotation: Annotation to add (e.g., key=value)
namespace: Namespace of the resource
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| annotation | Yes | ||
| namespace | No | default | |
| resource_name | Yes | ||
| resource_type | Yes |
Implementation Reference
- kubernetes.py:242-258 (handler)The main handler function for the 'annotate_resource' MCP tool. It uses kubectl annotate command to add an annotation to a specified Kubernetes resource. Registered via @mcp.tool() decorator, which also serves as the registration point.@mcp.tool() async def annotate_resource(resource_type: str, resource_name: str, annotation: str, namespace: str = "default") -> dict: """Annotate a Kubernetes resource with the specified annotation Args: resource_type: Type of the resource (e.g., pod, service, deployment) resource_name: Name of the resource to annotate annotation: Annotation to add (e.g., key=value) namespace: Namespace of the resource """ try: cmd = ["kubectl", "annotate", resource_type, resource_name, annotation, "-n", namespace, "--overwrite"] result = subprocess.run(cmd, capture_output=True, text=True, check=True) return {"message": f"Resource {resource_type}/{resource_name} annotated successfully in namespace {namespace}", "details": result.stdout} except subprocess.CalledProcessError as e: return {"error": f"Failed to annotate resource: {str(e)}"}