Skip to main content
Glama
abhijeetka
by abhijeetka

label_resource

Add labels to Kubernetes resources like pods, services, or deployments to organize and identify them within your cluster.

Instructions

Label a Kubernetes resource with the specified label

Args:
    resource_type: Type of the resource (e.g., pod, service, deployment)
    resource_name: Name of the resource to label
    label: Label to add (e.g., key=value)
    namespace: Namespace of the resource

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
resource_typeYes
resource_nameYes
labelYes
namespaceNodefault

Implementation Reference

  • The main handler function for the 'label_resource' tool, decorated with @mcp.tool() for registration. It uses kubectl label to add a label to a Kubernetes resource.
    async def label_resource(resource_type: str, resource_name: str, label: str, namespace: str = "default") -> dict:
        """Label a Kubernetes resource with the specified label
    
        Args:
            resource_type: Type of the resource (e.g., pod, service, deployment)
            resource_name: Name of the resource to label
            label: Label to add (e.g., key=value)
            namespace: Namespace of the resource
        """
        try:
            cmd = ["kubectl", "label", resource_type, resource_name, label, "-n", namespace, "--overwrite"]
            result = subprocess.run(cmd, capture_output=True, text=True, check=True)
            return {"message": f"Resource {resource_type}/{resource_name} labeled successfully in namespace {namespace}",
                    "details": result.stdout}
        except subprocess.CalledProcessError as e:
            return {"error": f"Failed to label resource: {str(e)}"}

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/abhijeetka/mcp-k8s-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server