service_create
Create a Kubernetes Service to expose pods and manage network access within a cluster namespace.
Instructions
Create a Service in the specified namespace.
Args: context_name: The Kubernetes context name namespace: The Kubernetes namespace name: The Service name selector: A dictionary of labels to select the target pods ports: A list of ports (e.g., [{"port": 80, "target_port": 8080}]) service_type: The type of the Service (default is "ClusterIP")
Returns: Status of the creation operation
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| context_name | Yes | ||
| namespace | Yes | ||
| name | Yes | ||
| selector | Yes | ||
| ports | Yes | ||
| service_type | No | ClusterIP |
Implementation Reference
- tools/service.py:27-55 (handler)The service_create tool handler, decorated with @mcp.tool() for registration, @use_current_context, and @check_readonly_permission. It creates a Kubernetes Service object using kubernetes.client.CoreV1Api and applies it to the specified namespace.@mcp.tool() @use_current_context @check_readonly_permission def service_create(context_name: str, namespace: str, name: str, selector: dict, ports: list, service_type: str = "ClusterIP"): """ Create a Service in the specified namespace. Args: context_name: The Kubernetes context name namespace: The Kubernetes namespace name: The Service name selector: A dictionary of labels to select the target pods ports: A list of ports (e.g., [{"port": 80, "target_port": 8080}]) service_type: The type of the Service (default is "ClusterIP") Returns: Status of the creation operation """ core_v1: CoreV1Api = get_api_clients(context_name)["core"] service = V1Service( metadata=V1ObjectMeta(name=name), spec=V1ServiceSpec( selector=selector, ports=[V1ServicePort(port=port["port"], target_port=port["target_port"]) for port in ports], type=service_type ) ) created_service = core_v1.create_namespaced_service(namespace=namespace, body=service) return {"name": created_service.metadata.name, "status": "Created"}
- tools/service.py:27-27 (registration)The @mcp.tool() decorator registers the service_create function as an MCP tool.@mcp.tool()