Skip to main content
Glama

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
NameRequiredDescriptionDefault
k8s_objectYes
nameYes
namespaceNodefault
portNo
protocolNoTCP
target_portNo
typeNoClusterIP

Implementation Reference

  • 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)}"}

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