service_create
Create Kubernetes Services in specified namespaces using context name, labels, ports, and service type. Simplify resource management on the k8s-pilot MCP server.
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 | ||
| name | Yes | ||
| namespace | Yes | ||
| ports | Yes | ||
| selector | Yes | ||
| service_type | No | ClusterIP |
Implementation Reference
- tools/service.py:28-55 (handler)The main handler function for the 'service_create' MCP tool. It creates a Kubernetes Service using the provided parameters, decorated with @mcp.tool() for registration and other decorators for context and permissions.@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"}