secret_create
Generate and manage Kubernetes Secrets in a specified namespace using key-value pairs, with automatic base64 encoding. Simplify secure data handling across multiple clusters.
Instructions
Create a Secret in the specified namespace.
Args: context_name: The Kubernetes context name namespace: The Kubernetes namespace name: The Secret name data: A dictionary of key-value pairs (values will be base64 encoded) secret_type: The type of the Secret (default is "Opaque")
Returns: Status of the creation operation
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| context_name | Yes | ||
| data | Yes | ||
| name | Yes | ||
| namespace | Yes | ||
| secret_type | No | Opaque |
Implementation Reference
- tools/secret.py:28-53 (handler)The main handler function for the 'secret_create' MCP tool. It creates a Kubernetes Secret using the provided parameters, encodes data in base64, and uses the Kubernetes CoreV1 API.@mcp.tool() @use_current_context @check_readonly_permission def secret_create(context_name: str, namespace: str, name: str, data: dict, secret_type: str = "Opaque"): """ Create a Secret in the specified namespace. Args: context_name: The Kubernetes context name namespace: The Kubernetes namespace name: The Secret name data: A dictionary of key-value pairs (values will be base64 encoded) secret_type: The type of the Secret (default is "Opaque") Returns: Status of the creation operation """ core_v1: CoreV1Api = get_api_clients(context_name)["core"] encoded_data = {key: base64.b64encode(value.encode()).decode() for key, value in data.items()} secret = V1Secret( metadata=V1ObjectMeta(name=name), data=encoded_data, type=secret_type ) created_secret = core_v1.create_namespaced_secret(namespace=namespace, body=secret) return {"name": created_secret.metadata.name, "status": "Created"}