expose_service
Create a Kubernetes service to expose resources like pods, deployments, or replicasets. Specify service type (ClusterIP, NodePort, LoadBalancer, or ExternalName) and configure ports for network access.
Instructions
Expose a resource as a new kubernetes service k8s_object can be pod (po), service (svc), replicationcontroller (rc), deployment (deploy), replicaset (rs) Type for this service: ClusterIP, NodePort, LoadBalancer, or ExternalName. Default is 'ClusterIP'.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| k8s_object | Yes | ||
| name | Yes | ||
| namespace | No | default | |
| port | No | ||
| protocol | No | TCP | |
| target_port | No | ||
| type | No | ClusterIP |
Implementation Reference
- kubernetes.py:130-142 (handler)The core handler function for the 'expose_service' tool. It is decorated with @mcp.tool(), which registers it in the FastMCP server. The function executes 'kubectl expose' to create a Kubernetes service exposing the given resource.@mcp.tool() async def expose_service(k8s_object: str, name: str, namespace: str = "default", type: str = "ClusterIP", port: int = 80, target_port: int = 80, protocol: str = "TCP") -> dict: """Expose a resource as a new kubernetes service k8s_object can be pod (po), service (svc), replicationcontroller (rc), deployment (deploy), replicaset (rs) Type for this service: ClusterIP, NodePort, LoadBalancer, or ExternalName. Default is 'ClusterIP'. """ try: cmd = ["kubectl", "expose", k8s_object, name, "-n", namespace, "--type", type, "--port", str(port), "--target-port", str(target_port),"--protocol", protocol] result = subprocess.run(cmd, capture_output=True, text=True, check=True) return json.loads(result.stdout) except subprocess.CalledProcessError as e: return {"error": f"Failed to expose : {str(e)}"}