Skip to main content
Glama

pod_create

Create a new pod in Kubernetes by specifying namespace, container image, and optional configurations like labels, commands, and environment variables.

Instructions

Create a new pod in the specified namespace.

Args: context_name: The Kubernetes context name namespace: The Kubernetes namespace name: The name for the new pod image: The container image to use labels: Optional dictionary of pod labels command: Optional command to run in the container args: Optional arguments for the command env_vars: Optional environment variables for the container

Returns: Information about the created pod

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
context_nameYes
namespaceYes
nameYes
imageYes
labelsNo
commandNo
argsNo
env_varsNo

Implementation Reference

  • Implementation of the pod_create MCP tool handler. This function creates a new Kubernetes Pod using the CoreV1Api client. It is registered via the @mcp.tool() decorator and includes permission checks and context usage decorators.
    @mcp.tool()
    @use_current_context
    @check_readonly_permission
    def pod_create(context_name: str, namespace: str, name: str, image: str,
                   labels: Optional[Dict[str, str]] = None,
                   command: Optional[List[str]] = None,
                   args: Optional[List[str]] = None,
                   env_vars: Optional[Dict[str, str]] = None):
        """
        Create a new pod in the specified namespace.
    
        Args:
            context_name: The Kubernetes context name
            namespace: The Kubernetes namespace
            name: The name for the new pod
            image: The container image to use
            labels: Optional dictionary of pod labels
            command: Optional command to run in the container
            args: Optional arguments for the command
            env_vars: Optional environment variables for the container
    
        Returns:
            Information about the created pod
        """
        from kubernetes.client import V1Pod, V1ObjectMeta, V1PodSpec, V1Container, V1EnvVar
    
        core_v1: CoreV1Api = get_api_clients(context_name)["core"]
    
        # Prepare environment variables if provided
        container_env = None
        if env_vars:
            container_env = [V1EnvVar(name=k, value=v) for k, v in env_vars.items()]
    
        # Create container
        container = V1Container(
            name=name,
            image=image,
            command=command,
            args=args,
            env=container_env
        )
    
        # Create pod spec
        pod_spec = V1PodSpec(containers=[container])
    
        # Create pod metadata
        pod_metadata = V1ObjectMeta(name=name, namespace=namespace, labels=labels)
    
        # Create pod
        pod = V1Pod(
            api_version="v1",
            kind="Pod",
            metadata=pod_metadata,
            spec=pod_spec
        )
    
        # Create the pod in Kubernetes
        created_pod = core_v1.create_namespaced_pod(namespace=namespace, body=pod)
    
        result = {
            "name": created_pod.metadata.name,
            "namespace": created_pod.metadata.namespace,
            "status": "Created",
        }
        return result

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/bourbonkk/k8s-pilot'

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